HC-SR04 Ultrasonic Distance Sensor Module - Arduino Compatible Proximity Detector
The HC-SR04 is the most widely used ultrasonic distance sensor in hobbyist electronics - it measures non-contact distance from 2 to 450cm with 3mm accuracy using a simple 4-pin interface that any microcontroller can drive. Send a 10 microsecond HIGH pulse on the Trig pin, and the module emits eight 40kHz ultrasonic bursts. The Echo pin goes HIGH for a duration proportional to the round-trip travel time of the sound wave; divide by 58 to get distance in centimeters.
The 15-degree detection angle works well for straight-ahead proximity detection without false positives from objects slightly off-axis. TTL-compatible signals connect directly to Arduino, ESP32, Raspberry Pi, and any 5V microcontroller. Note: use a voltage divider on the Echo pin for 3.3V microcontrollers like the ESP32.
Common project uses: Obstacle avoidance for robots and RC vehicles, parking sensors, liquid level monitoring, staircase lighting triggers, door or drawer proximity detection, and interactive installations. Libraries for the HC-SR04 are available for Arduino IDE (NewPing is recommended), MicroPython, and CircuitPython. Our Ultrasonic Parking Sensor Project Kit uses this exact sensor alongside an ESP32 and NE555 timer for a complete guided build - check the Projects section for the full guide.
Specifications
| Range | 2-450 cm |
|---|---|
| Accuracy | plus/minus 3mm |
| Detection Angle | 15 degrees |
| Interface | 4-pin (VCC, Trig, Echo, GND) |
| Operating Voltage | 5V DC |
| Signal | TTL compatible |
Frequently Asked Questions
How do I wire the HC-SR04 to an Arduino?
Connect VCC to Arduino 5V, GND to GND, Trig to any digital output pin, and Echo to any digital input pin. In code, send a 10-microsecond HIGH pulse to Trig, then measure how long Echo stays HIGH using pulseIn(). Divide the pulse duration in microseconds by 58 to get distance in centimeters. The NewPing Arduino library simplifies this to a single function call.
Can I use the HC-SR04 with an ESP32 or other 3.3V microcontroller?
The sensor requires 5V on VCC and outputs Echo at 5V logic, which exceeds the ESP32's 3.3V GPIO tolerance. Use a two-resistor voltage divider (1k ohm and 2k ohm) on the Echo line to bring it to a safe 3.3V before connecting to the ESP32. The Trig pin accepts 3.3V logic input without any conversion needed.
What is the minimum measurable distance?
The HC-SR04 has a minimum reliable measurement distance of approximately 2cm. Objects closer than 2cm may not trigger a valid Echo pulse, resulting in a timeout or zero reading. For very close-range sensing under 2cm, a capacitive or infrared proximity sensor is more appropriate.
How accurate is the HC-SR04 in real-world use?
In stable conditions the HC-SR04 achieves plus or minus 3mm accuracy at short to medium ranges up to about 200cm. Accuracy decreases at longer ranges and is affected by soft or angled surfaces that scatter the ultrasonic beam, temperature extremes, and mounting angle. Taking multiple readings and averaging them significantly improves reliability for precision applications.
Can I run multiple HC-SR04 sensors at the same time?
Yes, but trigger them sequentially rather than simultaneously. Triggering two sensors at the same time causes their ultrasonic pulses to interfere with each other. Trigger one sensor, wait for its Echo response (up to 38ms), then trigger the next. With careful timing in code you can read from four or more sensors reliably within a single loop cycle.