A ₹806 parking aid that beeps faster as something gets closer. An HC-SR04 ultrasonic sensor measures the distance to a wall or bumper, three LEDs show green, yellow or red, and a buzzer beeps with a gap that shrinks with the distance. The page works out the timing so you can see what the numbers mean before you build it.
Scope: beginner. This is a design worksheet with illustrative costs. It has not been bench-tested by this site. The distance-to-beep table below was computed by script. It is a hobby aid, not a safety device: do not rely on it to prevent a collision.
How it works
The sensor sends a burst of 40 kHz sound and times the echo. At about 343 m/s (20 °C) sound travels 1 cm out and back in about 58.3 microseconds, so the distance in centimetres is the echo time divided by 58.3. A car 100 cm away returns an echo after about 5,830 microseconds. Many listings give the usable range as roughly 2 to 400 cm; the sketch only cares about the first metre.
Beeping is done without delay() so the sensor keeps being read. Each time the gap since the last beep reaches the interval for the current distance, the buzzer is switched on for 60 ms. Below 20 cm the buzzer stays on. Above 100 cm it is silent.
Bill of materials
| Part | Qty | Unit | Total |
|---|---|---|---|
| Arduino Uno R3 (or compatible) | 1 | ₹550 | ₹550 |
| HC-SR04 ultrasonic sensor | 1 | ₹110 | ₹110 |
| Active buzzer module | 1 | ₹15 | ₹15 |
| LEDs (green, yellow, red) | 3 | ₹5 | ₹15 |
| 220 ohm resistors | 3 | ₹2 | ₹6 |
| Breadboard | 1 | ₹60 | ₹60 |
| Jumper wires | 1 | ₹50 | ₹50 |
| Parts total | ₹806 | ||
Scroll the table sideways to see every column.
Prices checked Nov 2026. Shipping and tools are not included.
Prices are illustrative figures for Indian sellers in November 2026, before shipping, and have not been checked against current listings.
The numbers
| Distance | Echo time | Beep gap | LED |
|---|---|---|---|
| 100 cm | 5,830 µs | 800 ms | Green |
| 60 cm | 3,500 µs | 480 ms | Green |
| 50 cm | 2,915 µs | 400 ms | Yellow |
| 30 cm | 1,750 µs | 240 ms | Yellow |
| 25 cm | 1,458 µs | 200 ms | Red |
| 20 cm | 1,166 µs | Continuous | Red |
Temperature changes the speed of sound by about 0.6 m/s per degree, so on a hot day the reading is a few percent off. That is fine for a parking aid; see the temperature-compensated ultrasonic distance page if you want it corrected.
Power and wiring
| Part | Connects to | Note |
|---|---|---|
| HC-SR04 VCC and GND | 5V and GND | Sensor is a 5 V part |
| HC-SR04 TRIG | D9 | |
| HC-SR04 ECHO | D10 | Echo is 5 V; fine for an Uno |
| Buzzer signal | D8 | Active buzzer, high = on |
| LEDs through 220 ohm | D2, D3, D4 | Green, yellow, red |
The sketch
// Ultrasonic parking sensor: Uno + HC-SR04 + buzzer + 3 LEDs
// Design worksheet: distances and gaps are starting values.
const int TRIG = 9, ECHO = 10, BUZ = 8;
const int LED_G = 2, LED_Y = 3, LED_R = 4;
unsigned long lastBeep = 0, beepUntil = 0;
float readCm() {
digitalWrite(TRIG, LOW); delayMicroseconds(2);
digitalWrite(TRIG, HIGH); delayMicroseconds(10);
digitalWrite(TRIG, LOW);
unsigned long t = pulseIn(ECHO, HIGH, 25000UL); // 25 ms timeout, about 4 m
if (t == 0) return 999; // no echo
return t / 58.3;
}
void setup() {
pinMode(TRIG, OUTPUT); pinMode(ECHO, INPUT); pinMode(BUZ, OUTPUT);
pinMode(LED_G, OUTPUT); pinMode(LED_Y, OUTPUT); pinMode(LED_R, OUTPUT);
}
void loop() {
float d = readCm();
digitalWrite(LED_G, d > 60);
digitalWrite(LED_Y, d <= 60 && d >= 30);
digitalWrite(LED_R, d < 30);
unsigned long now = millis();
if (d > 100) {
digitalWrite(BUZ, LOW);
} else if (d < 20) {
digitalWrite(BUZ, HIGH); // continuous
} else {
unsigned long gap = (unsigned long)(d * 8);
if (now - lastBeep >= gap) { lastBeep = now; beepUntil = now + 60; }
digitalWrite(BUZ, now < beepUntil);
}
delay(40); // let echoes die away
}The 40 ms pause between readings stops one echo being mistaken for the next. A reading of 999 means no echo came back; a soft surface such as a cloth can absorb the sound and look like open space. The sketch has been proofread but not compiled on this site.
Test plan
- Bench check: hold a book at 100, 60, 30 and 20 cm from a ruler and note which LED lights and how the beeping changes.
- Accuracy: compare the reading (print it with Serial) against the ruler at five distances and record the error.
- Surface test: try a wall, a metal panel, a cardboard box and a cloth. Soft or sloped surfaces return weaker echoes.
- Angle test: approach a wall at an angle and see where the reading stops being reliable.
- In place: mount it in the garage and roll a toy or slow-moving object toward the wall.
What usually goes wrong
| Symptom | Likely cause | Fix |
|---|---|---|
| Always reads 999 | Echo or trigger wires swapped, or sensor not powered | Check TRIG on D9, ECHO on D10 and the 5 V supply |
| Reading jumps around | Soft or angled surface, or electrical noise | Average three readings and aim at a flat surface |
| Beeps never stop | Distance reads under 20 cm | Check for the sensor seeing its own mounting |
| Buzzer is faint | Passive buzzer used | Use an active buzzer, or drive a passive one with tone() |
| LED zone flickers at the edge | No margin between zones | Add a 3 cm margin before switching zone |
Upgrades
- Display: show the distance on a small OLED or a 7-segment display.
- Two sensors: add a second sensor for the side of the car.
- Temperature correction: add a DS18B20 and correct the speed of sound.
- Stop line: flash all LEDs at the exact stop distance you choose.
Cost and parts notes
The ₹806 total is an illustration and does not include shipping. Use the cost calculator to compare sellers.
Common questions
How far can an HC-SR04 measure?
Listings commonly give 2 to 400 cm, and the sketch here only uses the first metre. Range depends on the surface and angle.
Why 58.3 microseconds per centimetre?
Sound covers about 0.0343 cm per microsecond at 20 °C, and the echo travels there and back, so each centimetre of distance adds about 58.3 µs.
Can I rely on it as a safety device?
No. It is a hobby aid and can miss soft, thin or sloped objects.
Can I run it off a power bank?
Yes, through the Uno USB socket. The sensor draws little current.
Last reviewed: November 2026. This is a design worksheet with illustrative costs. It has not been bench-tested by this site; library names, pins and limits must be checked against your board and the current library versions, and measurements from your build are welcome.