HC-SR04 ultrasonic sensor
Wire an HC-SR04 to a 5 V Arduino and learn how to measure an echo pulse without exposing a 3.3 V input to its 5 V output.

How it works
A short pulse on Trig starts a burst. The sensor reports the time of flight using the high duration of Echo. The signal travels to the object and back, so divide the distance traveled by two. An angled or soft target can return too little sound for a useful reading.
Pinout and wiring
Read the PCB markings: VCC, Trig, Echo and GND. Connect VCC to 5 V and join grounds. Trig goes from the controller to the sensor. Echo goes the other way; use a suitable level shifter or divider before a 3.3 V GPIO.
Timing and timeouts
Give Trig a pulse at least 10 microseconds wide. Leave enough time between triggers for old echoes to decay; the supplier sheet suggests a cycle longer than 60 ms. When reading Echo in code, set a timeout and treat a timeout as missing data instead of zero distance.
Specifications
| Parameter | Value or condition | Source |
|---|---|---|
| Module supply | 5 V for the standard HC-SR04 | SparkFun |
| Quoted measuring range | 2 cm to 4 m with a suitable target | SparkFun |
| Ultrasonic burst frequency | 40 kHz | SparkFun |
Compatibility and practice
Direct logic connection on a standard 5 V Uno; level-shift Echo for a 3.3 V input.
Related components
Sources and datasheets
- HC-SR04 module datasheet · SparkFun