Circuits / Sensors
Arduino UNO: HC-SR04 distance meter
TRIG starts a ping; ECHO stays high for the round trip of the sound, and pulseIn measures it: microseconds ÷ 58 is centimetres

Tap a part to see its voltages and currents. It is a model, not a measurement.
What do you need?
- Development board Arduino UNOAliExpress Amazon
- Ultrasonic distance sensor HC-SR04AliExpress Amazon
- Jumper wires × 5AliExpress Amazon
- BreadboardAliExpress Amazon
The AliExpress links are affiliate links: if you buy through them ohmio.dev gets a commission, at no extra cost to you. Affiliate links
This page is a guide: the numbers come from a simulation, and real parts vary. Check your parts before you power the circuit. Safety and responsibility
How does an HC-SR04 measure distance with sound?
The HC-SR04 measures time, not distance. A 10 µs pulse on TRIG makes it send a burst of 40 kHz sound. Then ECHO goes high and stays high until the echo comes back, so the width of that pulse is the round trip. For an object at 30 cm the model gives 1747 µs, with sound at 343.4 m/s at 20 °C. The UNO times it with pulseIn() and divides by 58, because sound covers 1 cm out and back in about 58 µs: 1747 / 58 gives 30. The model reads 2 for 2 cm, 100 for 100 cm and 401 for 400 cm, the end of the module's 2 to 400 cm range. Past that, pulseIn gives up after 30 ms and prints 0. The 58 assumes 20 °C: the same object at 100 cm reads 104 at 0 °C and 96 at 40 °C.
Values from the Protoboard ISO simulation: a model, not a bench measurement.
Hear about the next circuit
One email when a new circuit is out, about twice a month. Nothing else.