Tag Archives: Ultrasonic

Arduino Tutorial 59: How To Build a Portable Distance Sensor Ultrasonic Sensor

This is our completed build of a portable, ultrasonic distance sensor.

This Lesson picks up where Tutorial 55 left off. You want to take the basic distance measurement capability you built, and make it portable. In order to make it portable, you will need to add an LCD display, and figure out a way to power it. The easiest way to get portable power is to connect the Arduino to a USB power bank.

The sensor is part of our Elegoo Kit , so if you get this kit, you will be using the same hardware we are using.

A challenge with this project is to keep your build nice and neat, as there are lots of connections, and if any are not completely secure, you will get unpredictable performance in your device. 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.

The first task will be to lay out your components in preparation for the build. Carefully consider all the connections you will have to make, and then organize so that the connections can be made with minimum confusion. This means minimize the number of crossing wires, and try to have needed connections in the same general area.

The LCD will need to be wired up according to the following Schematic:

This schematic will allow you to connect the LCD to the Arduino

Now, you will also need to connect the HC-SR04 Ultrasonic Sensor.

HC-SR04 Pin Arduino Pin
VCC 5 V
GND GND
Trig digital 2
Echo digital 3

This video takes you through the build and programming step-by-step.


In this video we developed the following code:

 

Arduino Tutorial 53: Understanding and Connecting the HC-SR04 Sensor

This is our HC-SR04 Ultrasonic Sensor Connected to our Arduino Nano.

In this lesson we explore using the HC-SR04 from our Arduino Kit to measure distance. The sensor sends out a ping, and then waits to hear the echo. It measures the time between when the ping is sent and when the echo is heard. Knowing pingTravelTime, allows you to calculate distance from the sensor. In this lesson we will show you how to connect the sensor, and program it to read pingTravelTime. In future lessons we will show you how to change this into distance.

Notice we used an Arduino Nano, which allows the entire project to be build on a single breadboard. This allows a neater, smaller build, and one less likely to have problems from poor or loose connections. The build neatness is also facilitated by using small straight jumper wires, which you can get HERE.

Connecting up the HC-SR04 sensor is simple, as illustrated in this diagram:

Schematic for Connecting the HC-SR04 to an Arduino

This video will take you through our build and initial work step-by-step.

The simple code below is what we used in the video to begin making measurements with the sensor.