Sensors Part 5: the ultrasonic sensor HC-SR04 — measuring distance with sound
The HC-SR04 sends a 40 kHz chirp (too high to hear) and times the echo (ECHO pin HIGH, pulseIn()); distance = time × 343 m/s ÷ 2, so 1 ms ≈ 17 cm.
How does a car know the wall is close? SOUND! 🔊🚗
👂 The HC-SR04 has two "ears": T shouts, R listens.
🦇 It chirps at 40 kHz — 40,000 times a second, too high for people to hear (we hear about 20 Hz – 20 kHz).
↩️ The echo bounces back, and the ECHO pin stays HIGH for the whole trip — the Arduino times it with pulseIn().
🤔 Echo = 1 ms. How far is the wall?
✅ About 17 cm! Sound travels 343 m/s (at 20 °C / 68 °F): 0.001 s × 343 m/s = 34 cm there AND back ÷ 2 = 17 cm.
💻 In code: cm = t * 0.0343 / 2; (t in microseconds)
Parking sensors use the same echo trick.
Read the voiceover (transcript)
- How does a car know the wall is close? Sound!
- This sensor has two ears: one shouts, one listens!
- It chirps at forty kilohertz, too high to hear.
- The echo bounces back, and the Arduino times it.
- One millisecond. How far?
- About seventeen centimetres!
- Time times speed, then halve it!
- Next: the sensor that sees you walk in. Follow for Part 6!
Related lessons
Get new lessons + early access to the full course
One email when new lessons drop. No spam, unsubscribe any time.
✓ You're on the list! We'll email you when new lessons drop.
By joining you agree to the privacy policy.




