Why Your Ultrasonic Sensor Lies to You
You mount an HC-SR04 ultrasonic sensor. You write the code. You measure the distance to the object.
The object is 50cm away. The sensor reads 48cm. You move it to 100cm. The sensor reads 97cm. Close enough, right?
Then you try to use it in your interactive installation. Someone walks in front of it. The sensor reads 30cm. Someone else steps behind them. The sensor reads 28cm. Or 35cm. Or nothing at all.
The HC-SR04 is not lying to you. But it is not telling you the truth either. It is giving you one number, and you are drawing conclusions from it that the data does not support.
What the HC-SR04 Actually Measures
The HC-SR04 works by emitting an ultrasonic burst and measuring the time until the echo returns. The calculation is simple: distance = time × speed_of_sound / 2.
The speed of sound is 340m/s. At 20°C in air. At sea level. In dry air.
Your environment is probably none of those things.
Temperature: Sound travels at 340m/s at 20°C. At 0°C it is 331m/s. At 30°C it is 349m/s. A 10°C change introduces a 2.6% error. In an outdoor installation in direct sunlight, your temperature sensor might read 35°C while the air near the ground is 40°C. That is enough to throw your distance measurement off by 5-10%.
Humidity: Sound travels faster in humid air. The difference between dry air and 80% humidity at room temperature is about 0.5%. Negligible for most indoor projects, but significant if you are trying to measure sub-centimeter accuracy.
Angle: The HC-SR04 has a 15-degree beam angle. If the object is at an angle, the sound wave bounces off at a slightly different path. You get a longer time-of-flight, which your code interprets as a farther object. The sensor is not designed for angled surfaces.
Surface material: Hard, flat surfaces reflect sound well. Soft, absorptive surfaces — fabric, foam, acoustic tiles — absorb sound and give weak or no echoes. You might think no one is there when they are standing in front of your installation wearing a thick wool sweater.

Photo by LED Architectural Machine project via Hackster.io
The Three Failure Modes
Failure Mode 1: The Phantom Object
Your sensor reads a steady 45cm even when nothing is in front of it. This is usually caused by thermal drift or electrical interference. The sensor is reading the temperature of the room and converting it to a distance reading. Or it is picking up ultrasonic noise from the environment — fluorescent lights, air conditioning, ultrasonic humidifiers.
The fix: add a minimum threshold. Ignore any reading below 2cm or above the maximum reliable range of your sensor. For the HC-SR04, the reliable range is about 2cm to 400cm, but the sweet spot is 10cm to 200cm.
Failure Mode 2: The Jumpy Reading
Your sensor reads 48cm, then 52cm, then 46cm, then 50cm for the same static object. This is normal. The HC-SR04 has a resolution of about 0.3cm, but a repeatability of about 0.2% of the reading. At 50cm, that is ±0.1cm from the sensor alone. Add temperature variation and surface reflection noise, and you get ±2-3cm easily.
The fix: use a moving average or median filter. Take 5-10 readings and use the median. Discard outliers. This alone will reduce your noise by 80%.
Failure Mode 3: The Missing Reading
Your sensor returns 0cm or reads infinity when someone stands in front of it. This usually means the echo never returned — the sound was absorbed by the person's clothing or scattered by an angled surface.
The fix: for interactive installations, use multiple sensors at different angles. Or accept that the HC-SR04 is not reliable for your use case and switch to a PIR sensor for presence detection or a time-of-flight sensor like the VL53L0X for more accurate distance measurement.
How to Use It Correctly
The HC-SR04 is fine for projects where you need to know approximate distance — Is the person close or far? Is the water level high or low? Is the garbage can full or empty?
It is not fine for projects where you need precise measurement — What is the exact distance to within 1cm? Is the person's head at 120cm or 125cm?
For interactive art, approximate is usually fine. If you are using it to trigger effects when people get within 50cm, the HC-SR04 will work reliably 90% of the time.
The other 10%: design your interaction to gracefully handle the sensor being wrong. Do not design an interaction that requires exact positioning. Design it to respond to general proximity with a tolerance of ±10cm.
FAQ
Q: Can I use the HC-SR04 outdoors?
A: Not reliably. Direct sunlight creates temperature gradients in the air that distort ultrasonic measurements. Wind scatters the sound beam. Rain droplets reflect the sound back early, giving false close readings. Outdoor proximity detection is better served by PIR sensors or millisecond-wave radar sensors.
Q: The VL53L0X is more accurate. Should I just use that instead?
A: If you need sub-centimeter accuracy or need to measure through glass, yes. The VL53L0X uses a laser instead of ultrasonic and is not affected by temperature, humidity, or surface material in the same way. It is also more expensive ($5-10 vs $2 for the HC-SR04) and requires I2C communication instead of two GPIO pins.
The Next Step
Before mounting your HC-SR04 permanently, test it in your actual environment with your actual materials. Stand where your audience will stand. Wear what your audience will wear.
If the readings are stable enough for your interaction, proceed. If not, change the sensor or change the interaction design to tolerate the sensor's limitations.
Product recommendations:
HC-SR04 Ultrasonic Sensor (4-Pack) — The standard for maker proximity projects. $2-3 per unit. Reliable within its limitations. (Amazon)
VL53L0X Time-of-Flight Laser Ranger — For projects requiring higher accuracy. Laser-based, not affected by temperature or surface material. More expensive but more reliable for precise measurement. (Amazon)
I earn from qualifying purchases.
Article #007, 2026-04-18. Content Farm pipeline, Run #007.
Top comments (0)