Distance Measurement Using Arduino & Ultrasonic Sensor

0
66

Ultrasonic sensors are excellent tools for measuring distances and detecting objects without making physical contact. It can be used to detect liquid levels, figure out how close you are, and more recently, to help with self-parking and anti-collision systems in cars. This is a quick and accurate way to measure tiny distances. To figure out how far away an object was from the sensor in this project, we used the HC-SR04 Ultrasonic Sensor and an Arduino to read the sound waves.ECHO is the fundamental basis of ultrasonic distance measurement. When sound waves travel through the environment, they return to the source as an echo after colliding with an impediment. So, after striking the obstruction, we only need to calculate the travel time of both noises, i.e., the departing time and the return time to the origin. Because we know the speed of sound, we can determine the distance with a little math. Let’s get started with this Arduino distance measurement project, where we’ll apply the same technique.

 

Components Used

  1. Arduino Uno
  2. Ultrasonic sensor Module
  3. 16×2 LCD
  4. Bread board
  5. 12 V Power Supply
  6. Connecting wires

Ultrasonic Sensor Module

There are numerous Arduino distance sensors available, but we used the HC-SR04 in this project to detect distances ranging from 2cm to 400cm with a 3mm precision. An ultrasonic transmitter, receiver, and control circuit make up the sensor module. The following is the ultrasonic sensor’s functioning principle:

A trigger is used to send a high-level signal for 10 seconds.

The module automatically broadcasts eight 40 KHz signals and then determines whether or not a pulse was received.

The signal is received at a high level if it is received at all. The time difference between transmitting and receiving the signal is known as the “high duration time.”

Time x Sound Speed in Air (340 m/s) / 2

Hardware Pin Details

 16×2 Lcd Module

  • GND  –       ARDUINO GND
  • 5V     –       ARDUINO 5V
  • RS     –       ARDUINO PIN 13
  • EN     –       ARDUINO PIN 12
  • D4     –       ARDUINO PIN 11
  • D5     –       ARDUINO PIN 10
  • D6     –       ARDUINO PIN 9
  • D7     –       ARDUINO PIN 8

 

ULTRASONIC SENSOR

  • VCC     –      ARDUINO 5V
  • TRIG   –      ARDUINO PIN 2
  • ECHO  –      ARDUINO PIN 4
  • GND   –       ARDUINO GND

ARDUINO UNO PROGRAM

#include <LiquidCrystal.h>

LiquidCrystal lcd(13,12,11,10,9,8);

const int trigPin = 2;

const int echoPin = 4;

int ledA0 = 7;

 

void setup()

  Serial.begin(9600);

  lcd.begin(16, 2);

}

 

void loop()

{

  long duration, inches, cm;

 pinMode(trigPin, OUTPUT);

  digitalWrite(trigPin, LOW);

  delayMicroseconds(2);

  digitalWrite(trigPin, HIGH);

  delayMicroseconds(10);

  digitalWrite(trigPin, LOW);

  pinMode(echoPin, INPUT);

  pinMode(ledA0,OUTPUT);

  duration = pulseIn(echoPin, HIGH);

  inches = microsecondsToInches(duration);

  cm = microsecondsToCentimeters(duration);

  lcd.setCursor(0,0);

  lcd.print(inches);

  lcd.setCursor(6,0);

  lcd.print(“inch”);

  lcd.setCursor(0,1);

  lcd.print(cm);

  lcd.setCursor(6,1);

  lcd.print(“cm”);

  delay(1000);

  lcd.clear();

}

 

long microsecondsToInches(long microseconds)

{

  return microseconds / 74 / 2;

}

long microsecondsToCentimeters(long microseconds)

{

  return microseconds / 29 / 2;

}

 

Project Video

LEAVE A REPLY

Please enter your comment!
Please enter your name here