Fork me on GitHub

Project Notes

#035 RangeFinder

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


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.


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

The Breadboard

The Schematic

The Build

Credits and References

Project Source on GitHub Project Gallery Return to the LEAP Catalog

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

LEAP is just my personal collection of projects. Two main themes have emerged in recent years, sometimes combined:

  • electronics - 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
  • scale modelling - I caught the bug after deciding to build a Harrier during covid to demonstrate an electronic jet engine simulation. Let the fun begin..
To be honest, I haven't quite figured out if these two interests belong in the same GitHub repo or not. But for now - they are all here!

Projects are often inspired by things found wild on the net, or ideas from the many great electronics and scale modelling podcasts and YouTube channels. Feel free to borrow liberally, and if you spot any issues do let me know (or send a PR!). See the individual projects for credits where due.