Distance Measurement Using Ultrasonic Sensor

 

Apparatus Required for distance measurement:

Sl.No.

 

Name of the apparatus Specifications Quantity Buy
1 microcontroller board Arduino board 1
2 Potentiometer 10k 2
3 Battery (optional) 9v 1
4 LCD display 16×2 LCD display 1
5 Ultrasonic sensor 1
6 Jumpers wires As per required

Circuit diagram for Distance Measurement:

Distance Measurement
Distance Measurement

 

 

Working Principle of Distance Measurement:

these projects first use ultrasonic sensors to calculate distance using ultrasonic waves. On sensing obstacles, the sensor passes this data to the microcontroller (Arduino UNO). The microcontroller (Arduino UNO) then processes this data and calculates the distance between the sensors and the obstacle and its display in the display unit (LCD screen).

Method of calculating the distance:

As the name suggests, an ultrasonic sensor is a device which can calculate the distance of an object using ultrasonic waves. It uses a single ultrasonic element for both emission and reception. The device sends out ultrasonic waves at a certain frequency, which hit obstacles in front and bounces back. The sensor records the time(T) taken by the waves to return back. Using this recorded time, the distance of the object from the sensor can be calculated. We can get the total distance(D-total) traveled by the sound wave by multiplying the recorded time with the speed of the waves(v). This total distance is twice the distance between the object and the sensor. The actual distance(D) between the object and the sensor is then calculated by dividing the total distance by two.

So, calculated distance between obstacle and sensor (d) is = (T×V)/2 m.

See this Video:

Connection for Distance Measurement:

Connect the VCC pin of the ultrasonic sensor with 5V dc.

Connect the echo pin of the ultrasonic sensor with the pin 9 of Arduino board.

Connect the trigger pin of the ultrasonic sensor with the pin 8 of Arduino board.

Connect the GND pin of the ultrasonic sensor with the ground pin of Arduino board.

Connect the VSS pin of LCD display with the ground pin.

Connect the VDD pin of LCD display with the 5V dc.

Connect the V0 pin of LCD display with a 10k potentiometer and connect other two pins of the pot to ground and 5V dc.

Connect the RS pin of LCD display with the pin 7 of Arduino board.

Connect the RW pin of LCD display with the ground pin.

Connect the E pin of LCD display with the pin 6 of Arduino board.

Connect the D4 pin of LCD display with the pin 5 of Arduino board.

Connect the RS pin of LCD display with the pin 4 of Arduino board.

Connect the RS pin of LCD display with the pin 3 of Arduino board.

Connect the RS pin of LCD display with the pin 2 of Arduino board.

Connect the A pin of LCD display with a 10k potentiometer and connect other two pins of the pot to ground and 5v dc.

Connect the K pin of LCD display with the ground pin.

Source code for Distance Measurement:

/*
 *distance meter using Arduino UNO
 * Code by STUDENTS ROOM
 * Website: https://www.studentsroom.in
 */

#include <LiquidCrystal.h>
#define echo 9  // define the echo pin
#define trigger 8  // define the trigger pin
LiquidCrystal lcd(7, 6, 5, 4, 3, 2); // initialize the library with the numbers of the interface pins
float time = 0;
float distance = 0;
void setup()
{
  pinMode (trigger, OUTPUT);
  pinMode (echo, INPUT);
  lcd.begin(16, 2);       // set up the LCD's number of columns and rows:
  lcd.setCursor(1, 0);    
  lcd.print("well come ");// Print a message to the LCD.
  lcd.setCursor(4, 1);
  lcd.print("studentsroom");// Print anather message to the LCD.
  delay (1000);
  lcd.clear();
  lcd.print("wait");
  delay (1000);
}

void loop()
{
  lcd.clear();
  digitalWrite(trigger, LOW);
  delayMicroseconds(2);
  digitalWrite(trigger, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigger, LOW);
  delayMicroseconds(2);
  time = pulseIn(echo, HIGH);
  distance = time * 340 / 20000;
  lcd.clear();
  lcd.print("Distance:");
  lcd.print(distance / 100);
  lcd.print("m");
  delay(1000);
}

Precautions:

Please do the circuit as per the circuit diagram. And use a dc power supply to activate the circuit.

Don’t give more than 5 v power source to the ultrasonic sensor.

 

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Insert math as
Block
Inline
Additional settings
Formula color
Text color
#333333
Type math using LaTeX
Preview
\({}\)
Nothing to preview
Insert