
HC-SR04 Ultrasonic Distance Sensor Module designed for accurate non-contact distance measurement using ultrasonic sound waves. A low-cost, reliable, and easy-to-use sensor widely used in Arduino, ESP32, STM32, Raspberry Pi, robotics, automation, obstacle avoidance, smart parking systems, water level monitoring, and IoT applications.
The module operates by transmitting 40kHz ultrasonic pulses and measuring the echo return time to calculate distance. Features simple 4-pin interface, stable performance, high accuracy, and wide compatibility with most microcontrollers and development boards.
| Parameter | Value |
|---|---|
| Model | HC-SR04 |
| Sensor Type | Ultrasonic Distance Sensor |
| Operating Voltage | 5V DC |
| Operating Current | 15mA |
| Standby Current | <2mA |
| Operating Frequency | 40kHz |
| Measuring Range | 2cm – 400cm |
| Resolution | 0.3cm |
| Accuracy | ±3mm |
| Measuring Angle | <15° |
| Trigger Input | 10µs TTL Pulse |
| Output Signal | TTL Pulse |
| Interface | Trigger + Echo |
| Dimensions | ~45mm × 20mm × 15mm |
| Weight | ~9g |
| Pin | Description |
|---|---|
| VCC | 5V Power Supply |
| TRIG | Trigger Input |
| ECHO | Echo Output |
| GND | Ground |
The HC-SR04 works using ultrasonic sonar technology.
Distance Formula:
Distance = (Time × Speed of Sound) / 2
| Feature | HC-SR04 | IR Sensor |
|---|---|---|
| Technology | Ultrasonic | Infrared |
| Range | 2cm – 400cm | Short range |
| Accuracy | High | Medium |
| Ambient Light Effect | Minimal | High |
| Transparent Object Detection | Better | Poor |
| Outdoor Use | Limited | Better in some cases |
| Price | Low | Low |
| Best For | Robotics & distance | Line tracking |
| HC-SR04 | Arduino UNO |
|---|---|
| VCC | 5V |
| GND | GND |
| TRIG | D9 |
| ECHO | D10 |
| HC-SR04 | ESP32 |
|---|---|
| VCC | 5V |
| GND | GND |
| TRIG | GPIO5 |
| ECHO | GPIO18 (use voltage divider) |
Note: HC-SR04 Echo pin outputs 5V. Use a voltage divider when connecting to 3.3V microcontrollers like ESP32 or Raspberry Pi.
No external library required.
#define TRIG_PIN 9
#define ECHO_PIN 10
long duration;
float distance;
void setup() {
Serial.begin(9600);
pinMode(TRIG_PIN, OUTPUT);
pinMode(ECHO_PIN, INPUT);
}
void loop() {
// Clear trigger
digitalWrite(TRIG_PIN, LOW);
delayMicroseconds(2);
// Send 10us pulse
digitalWrite(TRIG_PIN, HIGH);
delayMicroseconds(10);
digitalWrite(TRIG_PIN, LOW);
// Read echo time
duration = pulseIn(ECHO_PIN, HIGH);
// Calculate distance
distance = duration * 0.0343 / 2;
Serial.print("Distance: ");
Serial.print(distance);
Serial.println(" cm");
delay(500);
}
The HC-SR04 is commonly used in:
The sensor remains one of the most popular low-cost ultrasonic modules for education, embedded systems, and maker projects due to its simplicity and reliability.
៛3,000
Fast Shipping
Phnom Penh & provinces
7 Day Returns
Hassle-free returns