Ultrasonic Sensor

Ultrasonic Sensor

Ultrasonic sensor is used to sense the distance of the objects present. Ultrasonic Sensor emits short, high frequency sound pulses at regular intervals. If they strike an object, then they are reflected back as echo signals to the sensors, which itself compute the distance to the target based on the time span between the signal and receiving echo.We can interface ultrasonic s sensor with Arduino to measure the distance of the objects present. 

HSR04

Applications


  • Ultrasonic Sensors for Fill Level Monitoring in Gravel Silos
  • Ultrasonic Sensors Detect Fill Level for Bulk Goods
  • Detecting Boom Height on Agricultural Machine
  • Ultrasonic Sensors for Anti-Collision Detection on Aerial Work Platforms

Sample Project Using Arduino: 

        In this project we going to measure the distance of an object placed before the ultrasonic sensor and to turn ON the buzzer when the distance is lesser than 35cm.
 

Materials Required:

  • ARDUINO UNO Board 
  • Ultrasonic sensor    
  • Buzzer  

Circuit:





Code:

int buzzer = 13;  //initialize buzzer on pin 13

int trigger = 7;  // initialize triggering on pin 7

int echo= 8;  // initialize echo on pin 8

void setup(){

Serial.begin(9600);  // Enable serial comunication, so we can see the distance on the serial monitor

pinMode(trigger, OUTPUT);  //definining trigger as output

pinMode(echo, INPUT);  // defining echo as input

pinMode(buzzer, OUTPUT);  //defining buzzer as output

digitalWrite(buzzer,LOW);  //initilizing the buzzer value as LOW

}

void loop(){  

 int duration, distance;  //Adding two variables duration and distance

digitalWrite(trigger, HIGH);  //triggering the wave by giving HIGH

delay(10);

digitalWrite(trigger, LOW);  //after sometime the triggering is stopped

duration = pulseIn(echo, HIGH);  //a special function for listening and waiting for the wave

distance = (duration/2) / 29.1;  //transforming the number to cm

delay(1000);

Serial.print(distance);  //printing the distance in serial monitor

Serial.print("cm");  //printing the unit of distance as cm

Serial.println(" ");  //just printing to a new line

if (distance < 35)  //checking whether the distance is less than 35cm

{

digitalWrite(buzzer,HIGH);  //if so make the buzzer to turn ON

 

Serial.println("Buzzer On");  //also printing as Buzzer On in serial monitor

}

else

{

digitalWrite(buzzer,LOW);  //if the condition is not satisfied means buzzer is turned off

}

}

Serial.println("Buzzer On");  //also printing as Buzzer On in serial monitor

}

else

{

digitalWrite(buzzer,LOW);  //if the condition is not satisfied means buzzer is turned off

}

}

 

Serial Monitor Output:



   

 


Comments

Popular posts from this blog

Voice Record & Playback Module

GSM Sim800L

GPS