HC-SR04 Ultrasonic Distance Sensor
Non-Contact Obstacle Detection and Ranging Module
The HC-SR04 is an affordable ultrasonic distance sensor that measures object distance by emitting 40kHz sound waves and timing the echo return. It is perfect for obstacle avoidance robots, proximity detection, and level monitoring in DIY projects. [citation:4][citation:10]
Reliable Ranging - Measures from 2cm to 400cm with 3mm accuracy
Simple 5V Interface - Compatible with Arduino and microcontrollers [citation:1][citation:6]
Operating voltage is 5V DC and current is 15mA [citation:1][citation:12]
For precise measurements, use a stable power supply and a 60ms measurement cycle
Soft surfaces may absorb ultrasonic waves, and angled objects can reflect the signal away [citation:4]
Technical Specifications
| Parameter | Value |
|---|
| Range | 2cm to 400cm [citation:1][citation:10] |
| Accuracy | ±3mm [citation:1][citation:12] |
| Frequency | 40kHz [citation:1][citation:6] |
| Beam Angle | 15° [citation:1][citation:2] |
| Trigger Pulse | 10µs TTL [citation:1][citation:6] |
| Dimensions | 45 x 20 x 15mm [citation:1][citation:12] |
= Pin Configuration =
| Pin | Function |
|---|
| VCC | 5V power |
| GND | Ground |
| Trig | Trigger input (10µs pulse) |
| Echo | Echo output (pulse width = distance) [citation:1][citation:6] |
= Key Features =
NonContact Measurement Detects objects without physical contact [citation:1]
Fast Response - Outputs echo pulse proportional to distance
Low Power Consumption - 15mA operation [citation:1][citation:2]
Precise Timing - Pulse width ranges from 150µs to 25ms [citation:1]
= Applications =
- Obstacle avoiding robots [citation:5]
- Distance measuring devices
- Parking sensors
- Level and proximity detection
- Interactive installations
Affordable Solution Excellent priceto-performance ratio
Easy to Use - Simple trigger and echo interface [citation:3]
√ Compatible with Arduino, ESP32, and Raspberry Pi [citation:3]
√ Works with standard distance calculation libraries
√ Includes 4-pin header for easy connection
Distance Calculation
Distance = (Echo pulse width × 0.034 cm/µs) / 2 [citation:1][citation:7]
Trigger the sensor with a 10µs HIGH pulse on Trig pin [citation:1][citation:5]
Measure Echo pulse width to calculate distance using formula above
Maximum echo timeout is 38ms, indicating no object within range [citation:1]
Troubleshooting
No reading:
- Verify stable 5V power
- Check trigger and echo pin connections
- Avoid using in environments with high ultrasonic noise
Inaccurate readings:
- Ensure target is within 2-400cm range [citation:1]
- Keep beam perpendicular to target surface
- Use 60ms or longer measurement cycles [citation:12]