01How it works
The HC-SR04 sends a 40 kHz pulse from the TRIG transmitter and listens on ECHO. Time of flight × speed of sound / 2 = distance.
02Wiring & code
- VCC → 5V, GND → GND, TRIG/ECHO → any GPIO.
- On 3.3V boards use a voltage divider on ECHO.
- distance_cm = pulseIn(echo, HIGH) / 58.
03Accuracy tips
Surface angle matters — soft or angled surfaces scatter the pulse. Average 3–5 readings for a stable value.
04Projects
- Parking assistant.
- Water-tank level.
- Obstacle-avoiding robot.



