Summary of How to Set Up an Ultrasonic Range Finder on an Arduino
Ultrasonic range finders like the HC-SR04 measure distance by emitting an ultrasonic pulse and timing its round-trip echo; using the speed of sound the Arduino computes distance. This tutorial shows three Arduino circuits: a simple setup and two more advanced versions that improve accuracy by compensating for temperature and humidity. The HC-SR04 works from 2 cm to 400 cm with ±3 mm accuracy and is useful for navigation, object avoidance, and motion detection. A downloadable quick start guide with diagrams and code is also provided.
Parts used in the HC-SR04 Range Finder Project:
- HC-SR04 ultrasonic range finder module
- Arduino board (e.g., Arduino Uno)
- Jumper wires
- Breadboard
- Power source for Arduino (USB cable or battery)
- Temperature sensor (for temperature-compensated circuits)
- Humidity sensor (for temperature and humidity-compensated circuit)
- Resistors as needed for sensor interfacing
- Mounting hardware or enclosure (optional)
Ultrasonic range finders are fun little modules that measure distance. You can use them to find the distance to an object, or to detect when something is near the sensor like a motion detector. They’re ideal for projects involving navigation, object avoidance, and home security. Because they use sound to measure distance, they work just as well in the dark as they do in the light. The ultrasonic range finder I’ll be using in this tutorial is the HC-SR04, which can measure distances from 2 cm up to 4oo cm with an accuracy of ±3 mm.

In this article, I’ll show you how to make three different range finder circuits for the Arduino. The first range finder circuit is easy to set up, and has pretty good accuracy. The other two are a bit more complicated, but are a bit more accurate because they factor in temperature and humidity. But before we get into that, lets talk about how the range finder measures distance.
The Speed of Sound
Ultrasonic range finders measure distance by emitting a pulse of ultrasonic sound that travels through the air until it hits an object. When that pulse of sound hits an object, it’s reflected off the object and travels back to the ultrasonic range finder. The ultrasonic range finder measures how long it takes the sound pulse to travel in its round trip journey from the sensor and back. It then sends a signal to the Arduino with information about how long it took for the sonic pulse to travel.
Knowing the time it takes the ultrasonic pulse to travel back and forth to the object, and also knowing the speed of sound, the Arduino can calculate the distance to the object. The formula relating the speed of sound, distance, and time traveled is:
Read more: How to Set Up an Ultrasonic Range Finder on an Arduino
- What does an ultrasonic range finder measure?
It measures distance to an object by emitting an ultrasonic pulse and timing the round-trip echo. - How does the Arduino calculate distance with the HC-SR04?
The Arduino uses the measured round-trip time of the ultrasonic pulse and the speed of sound to calculate distance. - What distance range does the HC-SR04 support?
The HC-SR04 can measure distances from 2 cm up to 400 cm. - How accurate is the HC-SR04?
The HC-SR04 has an accuracy of ±3 mm according to the article. - Do ultrasonic range finders work in the dark?
Yes, because they use sound rather than light, they work equally well in the dark. - Why would I use temperature and humidity sensors with the HC-SR04?
Adding temperature and humidity compensation improves accuracy because the speed of sound varies with temperature and humidity. - What applications are ideal for ultrasonic range finders?
They are ideal for navigation, object avoidance, and home security or motion detection projects. - Is there a quick start guide available for this tutorial?
Yes, the article includes a downloadable quick start guide covering steps, diagrams, and code.
