In this tutorial, we learn how to measure the distance by using the Ultrasonic Sensor with Arduino. We also use an LCD 16×2 Display to show the distance.
An ultrasonic sensor is used to measure the distance to an object using sound waves. It provides measurements of the time that takes the sound to fling something and return it to the sensor. Read More
It works on sound wave frequency like sonar. The ultrasonic sensor also cannot detect some objects.
HC-SR04 ultrasonic can measure a range of 2 cm to 400 cm (4 m).

This sensor has 2 openings on its front. One is the transmitter which transmits ultrasonic waves like a speaker and the other is a receiver that receives them like a microphone.
Components List
- Ultrasonic Sensor (HC-SR04)
- Arduino Uno
- Jumper Wires
- LCD Display 16×2
Pin Connections
Ultrasonic Pins | Arduino Pins |
---|---|
5v or Vin | 5V |
GND | GND |
Trigger | 9 |
Echo | 8 |
Circuit Diagram for Ultrasonic Sensor With Arduino

Code For Ultrasonic Sensor Arduino
Output

Ultrasonic Sensor and LCD 16×2 with Arduino
Now we are displaying the distance reading (sensor values) of the ultrasonic sensor on an LCD Display 16×2.
Read More about LCD 16×2:
Pin Connections of LCD 16×2 with Arduino
Pin No. | LCD Pins | Arduino Pins |
---|---|---|
1 | VSS/GND | GND |
2 | VDD/VCC | 5v |
3 | V0 | Potentiometer Vout |
4 | RS | 12 |
5 | RW | GND |
6 | E | 11 |
7-10 | D0-D3 | No connection |
11 | D4 | 5 |
12 | D5 | 4 |
13 | D6 | 3 |
14 | D7 | 2 |
15 | A/LED+ | 5v |
16 | K/LED- | GND |
Circuit Diagram of Ultrasonic Sensor and LCD

Code
Output
