Description
The HC-SR04 Ultrasonic Distance Sensor is a popular and affordable sensor module used in robotics and automation systems to detect objects and measure distance using ultrasonic waves.
It works by emitting a high-frequency sound pulse and measuring the time it takes to reflect back. With a wide detection range and easy-to-use 4-pin interface, it integrates perfectly with Arduino, Raspberry Pi, and other microcontroller platforms.
🔍 What This Sensor Is & What It Does
The HC-SR04 Ultrasonic Sensor measures distance using sound waves.
It sends out an ultrasonic pulse and measures how long it takes to bounce back.
Perfect for:
✅Obstacle detection
✅Robotics & car avoidance
✅Smart dustbin
✅Water tank level
✅Security motion detection
✅Autonomous robots
✅Parking assist
✅Industrial distance sensing
Whether you’re building a line-following robot, obstacle-avoiding car, or smart parking system — this is the go-to sensor. Get it now from Dream RC, Bangladesh’s trusted robotics supplier.
⚙️ Product Features & Specifications
| 🔧 Feature | 📌 Details |
|---|---|
| 🌊 Measurement Method | Ultrasonic (Sonar Echo) |
| 📏 Measuring Range | 2 cm – 400 cm |
| 🎯 Accuracy | ±3 mm |
| 📐 Measuring Angle | < 15° |
| 🔌 Operating Voltage | 5V DC |
| ⚡ Operating Current | 15 mA typical |
| 💬 Output Signal | Digital (Trigger & Echo) |
| 📡 Trigger Pulse Input | 10µs TTL pulse |
| ⏱️ Response Time | < 30 ms |
| 🔗 Interface Pins | VCC, Trig, Echo, GND |
| 📐 Dimensions | 45 mm x 20 mm x 15 mm |
| ⚖️ Weight | Approx. 10g |
| 💻 Compatibility | Arduino, ESP32, Raspberry Pi, STM32, etc. |
⚡ Power Requirements
| Requirement | Details |
|---|---|
| Operating Voltage | 5V DC |
| Current Consumption | 15mA (typical) |
| Trigger Pin Logic | 5V |
| Echo Pin Output | Any Digital Pin |
| Max Range | 400 cm |
| Min Range | 2 cm |
📦 Package Includes
1 x HC-SR04 Ultrasonic Distance Sensor Module
🔌 Wiring Diagram (Arduino UNO)
HC-SR04 → Arduino UNO

| HC-SR04 Pin | Connect To |
|---|---|
| VCC | 5V |
| TRIG | D13 |
| ECHO | D12 |
| GND | GND |
💻 Arduino Sample Code (Beginner-Friendly)
Ultrasonic Sensor / Sonar Sensor Sample / Demo Code For Arduino, ESP 32 & ESP 8266
// Dream RC (dream-rc.com) - Ultrasonic Sensor Code
#define TRIG 13 // TRIG pin (ESP8266: D5, ESP32: 4)
#define ECHO 12 // ECHO pin (ESP8266: D6, ESP32: 5)
void setup() {
Serial.begin(9600); // #(ESP recommended: 115200)
pinMode(TRIG, OUTPUT);
pinMode(ECHO, INPUT);
}
void loop() {
digitalWrite(TRIG, LOW);
delayMicroseconds(2);
digitalWrite(TRIG, HIGH);
delayMicroseconds(10);
digitalWrite(TRIG, LOW);
long duration = pulseIn(ECHO, HIGH);
float distance = duration * 0.034 / 2; // Convert Time to CM
Serial.print("Distance: ");
Serial.print(distance);
Serial.println(" cm");
delay(500); // Add Delay To The Parogram
}
📌Library Dependencies
No external libraries required.
The HC-SR04 uses only built-in Arduino functions:
✅digitalWrite()✅digitalRead()✅pulseIn()✅delayMicroseconds()
📤 Sample Serial Output
Values fluctuate ±1 cm — normal
“0 cm” = no object or weak echo
Large numbers = too far or wrong wiring
🎯 Accuracy Table
| Distance | Expected Accuracy |
|---|---|
| 2–50 cm | ± 0.3 cm |
| 50–200 cm | ± 1 cm |
| 200–400 cm | ± 3 cm |
| Soft objects (cloth/foam) | Poor / No reading |
| Sunlight / Outdoor | Accuracy reduces |
🔧 Troubleshooting Guide
✔ Always getting 0❓
❌Object too soft (cloth, sponge)
❌Wrong wiring TRIG/ECHO
❌Using 3.3V instead of 5V
❌Bad USB power
✔ Random unstable readings
✅Use short wires (<20cm)
✅Add capacitor (10–100 µF) across VCC–GND
❌Avoid vibration from motors
✔ ESP32/ESP8266 not working
✅Echo must be reduced to 3.3V
✅Use 10k + 5k voltage divider
✔ Always shows same value
✅TRIG not receiving 10µs pulse
✅Code running too fast (add delay)
🧩 Compatibility Table
| Board | Compatible? | Notes |
|---|---|---|
| Arduino UNO | ✅ | Works perfectly |
| Arduino Mega | ✅ | Same pins |
| Arduino Nano | ✅ | 5V logic |
| ESP8266 | ✅ | Works perfectly |
| ESP32 | ✅ | Works perfectly |
| Raspberry Pi | ⚠️ | Requires level shifting |
| STM32 | ✅ | Works directly |
💡 Popular Project Ideas
✅Smart Dustbin
✅Water Tank Level Monitor
✅Obstacle Avoiding Robot
✅Parking Distance System
✅Motion Trigger Alarm
✅Automatic Door Opener
✅Smart Blind Stick
✅RC Collision Prevention System
❓ FAQ (Frequently Asked Questions)
1. What is the range of HC-SR04?
✅2 cm to 400 cm.
2. Can HC-SR04 work outdoors?
✅Yes, but sunlight and wind reduce accuracy.
3. Why does HC-SR04 show unstable values?
⚠️Long wires, vibration, low power, or soft materials.
4. Can I use it with ESP32 or ESP8266?
✅Yes — but Echo pin needs 5V → 3.3V voltage divider.
5. Can ultrasonic sensors detect water?
✅Yes, if the water surface is still (not splashing).
🚚 Dream RC is giving you the best deal in Bangladesh – high quality at the lowest price!
💬 What is the Ultrasonic Sonar Sensor price in BD (Bangladesh) & why buy from us?
The Ultrasonic Sonar Sensor current price in Bangladesh is 89 BDT.
From us – Dream RC, you can get Ultrasonic Sonar Sensor at the most affordable price with the lowest delivery charges & fast shipment all over Bangladesh.






