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

Ultrasonic Distance 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:

Arduino LCD 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 PinArduino Pin
VCC5 V
GNDGND
Trigdigital 2
Echodigital 3

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


In this video we developed the following code: