The Principles of Sonar Echolocation
Bats and dolphins navigate murky waters and dark caves by emitting high-frequency ultrasonic clicks and listening for reflections. The HC-SR04 ultrasonic distance sensor operates on the exact same acoustic principle.
Calculating Distance via Speed of Sound
The sensor sends a 10-microsecond trigger pulse, emitting eight 40kHz sonic burst cycles. It measures the duration (time in microseconds) until the acoustic wave bounces back to the receiver pin:
Distance (cm) = (Travel Time × 0.0343 cm/μs) / 2
We divide by 2 because the acoustic pulse travels to the obstacle and returns back.
Reactive Navigation State Machines
Students write state machine logic for their robot car:
- If distance > 25 cm: Drive forward at 80% throttle.
- If distance ≤ 25 cm: Stop motors, rotate servo sensor to scan left and right, evaluate which path has greater clearance, and execute a 90-degree pivot turn.