codings for ultrasonic sensor

                     codings for ultrasonic sensor

#define trig 5
#define echo 6
void setup() {
  Serial.begin(9600);
  pinMode(trig,OUTPUT);
  pinMode(echo,INPUT);
  pinMode(13,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;

  if(distance <= 10)
  {
    digitalWrite(13,HIGH);
  }
  else
  {
    digitalWrite(13,LOW);
  }
  
 delay(1000);
  

}
---------------------------***********----------------------------***************------------------
This is the codings for ultrasonic sensor... 
For reference watch my youtube channel..


Comments


Comments

Popular posts from this blog

using millis() in ultrasonic sensor program in tamil

RFID attendance system review in tamil

CHATBOT programming tutorial in tamil