The HC-SR04 is one of the most popular ultrasonic ranging modules used in maker, robotics, and embedded systems projects. By emitting a burst of 40kHz ultrasonic sound and measuring the time it takes for the echo to return, it accurately calculates the distance to an object — from as close as 2cm up to 450cm, with a precision of ±0.3cm. Powered directly from 5V, it connects to any Arduino or compatible microcontroller with just two digital I/O pins, making it an ideal first sensor for beginners and a reliable workhorse for engineers.
Key Features
- Operating Voltage 5V DC: Works directly with Arduino 5V power rail — no extra regulation needed.
- Detection Range 2cm–450cm: Covers most practical robotics and automation use cases, from close-range obstacle avoidance to medium-range distance mapping.
- High Precision ±0.3cm: Accurate enough for object detection, level sensing, and positioning applications.
- Low Quiescent Current (<2mA): Draws minimal power in standby; approximately 15mA during active measurement — battery-friendly for portable projects.
- Simple GPIO Interface: Only a 10µs TTL trigger pulse is needed to initiate a measurement. The module automatically fires an 8-cycle 40kHz ultrasonic burst and returns an Echo pulse whose width is directly proportional to distance.
- Narrow Sensing Cone (≤15°): The tight beam angle reduces false readings from objects outside the intended detection path, improving measurement reliability.
- Working Temperature -15°C to 70°C: Suitable for both indoor and outdoor environments.
Pinout & Wiring
| Pin # | Symbol | Description |
|---|
| 1 | VCC | Power supply — connect to +5V |
| 2 | TRIG | Trigger input — send a 10µs HIGH pulse to start ranging |
| 3 | ECHO | Echo output — pulse width proportional to time-of-flight |
| 4 | GND | Ground — connect to 0V |
Wiring note (Arduino UNO example): VCC → 5V, GND → GND, TRIG → D9, ECHO → D10. Distance (cm) = (Echo pulse duration in µs × 0.034) / 2. Always connect GND first before powering the module to avoid spurious HIGH output.
⚠️ The ECHO pin outputs a 5V signal. For 3.3V microcontrollers (ESP32, ESP8266, Raspberry Pi), use a voltage divider on the ECHO line to avoid damaging the GPIO.
Compatibility
- Arduino UNO / Nano / Mega: Plug-and-play at 5V — no level shifting required on either pin.
- ESP32 / ESP8266: Power via 5V pin; TRIG can be driven directly from 3.3V GPIO (module accepts TTL). ECHO output requires a voltage divider (e.g., 1kΩ / 2kΩ) before connecting to the 3.3V GPIO input.
- Raspberry Pi: Same 3.3V logic caution applies — a voltage divider on the ECHO line is mandatory.
Typical Applications
- Obstacle avoidance in autonomous robots and smart cars
- Non-contact level measurement in tanks or bins
- Parking assist and proximity alert systems
- People/object counting at doorways
- Drone altitude hold (low-altitude sensing)
- Interactive installations — trigger events when a person approaches
Technical Specifications
| Parameter | Value |
|---|
| Interface / Protocol | GPIO — TTL Trigger & Echo pulse-width measurement |
| Operating Voltage | 5V DC |
| Quiescent Current | <2mA |
| Active Measurement Current | ~15mA (max 20mA) |
| Trigger Input Signal | 10µs TTL HIGH pulse |
| Ultrasonic Frequency | 40kHz (8-cycle burst) |
| Echo Output | TTL pulse — width proportional to distance |
| Detection Range | 2cm – 450cm |
| Precision | ±0.3cm |
| Sensing Angle | ≤15° |
| Working Temperature | -15°C to 70°C |
| MPN | HC-SR04 |
Frequently Asked Questions
Q: Can I use the HC-SR04 with an ESP32 or Raspberry Pi?
A: Yes, but with a precaution. The TRIG pin accepts 3.3V TTL signals, so you can drive it directly from an ESP32 GPIO. However, the ECHO pin outputs 5V — you must add a voltage divider (e.g., 1kΩ in series + 2kΩ to GND) before connecting it to any 3.3V logic input, otherwise you risk damaging your microcontroller.
Q: How do I calculate the distance from the Echo pulse?
A: Measure the duration (in microseconds) that the ECHO pin stays HIGH. Apply the formula: Distance (cm) = pulse duration (µs) × 0.034 / 2. The division by 2 accounts for the sound wave travelling to the object and back. Arduino libraries such as NewPing handle this automatically.
Package contents: 1 × HC-SR04 Ultrasonic Distance Sensor Module
⚠️ Important: Insert the module into the circuit before applying power. Always connect GND first. Do not power the module from an electric power supply without ensuring the GND terminal is connected first, as improper power-up sequence may cause a false HIGH output on the ECHO pin.