arduino with ultra sonic and RGB led in tamil

codings for this video

#define trig 8
#define echo 9
int red = 10, green = 11,blue = 12;
void setup() {
  Serial.begin(9600);
  pinMode(trig,OUTPUT);
  pinMode(echo,INPUT);
  pinMode(red,OUTPUT);
  pinMode(blue,OUTPUT);
  pinMode(green,OUTPUT);
}

void loop() {
  long duration , distance;
  
  digitalWrite(trig,LOW);
  delay(2);
  digitalWrite(trig,HIGH);
  delay(2);
  digitalWrite(trig,LOW);
  
  duration= pulseIn(echo,HIGH);
  distance=(duration/2)/29.1;
  Serial.println(distance);

  if(distance <= 10)
  {
    digitalWrite(red,LOW);
    digitalWrite(blue,LOW);
    digitalWrite(green,HIGH);
  }
  else if(distance <= 15)
  {
    digitalWrite(red,LOW);
    digitalWrite(blue,HIGH);
    digitalWrite(green,LOW);
  }
  else if(distance <= 20)
  {
    digitalWrite(red,HIGH);
    digitalWrite(blue,LOW);
    digitalWrite(green,LOW); 
  }
  else
  {
    digitalWrite(red,LOW);
    digitalWrite(blue,LOW);
    digitalWrite(green,LOW); 
  }
  
 delay(100);
  

}
---------*****************------------------****************************-----------------
copy this codings and upload that in arduino IDE directly.
connect all wires like coding.

Comments

Popular posts from this blog

using millis() in ultrasonic sensor program in tamil

CHATBOT programming tutorial in tamil

RFID attendance system review in tamil