Maker Pro
Arduino

Distance Measurement Using Ultrasonic Sensor And Displaying On LCD

February 25, 2018 by Arunkumar Iyer
Share
banner

Using sound waves, the ultrasonic sensor calculates the distance between itself and an object and displays on a LCD.

How does an Ultrasonic Distance Sensor work?

The Ultrasonic Sensor sends out a high-frequency sound pulse and then times how long it takes for the echo of the sound to reflect back. The sensor has 2 openings on its front. One opening transmits ultrasonic waves, (like a tiny speaker), the other receives them, (like a tiny microphone).

The speed of sound is approximately 341 meters (1100 feet) per second in air. The ultrasonic sensor uses this information along with the time difference between sending and receiving the sound pulse to determine the distance to an object. It uses the following mathematical equation:

Distance = Time x Speed of Sound divided by 2

Why/When to use Ultrasonic Sensors ?

  1. Ideally suited to accurate, automatic distance measurement in normal and difficult environments. 
  2. Particularly suitable for environments where optical sensors are unusable such as smoke, dust and similar.
  3. Very accurate, stable and can be used over large ranges.

Ultrasonic sensors can measure the following parameters without contacting the medium to be measured:

  1. Distance
  2. Level
  3. Diameter
  4. Presence
  5. Position

Functioning Of Project:

The ultrasonic sensor emits a high-frequency sound pulse and calculates the distance depending  upon the time taken by the echo signal to travel back after reflecting from the desired target. The speed of sound is 341 meters per second in air. After the distance is calculated, it will be displayed on the LCD display. 

Timing Diagram of Ultrasonic Sensor.

/*LCD circuit:
 * LCD RS pin to digital pin 12
 * LCD Enable pin to digital pin 11
 * LCD D4 pin to digital pin 5
 * LCD D5 pin to digital pin 4
 * LCD D6 pin to digital pin 3
 * LCD D7 pin to digital pin 2
 * LCD R/W pin to ground
 * LCD VSS pin to ground
 * LCD VCC pin to 5V
 * 10K resistor:
 * ends to +5V and ground
 * wiper to LCD VO pin (pin 3)*/




#include<LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2); //Interface pins of the LCD 
const int trig_pin=8;
const int echo_pin=9;
long distance,duration;

void setup() {
lcd.begin(16,2);
lcd.setCursor(0,0); //set the cursor to column 0 and line 0
pinMode(8,OUTPUT);
pinMode(9,INPUT);
}


void loop() {
digitalWrite(8,HIGH);
delayMicroseconds(20);
digitalWrite(8,LOW);
delayMicroseconds(20);
duration = pulseIn(echo_pin, HIGH); //To receive the reflected signal.
distance= duration*0.034/2;
lcd.setCursor(0,1); //set the cursor to column 0 and line 1
lcd.print(distance);
lcd.print("cm");
delay(100);
}

Author

Avatar
Arunkumar Iyer

I am student of electronics and telecommunication engineering. I am very much fond of electronics and it's applications.

Related Content

Categories

Comments


You May Also Like