HC-SR04 Ultrasonic Sensor
The HC-SR04 Ultrasonic Sensor Module is a popular tool for measuring distance and detecting objects. It’s small, easy to use, and combines everything you need: a transmitter, receiver, and control circuit in one module. It works like a sonar, sending out sound waves to measure the distance to objects, just like how bats and dolphins sense their surroundings. This makes it an ideal ultrasonic sensor module for robotics and IoT applications where accuracy and reliability are essential.
This HC-SR04-Ultrasonic Range Finder can measure distances from 2 cm up to 400 cm with high accuracy, about 3 mm, making it the best distance measuring sensor 2cm to 400cm for both beginners and professionals. It’s reliable for many projects, from robotics to simple object detection, and works well even in different lighting conditions.
This HC SR04 ultrasonic distance sensor module has two main pins, Trigger and Echo, which connect easily to microcontrollers like Arduino, making it perfect as an ultrasonic distance sensor for Arduino projects where non-contact distance sensing is required. Understanding the HC-SR04 ultrasonic sensor working and pinout is simple, making it a go-to choice for students and developers.
Check out the best selection of Distance Sensors.
Note: The HC-SR04 sensor has a 5V output (which needs to be reduced to 3.3V to work with the Raspberry Pi).
Read our blog on how to connect ultrasonic sensor to Raspberry Pi.
Looking for the Best Price for the HC SR 04 Ultrasonic Sensor Online?
At Robocraze, the HC-SR04 ultrasonic sensor price in India starts at ₹69, and may vary based on ongoing offers, stock availability, and bundled deals. We ensure high-quality, performance-tested modules that meet reliable accuracy standards for robotics, automation, and IoT applications.
Unlike low-grade alternatives in the market, our HC-SR04 sensors undergo quality checks to deliver stable distance measurements and consistent trigger/echo response. With competitive HC-SR04 ultrasonic sensor price in India, genuine components, and technical support, Robocraze provides better value compared to many generic sellers online.
Features:
- Non-Contact Distance Sensor
- Measures 2cm to 400cm
- Sonar technology for accuracy
- Suitable for robotics and DIY projects, including ultrasonic sensor module for robotics and IoT
- Stable performance indoors and outdoors
- Durable materials
- Easy to install, user-friendly
- 5V DC power supply
- High resolution: 0.3 cm
- Best ultrasonic sensor for Arduino and Raspberry Pi projects, ideal for ultrasonic distance sensor for Arduino projects
Applications:
- Used to avoid and detect obstacles with robots like biped robots, obstacle avoider robots, path-finding robots, etc.
- Used to measure the distance within a wide range of 2cm to 400cm
- Can be used to map the objects surrounding the sensor by rotating it
- The depth of certain places like wells, pits, etc. can be measured since the waves can penetrate through the water
- Its wide measuring range makes it the best distance measuring sensor 2cm to 400cm for real-world applications.
Read our blog explaining the ultrasonic sensor working.
Working & Pinout Explanation:
Understanding the HC-SR04 ultrasonic sensor working and pinout is essential for integrating it into your projects. The module operates using two main pins:
-
Trigger Pin: Sends ultrasonic pulses
-
Echo Pin: Receives reflected signals
The sensor calculates distance based on the time taken for the sound waves to return. This simple mechanism makes it highly effective for automation, robotics, and obstacle detection systems. Its easy interface is one reason why it is widely used as an ultrasonic distance sensor for Arduino projects.
Important Note for ESP32 & 3.3V Microcontrollers: The HC-SR04 operates at 5V. If you are interfacing it with a 3.3V logic board like the ESP32, you must use a voltage divider (e.g., 1kΩ and 2kΩ resistors) or a logic level shifter on the Echo pin to prevent damaging your microcontroller. The Trigger pin can be driven directly by 3.3V.
Pinout
Wiring Diagram:
HC SR 04 Ultrasonic Sensor Specifications Comparison:
| Parameter |
HC-SR04 Ultrasonic Sensor (Robocraze) |
Typical Low-Grade Alternative |
| Operating Voltage |
5V DC |
5V DC |
| Operating Current |
15mA |
15–20mA |
| Measuring Range |
2cm – 400cm |
3cm – 300cm |
| Measuring Angle |
< 15° |
15–20° |
| Accuracy |
±3mm |
±5mm or higher |
| Frequency |
40 kHz |
40 kHz |
| Build Quality |
Quality-tested PCB with stable soldering |
Inconsistent soldering quality |
| Performance Stability |
Reliable echo response and stable readings |
Possible signal noise and unstable readings |
HC-SR04 vs Waterproof JSN-SR04T vs IR Sensor: Which to Choose?
Choosing the right distance or obstacle detection sensor depends entirely on your project’s environment and range requirements. Here is a quick breakdown to help you decide:
| Feature |
HC-SR04 Ultrasonic Sensor |
JSN-SR04T Waterproof Sensor |
IR (Infrared) Sensor |
| Best Environment |
Indoor, dry, controlled settings |
Outdoor, wet, dusty, or humid conditions |
Indoor, controlled lighting |
| Typical Range |
2 cm – 400 cm |
25 cm – 450 cm |
2 cm – 30 cm (varies by model) |
| Sunlight Interference |
None (uses 40kHz sound waves) |
None (uses sound waves) |
High (struggles in direct sunlight) |
| Ideal Use Cases |
Arduino distance code, indoor obstacle avoiding robot, general measurement |
Water level detection, outdoor robotics, agricultural automation |
Line-following robots, edge detection, short-range proximity |
1. HC-SR04 Ultrasonic Sensor (The All-Rounder)
This is the most popular choice for students, hobbyists, and general robotics. It offers an excellent balance of price, accuracy (±3mm), and a wide 2–400cm range. Choose this if your project is indoors or in a dry environment and you need a reliable, non-contact ultrasonic distance sensor.
2. Waterproof JSN-SR04T (The Outdoor Specialist)
If your project involves water, rain, or heavy dust, the standard HC-SR04 will eventually fail. The JSN-SR04T Waterproof Ultrasonic Sensor features a sealed, potting-compound transducer that can be exposed to the elements. Choose this if you are building outdoor robots or water tank level indicators.
3. IR Sensors (The Short-Range Specialist)
Infrared sensors (like the TCRT5000 or E18-D80NK) are excellent for very short-range detection. However, they are easily blinded by direct sunlight and struggle to detect black or highly transparent surfaces. Choose this if you need ultra-fast, short-range detection for line-maze robots.
Common Problems: Why is My HC-SR04 Reading 0 or Max Distance?
The HC-SR04 is a highly reliable module, but like any electronic component, it can occasionally give erratic readings. If your Arduino distance code is returning 0 cm or constantly maxing out, don't panic. Here is how to troubleshoot the most common issues.
Problem 1: The Sensor Constantly Reads "0 cm"
A reading of exactly zero usually means the sensor sent the trigger pulse but never received a valid echo back, or the object is inside the sensor's "blind zone".
-
Object is too close: The HC-SR04 has a minimum blind distance of about 2 cm. Move the object further away.
-
Sound-absorbing materials: Soft fabrics, foam, or angled surfaces absorb or deflect the 40kHz sound waves. Ensure the target is a hard, flat surface positioned perpendicular to the sensor.
-
Echo pin wiring issue: Double-check that the Echo pin is securely connected to the correct digital pin on your microcontroller.
Problem 2: The Sensor Reads "Max Distance" or Times Out
If your serial monitor outputs a massive number (or 0, depending on how your pulseIn() timeout is coded), it means the sensor is waiting for an echo that never arrives, or there is a hardware fault.
-
Out of range: Ensure the object is strictly within the 2 cm to 400 cm measuring range.
-
Loose connections: Vibration in robotics projects (like an obstacle avoiding robot) can easily loosen jumper wires. Reseat your Trig, Echo, VCC, and GND pins.
-
Power starvation: The HC-SR04 requires a stable 5V. If it's sharing a power rail with heavy motors, voltage drops can cause the sensor to freeze or fail.
💡 Hardware Pro Tip: If you are still getting random max-distance errors, add a 10µF to 100µF electrolytic capacitor directly across the VCC and GND pins on the back of the sensor. This stabilizes the power supply during the high-current ultrasonic burst and eliminates 90% of erratic readings!