Distance Measurement using Ultrasonic Sensor and Arduino

Ultrasonic sensors are great tools to measure distance and detect objects without any actual contact with the physical world. It is used in several applications, like in measuring liquid level, checking proximity and even more popularly in automobiles to assist in self-parking or anti-collision systems. Previously we have also build many Ultrasonic Sensor projects like water level detectingUltrasonic Radar etc . This is an efficient way to measure small distances precisely. In this project, we have used the HC-SR04 Ultrasonic Sensor with Arduino to determine the distance of an obstacle from the sensor. The basic principle of ultrasonic distance measurement is based on ECHO. When sound waves are transmitted in the environment then waves return back to the origin as ECHO after striking on the obstacle. So we only need to calculate the traveling time of both sounds means outgoing time and returning time to origin after striking on the obstacle. As the speed of the sound is known to us, after some calculation we can calculate the distance. We are going to use this same technique for this Arduino distance measurement project, so let’s get started.  

Distance Measurement using Ultrasonic Sensor and Arduino

Components Used

  1. Arduino Uno or Pro Mini
  2. Ultrasonic sensor Module
  3. 16×2 LCD
  4. Scale
  5. Bread board
  6. 9 volt battery
  7. Connecting wires

Ultrasonic Sensor Module

There are many types of Arduino distance sensors, but in this project we have used the HC-SR04 to measure distance in range of 2cm-400cm with an accuracy of 3mm. The sensor module consists of an ultrasonic transmitter, receiver and control circuit. The working principle of ultrasonic sensor is as follows:

  1. High level signal is sent for 10us using Trigger.
  2. The module sends eight 40 KHz signals automatically, and then detects whether pulse is received or not.
  3. If the signal is received, then it is through high level. The time of high duration is the time gap between sending and receiving the signal.

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

Ultrasonic Sensor HC SR04 Distance Measurement using Ultrasonic Sensor and Arduino

Timing Diagram

The module works on the natural phenomenon of ECHO of sound. A pulse is sent for about 10us to trigger the module. After which the module automatically sends 8 cycles of 40 KHz ultrasound signal and checks its echo. The signal after striking with an obstacle returns back and is captured by the receiver. Thus the distance of the obstacle from the sensor is simply calculated by the formula given as

            Distance= (time x speed)/2.

Here we have divided the product of speed and time by 2 because the time is the total time it took to reach the obstacle and return back. Thus the time to reach obstacle is just half the total time taken.

Ultrasonic sensor timing di

Ultrasonic Sensor Arduino Circuit Diagram and Explanation

Arduino Distance Measurement Using Ultrasonic Sensor circuit

The circuit diagram for arduino and ultrasonic sensor is shown above to measure the distance. In circuit connections Ultrasonic sensor module’s “trigger” and “echo” pins are directly connected to pin 18(A4) and 19(A5) of arduino. A 16×2 LCD is connected with arduino in 4-bit mode. Control pin RS, RW and En are directly connected to arduino pin 2, GND and 3. And data pin D4-D7 is connected to 4, 5, 6 and 7 of arduino.

First of all we need to trigger the ultrasonic sensor module to transmit signal by using arduino and then wait for receive ECHO. Arduino reads the time between triggering and Received ECHO. We know that speed of sound is around 340m/s. so we can calculate distance by using given formula:

Distance= (travel time/2) * speed of sound

Where speed of sound around 340m per second.

A 16×2 LCD is used for displaying distance.

For More Details: Distance Measurement using Ultrasonic Sensor and Arduino

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top