Ultrasonic Sensor HC-SR04 for IoT: Working, Applications, Circuit, and Integration Guide
Discover how the Ultrasonic Sensor HC-SR04 works and how to use it in IoT projects. This detailed guide covers its working principle, pin configuration, interfacing with Arduino, applications in smart systems, and complete circuit setup. Ideal for beginners and IoT developers looking to integrate distance sensing in real-time projects.

Device Overview
Introduction
Ultrasonic sensors have become a key component in modern electronics and Internet of Things (IoT) applications. Among them, the HC-SR04 Ultrasonic Sensor is one of the most popular and affordable distance-measuring devices. It uses high-frequency sound waves to detect the distance between objects and is widely used in robotics, automation, water level monitoring, parking sensors, and more.
This guide provides complete insights into the Ultrasonic Sensor HC-SR04, including its working principle, specifications, interfacing with Arduino, applications, advantages, and integration tips for IoT projects.
What is Ultrasonic Sensor HC-SR04?
The HC-SR04 is an ultrasonic distance measuring sensor that calculates the distance to an object by sending and receiving sound waves. It uses the time-of-flight method to determine how long it takes for the sound to reflect back from a surface.
Working Principle
HC-SR04 works based on ultrasonic echolocation — similar to how bats and dolphins navigate.
-
The Trigger pin sends an ultrasonic pulse (40kHz).
- This pulse travels through the air and hits an object.
-
The reflected signal is captured by the Echo pin.
- The sensor calculates distance using the formula:
Speed of sound = ~343 m/s in air
Technical Specifications
Parameter | Value |
---|---|
Model | HC-SR04 |
Operating Voltage | 5V DC |
Operating Current | 15mA |
Frequency | 40 kHz |
Measuring Range | 2 cm to 400 cm (4 meters) |
Accuracy | ±3 mm |
Measuring Angle | ≤ 15° |
Trigger Input Signal | 10µs TTL pulse |
Echo Output Signal | TTL pulse (width = distance) |
Module Size | 45mm × 20mm × 15mm |
Pin Configuration
Pin | Name | Description |
---|---|---|
1 | VCC | +5V Power Supply |
2 | Trig | Trigger Input (10µs pulse) |
3 | Echo | Echo Output (pulse width) |
4 | GND | Ground |
Interfacing HC-SR04 with Arduino
Required Components:
- 1x Ultrasonic Sensor HC-SR04
- 1x Arduino Uno / Nano / Mega
- Jumper wires
- Breadboard (optional)
Circuit Diagram:
-------- -------
VCC → 5V
GND → GND
Trig → Digital Pin 9
Echo → Digital Pin 10
Sample Arduino Code
Output:
The distance (in cm) of the object from the sensor will be displayed in the Serial Monitor.
Applications of HC-SR04 Ultrasonic Sensor
- Water level measurement
- Smart dustbins
- Parking assistance system
- Obstacle detection in robotics
- Industrial automation
- IoT-based security systems
- Blind assistive devices
- Smart agriculture (e.g., irrigation level detection)
- Home automation
Advantages of Using HC-SR04
- Low cost and easily available
- High accuracy (±3 mm)
- Easy to interface with microcontrollers
- Reliable and consistent output
- Works in dark or non-visual environments
Limitations
- Can be affected by temperature and humidity
- Works best with flat, smooth surfaces
- Limited angle (15° cone)
- Not suitable for transparent or absorbent objects
Types of Ultrasonic Sensors
Although HC-SR04 is the most popular, here are other types used in IoT:Sensor Name | Features |
---|---|
HC-SR04 | Standard, low-cost, most used |
JSN-SR04T | Waterproof, suitable for outdoor projects |
MB1020 (MaxBotix) | High precision, industrial grade |
HY-SRF05 | Enhanced range and accuracy over HC-SR04 |
Integration Tips for IoT Projects
- Always add a small capacitor across VCC and GND to eliminate noise.
- Use software or hardware filters to reduce false signals.
- For long-range accuracy, prefer waterproof sensors like JSN-SR04T.
- Combine with NodeMCU/ESP32 for WiFi-enabled IoT setups.
- Ensure echo pin timing is handled properly to avoid incorrect distance readings.
Conclusion
The Ultrasonic Sensor HC-SR04 is an ideal choice for distance measurement in various DIY and professional IoT applications. With simple interfacing, accurate output, and affordable pricing, it remains a top pick among makers and engineers. Whether you’re building a smart water level detector or an obstacle-avoiding robot, the HC-SR04 is a reliable and efficient sensor to integrate.
Where to Buy
Platform | Price | Action |
---|---|---|
|
₹279 | Buy Now |
Prices may vary. Click on "Buy Now" to check current availability and pricing.
Administrator
Frequently Asked Questions
Common questions about Ultrasonic Sensor HC-SR04 for IoT: Working, Applications, Circuit, and Integration Guide. Find answers to the most frequently asked questions.
User Reviews & Comments
Share your experience with this IoT device. Your feedback helps our community make informed decisions!
Share Your Experience
Help others by sharing your thoughts about this IoT device.
Related Devices
Explore more IoT devices in the same category
No Related Devices
Check out other categories for more IoT devices.
Bavaliya Nayan
1 week agoSuper 😍 bro it's working 💪