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

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

Project Source on GitHub Return to the LEAP Catalog
About LEAP

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.

Projects are often inspired by things found wild on the net, or ideas from the many great electronics podcasts and YouTube channels. Feel free to borrow liberally, and if you spot any issues do let me know or send a pull-request.

NOTE: For a while I included various scale modelling projects here too, but I've now split them off into a new repository: check out LittleModelArt if you are looking for these projects.

Project Gallery view the projects as an image gallery Notebook reference materials and other notes Follow the Blog follow projects and notes as they are published in your favourite feed reader