Distance Measurement Using Arduino & HC-SR04 Ultrasonic Sensor

Distance Measurement Using Arduino & HC-SR04 (Last Updated On: February 25, 2019)

Distance Measurement Using Arduino & HC-SR04 Ultrasonic Sensor:

In this project we are going to interface Ultrasonic sensor HC-SR04 with Arduino and LCD Display. Ultrasonic sensor is used to measure the distance. It acts as a Sonar. It sends an ultrasonic wave of certain frequency which comes back after hitting the object and calculates the time traveled by it. So lets learn about Distance Measurement Using Arduino & HC-SR04 Ultrasonic Sensor.

Components Required:

1. Arduino Uno Board
2. Ultrasonic Sesnor HC-SR04  - (Buy Online from Amazone)
3. 16*2 LCD Display
4. Breadboard
5. Connecting Wires
6. 5V Power Supply

Ultrasonic Sensor HC-SR04:


The HC-SR04 ultrasonic sensor uses sonar to determine distance to an object like bats do. It offers excellent non-contact range detection with high accuracy and stable readings in an easy-to-use package.

Distance Measurement Using Arduino & HC-SR04

From 2cm to 400 cm or 1” to 13 feet. Its operation is not affected by sunlight or black material like sharp rangefinders are (although acoustically soft materials like cloth can be difficult to detect). It comes complete with ultrasonic transmitter and receiver module.


The specifications of the ultrasonic distance sensor HC-SR04 are below:

1. Minimum measuring range - 2 cm
2. Maximum measuring range : 400 cm or 4 meter
3. Accuracy : 3 mm
4. Operating Voltage : +5V
5. Operating Current : 15mA
6. Working Frequency : 40 KHz
7. Trigger Input signal : 10us pulse
8. Measuring angle : 15 degree


1. VCC: +5VDC
2. Trig : Trigger (INPUT)
3. Echo: Echo (OUTPUT)

How Does it Work?

Ultrasonic sensors emit short, high-frequency sound pulses at regular intervals. These propagate in the air at the velocity of sound. If they strike an object, then they are reflected back as echo signals to the sensor, which itself computes the distance to the target based on the time-span between emitting the signal and receiving the echo.

Distance Measurement Using Arduino & HC-SR04

We will have to convert this time into cm to calculate the distance traveled. We will use the following equation to calculate the distance.

S = v * t

Ultrasonic wave is basically a sound wave which travels at a speed of 340 m/s (0.034 cm/s). The ultrasonic sensor is measuring the time it takes to hit the object and then come back but we need only time that it takes to hit the object. So, we will divide it by 2.

S = (t * 0.034)/2

Circuit Diagram & Connections:

Distance Measurement Using Arduino & HC-SR04

Source Code/Programs:

For project Distance Measurement Using Arduino & HC-SR04 Ultrasonic Sensor, copy this code then compile and upload to your Arduino board.But before that you need to add the NewPing library first. So download from below.

Download NewPing.h Library

#define trig A5
#define echo A4
#define maximum 400
int usec;
int cm;
float inch;
NewPing sonar(trig, echo, maximum);
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
void setup()

void loop()
{ lcd.clear();
lcd.print("Distance Finder");

Recommended For You

Ask A Question .......