Fork me on GitHub

Project Notes

#035 RangeFinder

Use an Arduino to measure range with HC-SR04 module and output to 16x2 LCD.

Notes

The HC-SR04 ultrasonic ranging module provides 2cm-400cm non-contact measurement. It is a 5V unit and can be powered from the Arduino 5V pin.

When triggered, the echo pin goes high until the pulse is returned. Reading the high pulse duration with the pulseIn function thus returns the round-trip time in microseconds. The distance is calculated based on speed of sound, and divided by 2 to eliminate the return trip component.

distance = high pulse duration × speed of sound  / 2

In practice, I found I had to calibrate the calculation to account for local conditions and variations in unit accuracy. Once calibrated however, the distance measurement accuracy is pretty good, although I don’t think quite the 3mm as advertised.

LCD Output

Output is sent to an 16x2 LCD display. The LiquidCrystal library works with all LCD displays that are compatible with the Hitachi HD44780 driver. There are many of them out there, and you can usually tell them by the 16-pin interface.

A variable resistor is used to trim contrast, and the LCD backlight is powered from the 5V rail.

Construction

NB: schematics use non-standard HC-SR04 Fritzing Part

The Breadboard

The Schematic

The Build

Credits and references

About LEAP#35 SensorsArduinoHC-SR04
Project Source on GitHub Return to the LEAP Catalog

This page is a web-friendly rendering of my project notes shared in the LEAP GitHub repository.

LEAP is my personal collection of electronics projects, usually involving an Arduino or other microprocessor in one way or another. Some are full-blown projects, while many are trivial breadboard experiments, intended to learn and explore something interesting (IMHO!).

The projects are usually inspired by things found wild on the net, or ideas from the sources such as:

Feel free to borrow liberally, and if you spot any issues do let me know. See the individual projects for credits where due. There are even now a few projects contributed by others - send your own over in a pull request if you would also like to add to this collection.