In this guide
The HC-SR04 is probably sitting in your college lab's component drawer right now — a small blue PCB with two silver cylinders that look like tiny eyes. It costs less than a vadapav, yet it gives your project something powerful: the ability to measure distance without touching anything. Parking sensors, water tank level monitors, obstacle-avoiding robots, smart dustbins — the HC-SR04 is inside all of them.
This guide explains how ultrasonic ranging actually works, how to wire the sensor without the classic mistakes, and eight project ideas built around it.
What is the HC-SR04?
The HC-SR04 is an ultrasonic distance sensor module. It has two transducers: one transmits a burst of ultrasound (sound above human hearing, at 40 kHz), and the other listens for the echo bouncing back from an object. By timing how long the round trip takes, it computes distance.
What it is NOT: it is not a camera, not a laser, and not a proximity switch. It measures the distance to the nearest reasonably reflective surface in a roughly 15-degree cone in front of it. Soft fabrics, angled surfaces, and very small objects give weak or missed echoes — that limitation shapes every project idea below.
Key facts:
- Range: 2 cm to 400 cm — below 2 cm the echo returns before the sensor is ready to listen.
- Accuracy around ±3 mm under good conditions — plenty for tank levels and robot navigation.
- 5V powered, with a simple two-pin digital interface: TRIG (input) and ECHO (output).
- 40 kHz ultrasonic burst — inaudible to humans, but keep it away from other ultrasonic sensors to avoid crosstalk.
How the HC-SR04 works
The measurement cycle, step by step:
- Trigger. Your microcontroller pulls the TRIG pin HIGH for at least 10 microseconds, then LOW.
- Burst. The sensor fires eight 40 kHz ultrasonic pulses from the transmitter transducer.
- Listen. The TRIG pulse ends, and the ECHO pin goes HIGH. The receiver transducer now listens.
- Echo. When the reflected sound returns, the ECHO pin goes LOW. The time ECHO stayed HIGH equals the sound's round trip.
- Calculate. Sound travels at about 343 meters per second in air. Distance in centimeters = echo time in microseconds ÷ 58. (The ÷58 folds in the speed of sound and the divide-by-two for the round trip.)
- Repeat. Wait at least 50-60 ms between readings so leftover echoes from the previous burst die out — otherwise you get ghost readings.
Key specifications
| Parameter | Value |
|---|---|
| Operating voltage | 5V DC |
| Operating current | ~15 mA |
| Ultrasonic frequency | 40 kHz |
| Measuring range | 2 cm – 400 cm |
| Accuracy | ±3 mm (typical, hard flat surface) |
| Measuring angle | ~15 degrees |
| Trigger input | 10 µs TTL pulse |
| Echo output | 5V TTL pulse, width = round-trip time |
| Dimensions | 45 × 20 × 15 mm |
Wiring it up: HC-SR04 + Arduino Uno
| HC-SR04 pin | Arduino Uno pin | Notes |
|---|---|---|
| VCC | 5V | Must be 5V — the sensor is unreliable at 3.3V |
| GND | GND | Common ground, always |
| TRIG | D9 (any digital) | Output from Arduino; 3.3V logic is enough to trigger |
| ECHO | D10 via voltage divider | ECHO outputs 5V — see warning below |
The #1 wiring gotcha: the ECHO pin outputs a 5V signal. On a 5V Arduino Uno that is fine. On a 3.3V board (ESP32, Raspberry Pi Pico), feed ECHO through a simple voltage divider (e.g. 1kΩ + 2kΩ resistors) or you will damage the pin over time. The TRIG pin, by contrast, triggers reliably from 3.3V.
Common mistakes that kill HC-SR04 projects
- Reading too fast. Firing the sensor every 10 ms creates echo crosstalk — each new burst collides with the previous burst's fading echo. Keep at least 50-60 ms between measurements.
- Angled or soft targets. Ultrasound reflects best off hard, flat surfaces facing the sensor. A curtain, a slanted wall, or a small pole at an angle can vanish from readings entirely. Design your project around this.
- Two sensors interfering. Two HC-SR04s firing simultaneously hear each other's bursts. Stagger their triggers in code.
- Powering from a weak 5V rail. The sensor draws ~15 mA in bursts; on a sagging supply (long USB cable, overloaded regulator) readings get noisy. Short, solid power wiring matters.
- Ignoring temperature. The speed of sound changes ~0.6 m/s per °C. For a water tank monitor it hardly matters; for a precision instrument over meters, compensate with a temperature reading.
- Mounting it where it vibrates. On a robot chassis, motor vibration couples into the transducers and adds noise. Soft-mount the sensor or average several readings.
Project ideas using the HC-SR04
1. Automatic braking system with ultrasonic sensors
HC-SR04s watch the road ahead; when an obstacle closes inside a threshold distance at speed, the controller cuts the throttle and applies the brakes. A strong mechatronics final-year build — sensing, decision logic, and actuation in one loop. See the automatic braking system.
2. Automatic water tank overflow controller
The sensor stares down into the tank from the lid, measuring the water surface distance. The controller starts the pump when the level is low and stops it before overflow — the single most-built HC-SR04 project in Indian colleges, and still a solid submission with proper dry-run protection. See the water tank overflow controller.
3. IoT parking slot availability display
One sensor per slot (or a scanning array) detects whether a car is parked; an ESP32 pushes slot status to a dashboard and a display at the entrance. Clean IoT + sensor fusion story for a final-year report. See IoT parking slot display.
4. Flood water-level alerts for underpasses
The same tank-level principle, ruggedized: an ultrasonic sensor monitors water rising in an underpass and sends GSM SMS alerts before vehicles get trapped. Real civic problem, real sensor physics. See flood water-level alerts.
5. Forklift proximity alert
An HC-SR04 on a warehouse forklift watches for workers and racks in the blind zone and sounds an escalating alarm as distance closes. Industrial safety angle that stands out in viva. See the forklift proximity alert.
6. Pothole detection with ultrasonic sensing
A downward-facing sensor on a vehicle measures road surface distance; sudden spikes mark potholes, logged with GPS coordinates. Genuinely useful civic data, and the signal-processing (filtering out speed bumps vs potholes) gives the project depth. See pothole detection.
7. Ultrasonic blind-spot detection for two-wheelers
Handlebar-mounted sensors watch the blind zone beside a bike and buzz the handlebar grip when a vehicle enters it. Compact, wearable-adjacent, and very demoable. See the blind-spot detection system.
8. Aquaponics monitoring dashboard
Water level is one of several parameters (pH, temperature, feeding schedule) an ESP32 tracks for an aquaponics tank, with the HC-SR04 handling level. Shows how the sensor slots into a multi-sensor IoT system rather than a single-trick build. See aquaponics monitoring.
Frequently asked questions
How accurate is the HC-SR04 really?
About ±3 mm on a hard, flat surface facing the sensor, in still air at room temperature. In real projects — angled surfaces, temperature swings, vibration — treat ±1 cm as honest working accuracy and design your thresholds with margin.
Can I use the HC-SR04 with an ESP32 or Raspberry Pi?
Yes, with one precaution: the ECHO pin outputs 5V, and ESP32/Pi GPIO pins are 3.3V. Run ECHO through a voltage divider (1kΩ + 2kΩ) before it reaches the pin. The TRIG pin triggers fine from 3.3V logic.
What is the minimum distance it can measure?
About 2 cm. Below that, the echo returns while the sensor is still transmitting, so it cannot hear it. For very close range, look at IR or time-of-flight laser sensors instead.
Why do my readings jump around randomly?
The usual suspects in order: readings taken too fast (keep 60 ms apart), a second ultrasonic source nearby, a sagging 5V supply, or the target surface being angled or soft. Fix the timing first — it solves most cases.
HC-SR04 vs waterproof JSN-SR04T — which for a water tank?
The standard HC-SR04 is not waterproof; humidity and splashes kill it over time. For a permanent tank installation, the JSN-SR04T (sealed probe version) is the right call. For a college demo measured over days, the HC-SR04 mounted under the lid is fine.
Can two HC-SR04 sensors work side by side?
Yes, if you stagger them: trigger sensor A, wait for its echo to finish, then trigger sensor B. Fired simultaneously they hear each other's bursts and both report garbage.
Where to go next
Pick the idea that fits your branch — the tank controller and parking system for a clean IoT submission, the braking system or pothole detector for mechatronics depth. Each linked project page has the full breakdown: components, how it works, specifications, and FAQs. If you want it built to order with documentation and viva support, the quotation form on the page is the fastest route.