HC-SR04 Ultrasonic Distance Sensor & 3.3V Echo Divider Lab — Engineering Notes & Troubleshooting
Send a 10 µs TRIG pulse to fire eight 40 kHz ultrasonic chirps and measure how many microseconds ECHO stays HIGH to compute distance! Critical Warning: HC-SR04 outputs 5 V on ECHO — add a 1 kΩ + 2 kΩ voltage divider when wiring to a 3.3V ESP32 or Raspberry Pi!
Blind zone is < 2 cm (ringing overwhelms receiver); maximum reliable range is ~400 cm on flat hard surfaces.
- Distance formula: d (cm) = Echo_µs × 0.0343 ÷ 2 ≈ Echo_µs ÷ 58.2 (divide by 2 because sound travels to the object AND back!).
- Wait at least 60 ms between measurements so stray acoustic echoes from the previous ping die out cleanly.
- 3.3V Board Safety: Standard HC-SR04 needs 5V VCC and sends 5V back on ECHO. Use a 1 kΩ / 2 kΩ resistor divider on ECHO (or buy the 3.3V-native HC-SR04P) for ESP32 & Raspberry Pi!
| Symbol | Component | Real-World Engineering Tip |
|---|---|---|
| US1 | HC-SR04 40 kHz Ultrasonic Module | Speed of sound shifts slightly with air temperature: c ≈ 331.3 + 0.606 × Temp(°C) m/s. |
Real-World Bench Scenario: Obstacle-Avoiding Robot & Smart Water Tank Level Monitor: pair HC-SR04 with an ESP32 (plus 1kΩ/2kΩ echo divider) and a waterproof JSN-SR04T probe outdoors!
Bench Challenge: Board Switch Test: Switch controller to 'ESP32 / Raspberry Pi (3.3V)' with Echo Divider OFF to trigger the 5V GPIO Over-Voltage Hazard, then enable the 1kΩ+2kΩ divider!