Ultrasonic Sensor with Arduino

1
17

In this tutorial, we learn how to measure the distance by using the Ultrasonic Sensor with Arduino. We also use an LCD 16x2 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.

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).

ultrasonic sensor
Ultrasonic Sensor

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.

Pin Connections

Ultrasonic Pins Arduino Pins 
5v or Vin 5V
GND GND
Trigger 9
Echo 8

Circuit Diagram of Ultrasonic Sensor With Arduino

Circuit Diagram of Ultrasonic Sensor With Arduino

Code For Ultrasonic Sensor Arduino

Output

Output of Ultrasonic Sensor with Arduino

Ultrasonic Sensor and LCD 16x2 with Arduino

Now we are displaying the distance reading (sensor values) of the ultrasonic sensor on an LCD Display 16x2.

Pin Connections of LCD 16x2 with Arduino

Pin No. LCD Pins Arduino Pins
1 VSS/GND GND
2 VDD/VCC 5v
3 V0 Potentiometer Vout/Wiper
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

distance measurement using ultrasonic sensor and arduino with lcd display

Code

Output

Our Youtube Channel