LESSONSensors · Part 5EP.207 · 24 s

Sensors Part 5: the ultrasonic sensor HC-SR04 — measuring distance with sound

// WHAT YOU WILL LEARN

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.

// LESSON NOTES

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)
  1. How does a car know the wall is close? Sound!
  2. This sensor has two ears: one shouts, one listens!
  3. It chirps at forty kilohertz, too high to hear.
  4. The echo bounces back, and the Arduino times it.
  5. One millisecond. How far?
  6. About seventeen centimetres!
  7. Time times speed, then halve it!
  8. Next: the sensor that sees you walk in. Follow for Part 6!

Related lessons