Bats find insects by listening for echoes. A cheap ultrasonic sensor does the same with a click too high for us to hear.
Key idea
The sensor sends a pulse of sound and times the echo. Sound goes there and back, so $d = \dfrac{v\,t}{2}$, with $v \approx 343\ \text{m/s}$ in room-temperature air. A closer formula is $v \approx 331 + 0.6\,T$ m/s, with $T$ in Β°C.
Why it works
Sound is slow enough to time with a microcontroller: 1 meter away gives an echo after about 5.8 ms. Soft, angled or very small objects send back weak echoes, so these sensors can miss things a camera would see.
Worked example: Echo time to distance
An echo after 1,750 Β΅s.
- $343 \times 0.00175 \approx 0.600\ \text{m}$ round trip.
- Half: about 0.30 m.
Answer: About 30 cm.
Common mistake
Forgetting to halve the round trip, which makes every object look twice as far as it is.