Arduino Tutorial 55: Measuring Distance With HC-SR04 Ultrasonic Sensor

This lesson builds on the work done in Lessons 53 and 55. In this lesson we use the Ultrasonic Sensor to build a distance sensor. The HC-SR04 ultrasonic sensor can be programmed to send out a ping, and then measure the time it takes to hear the echo of the ping come back, after bouncing off a target. Knowing the speed of sound allows us to calculate distance to the sensor.

The circuit uses the following Schematic:

HC-SR04-Schematic
Schematic for Connecting the HC-SR04 to an Arduino

This is the code we develop in the video

The sensor is part of our Elegoo Kit , so if you get this kit, you will be using the same hardware we are using. This project builds on the work we did in Lesson 53.

For this build we will be using an Arduino Nano, which allows the project to be built on a single breadboard. You can use the Arduino Uno if you do not have a Nano, and things will work out the same. The build neatness is also facilitated by using small straight jumper wires, which you can get HERE.