Seminars & Reports
ReportApril 3, 2025

HC-SR04: Distance with sound

Measure 2 cm to 4 m with a $2 ultrasonic module.

HC-SR04: Distance with sound

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.
Related part

Seminars & Reports