The HC-SR04 measures a 15-degree cone, not a point, and its useful range is closer to 3–250 cm than the 2–400 cm on the listing. It is the right first distance sensor for a ₹1,000 robot. It is the wrong sensor for a soft curtain, a glass door or a robot that needs millimetre accuracy.
Key specifications
| Operating voltage | 5 V |
|---|---|
| Current | about 15 mA |
| Range | 2–400 cm claimed, 3–250 cm realistic |
| Beam angle | about 15 degrees |
| Trigger pulse | 10 microseconds |
| Echo | pulse width proportional to distance |
| Accuracy | about 3 mm at close range |
| Update rate | about 50 ms per reading |
Substitute: VL53L0X time-of-flight for short range and soft targets, or JSN-SR04T for a waterproof probe.
How it measures
The module has a transmitter and a receiver. Pull TRIG high for 10 microseconds, and the board fires a burst of ultrasonic pulses. ECHO goes high until the echo returns, and the width of that pulse is proportional to the round trip. The usual conversion is distance in centimetres = echo time in microseconds ÷ 58, or distance in inches = time ÷ 148. The 58 comes from the speed of sound at room temperature; cold air changes it by roughly 0.6 m/s per degree Celsius, which is a few millimetres over two metres.
The sensor cannot tell you where inside the cone the reflection came from. A chair leg at 40 cm and a wall at 90 cm can produce readings that jump between the two, depending on which surface returns more energy. That is why a single reading is not enough for a robot; take several and use the median.
Wiring and logic levels
- VCC to 5 V. The module is not a 3.3 V device; it may work below 5 V but the range and accuracy drop.
- GND to the common ground.
- TRIG to any digital output. A 10 µs pulse starts a measurement.
- ECHO to a digital input. The pulse is 5 V, so an ESP32 or other 3.3 V board needs a divider (for example 1 kΩ and 2 kΩ) or a level shifter.
Never connect the 5 V echo directly to a 3.3 V GPIO and hope. Some boards tolerate it briefly; the datasheet does not. A two-resistor divider costs a few rupees and removes the risk.
A reading you can trust
Trigger low for 2 µs, then high for 10 µs, then read the echo with a timeout. A timeout matters: if no echo returns, pulseIn() will otherwise wait for its default period and stall your control loop. At 58 µs per centimetre, 30,000 µs corresponds to about 5 metres, which is a sensible upper bound. Discard zero readings, take three samples spaced by at least 20 ms, and use the median rather than the mean. The sensor needs roughly 50 ms between measurements; hammering it faster produces echoes from the previous burst.
On a moving robot, mount the sensor at bumper height and keep the transducers clear of the chassis. Recessing it in a tube creates ringing that the receiver hears as a close object. Two HC-SR04 sensors facing the same direction will interfere; trigger them alternately or separate them by more than a metre if they must run together.
Failure modes and what they look like
| Reading | Likely cause | Check |
|---|---|---|
| Always 0 | No echo, wrong pin, no common ground, or trigger pulse too short. | Scope or serial-print the echo width; verify TRIG with an LED test. |
| Stuck at maximum | Object is out of range, too soft, or angled away. | Test against a flat wall at 30–100 cm. |
| Random jumps | Cross-talk, supply noise, or a reflective floor. | Increase the interval, add a capacitor, mount higher. |
| Consistently short | Soft target, narrow object, or the chassis is in the cone. | Move the sensor forward; test with a hard board. |
| Works on USB, fails on battery | Supply sag or a missing ground. | Measure 5 V at the module while measuring. |
When the HC-SR04 is the wrong choice
- Soft or angled targets: curtains, foam, clothing and sloped surfaces absorb or deflect the pulse. Use a time-of-flight sensor or a short-range IR sensor.
- Outdoors in wind or rain: the air path is disturbed and the module is not sealed. Use a waterproof JSN-SR04T probe, accepting its slower response.
- Very close work: below about 3 cm the sensor is in its blind zone. A VL53L0X time-of-flight sensor is better for 3–120 cm.
- Precision mapping: the cone is wide and the reading is an average of whatever it hits. Use a scanning lidar or a camera if you need geometry.
Common questions
Why does the HC-SR04 read 0 cm?
No echo returned within the timeout, or the echo pin is not connected to the right input. Check the common ground, the trigger pulse and the timeout in your code.
Can I connect the echo pin directly to an ESP32?
No. The echo is a 5 V signal and the ESP32 is a 3.3 V device. Use a resistor divider or a level shifter.
What is the real maximum range?
About 250 cm against a flat, hard target in still air. The 400 cm figure assumes ideal conditions that a classroom robot rarely has.
How often can I take a reading?
About every 50 ms. Faster reads can pick up the previous burst and produce false close readings.
Related: obstacle avoiding robot, ESP32 robot car, Arduino Uno guide, where to buy parts.
Keep reading
- HC-SR04 readings jumping — Four fixes before you add a filter.
- Smart dustbin with Arduino — A complete build using this sensor.
- Obstacle avoiding robot with Arduino — Scanning with the same sensor on a servo.
Sources and further reading
Documents used to check the numbers on this page:
- HC-SR04 datasheet — timing and range figures.
- Arduino Language Reference — pin functions, timings and library behaviour.
Last reviewed: October 2026. Specifications checked against common HC-SR04 datasheets. Prices are Indian retail ranges.
Where to buy in India
These open a store search. Compare seller, price and reviews before you order.
