What the echo measures
The sensor never measures a distance. It measures a length of time, and hands it to you as the width of a pulse — which is why the first number most people print is roughly double what they expected.
A burst, a wall, and a stopwatch
Press the button and watch one measurement happen. The slider moves the wall.
The whole part is those six steps. Your board asks for a reading; the transmitter can emits a short burst of 40 kHz sound; that burst crosses the room, bounces off whatever is in front of it, and comes back; the receiver can hears it. In between, the sensor holds its ECHO pin high, and it lets go the instant the echo arrives.
So what reaches your microcontroller is a pulse, and the only information in it is how long it lasted.
The arithmetic
Sound travels about 343 metres per second in air at 20 °C. That is 34 300 centimetres per second, or 0.0343 cm per microsecond — slow enough that an ordinary microcontroller can time it with an ordinary timer, which is the whole reason this technique is cheap.
The pulse covers the trip out and the trip back, so:
distance = (microseconds / 2) × 0.0343
The divide-by-two is the step people drop. Nothing warns you when you do: the readings look stable, they track the object smoothly, and everything is simply twice as far away as it is.
Why 40 kHz
Two reasons, and they pull in the same direction. It is above human hearing, so a room full of these is silent. And a shorter wavelength spreads less, which is what gives the sensor a cone to aim rather than a sphere to wonder about.
The cost is that 40 kHz is absorbed quickly by soft things. A curtain returns almost nothing, and there is no "weak reading" to notice — there is simply no echo, and a sketch that has not planned for that will report a confident zero. The honest range is where that gets sorted out.
Which of these you actually do
None of it, if you use a bus. In GPIO mode the microseconds are yours and so is the arithmetic. In I2C or UART mode the chip does the timing and the division and hands you a finished distance, which is three bytes of micrometres.
That choice is made with a soldering iron rather than in code, and it is the subject of most of this handbook.
When it does not work
The divide-by-two is missing. The sound crosses the gap twice, out and back, so the time you measured covers double the distance you want. Halve it before multiplying by the speed of sound, not after.
No, and neither can most animals you live with. The burst is at 40 kHz, roughly twice the top of adult human hearing. A phone microphone will not pick it up either, so there is no way to confirm the sensor is firing except by reading the echo pin.
The dark is irrelevant — this is sound, not light, so it works in a pitch-black room exactly as well as a lit one. Glass is the opposite problem: it is hard and flat, so it reflects the burst beautifully and the sensor reports the window rather than what is behind it.
One transmits and one listens, and they are different parts. A single transducer would still be ringing from its own burst when the first echo arrived, which is the same reason there is a blind zone in front of the board at all.
Why the part in the box is not the part on the label, and what that changes.
Not the HC-SR04 you know →Edit this page — content/books/ultrasonic-sensor/what-the-echo-measures.mdx
Questions about this product
See what other owners have asked, and read their solutions.
Ultrasonic Distance Sensor
Loading discussions…
Discuss this article
Ask about this page. The answer stays here, on the page it belongs to, for whoever hits the same wall next.