The Smart Parking Sensor project teaches you how to build a practical real-world application using the HC-SR04 ultrasonic sensor: automatic parking distance detection.
In this project, the Arduino uses the HC-SR04 sensor to measure the distance between a vehicle and an obstacle. LED indicators and a buzzer provide visual and audio feedback to warn the driver when they are getting too close to obstacles.
When an object is far away, the green LED glows. As the vehicle gets closer, the yellow LED turns on. When the distance becomes dangerous, the red LED flashes and the buzzer sounds an alarm, creating a complete parking assistance system.
This project teaches Sensor-Based Distance Detection, Multi-Level Alert Systems, Conditional Logic for Automation, Integration of Multiple Outputs, and Real-World Safety Applications.
By finishing this project, you’ll understand how smart parking systems in modern vehicles work and how to combine sensors with multiple outputs for safety alerts.
To build this circuit, collect these specific items from your kit:
Arduino Uno × 1, Breadboard × 1, HC-SR04 Ultrasonic Sensor × 1, Green LED × 1, Yellow LED × 1, Red LED × 1, 220Ω Resistor × 3, Passive Buzzer × 1, Jumper Wires × 8, USB Cable × 1
Connect the Arduino GND pin to the negative rail of the breadboard. This creates a shared ground connection for all components.
Place the HC-SR04 ultrasonic sensor near the edge of your breadboard. Connect the VCC pin to Arduino 5V. Connect the GND pin to the breadboard negative rail. Connect the TRIG pin to Arduino Pin 9. Connect the ECHO pin to Arduino Pin 10.
Put the green LED into the breadboard. Connect the long leg (Anode) to Arduino Pin 3 through a 220Ω resistor. Connect the short leg (Cathode) to the breadboard GND rail.
Put the yellow LED into the breadboard. Connect the long leg (Anode) to Arduino Pin 4 through a 220Ω resistor. Connect the short leg (Cathode) to the breadboard GND rail.
Put the red LED into the breadboard. Connect the long leg (Anode) to Arduino Pin 5 through a 220Ω resistor. Connect the short leg (Cathode) to the breadboard GND rail.
Place the passive buzzer onto the breadboard. Connect the positive (+) terminal to Arduino Pin 8. Connect the negative (-) terminal to the breadboard GND rail.
Check all LED directions and verify the ultrasonic sensor connections before uploading your code.
Important: The smart parking sensor combines distance measurement with multiple alert levels, so all wiring must be correct for proper functionality.
In setup(), Arduino sets Pin 9 as OUTPUT for the ultrasonic sensor trigger. Pin 10 is set as INPUT to receive the echo signal. Pins 3, 4, and 5 are configured as OUTPUT for the three LEDs. Pin 8 is set as OUTPUT for the buzzer control.
The Arduino continuously measures distance using the HC-SR04 sensor. The pulseIn() function measures how long the echo takes to return. This duration is converted to distance in centimeters using the distance formula.
The program compares the measured distance against three threshold values. If distance is greater than 50 centimeters, the system is in safe range. If distance is between 30 and 50 centimeters, the warning level activates. If distance is less than 30 centimeters, the danger level triggers.
The entire process repeats inside the loop() function every 200 milliseconds. This allows the system to respond quickly to changing distances and provide real-time feedback to the driver.
After uploading your code, here is what happens.
Place the sensor facing a wall or obstacle. At distances greater than 50 centimeters, the green LED glows steady. Move closer until the distance reaches 40 centimeters and the yellow LED turns on. Continue moving closer until the distance drops below 30 centimeters and the red LED flashes while the buzzer sounds an alarm. Move the obstacle away and watch the LEDs and buzzer respond in real-time to the changing distance.
LEDs Do Not Change Color :- Verify that all three LEDs connect to the correct pins and check their polarity. Make sure the distance thresholds in your code match your desired warning ranges.
Buzzer Does Not Make Sound :- Check the buzzer polarity and verify Pin 8 connection. Confirm that the buzzer is activated in your code when distance drops below the danger threshold.
Distance Readings Are Unstable :- Move the sensor away from reflective surfaces and obstacles. Add a short delay between measurements or use an averaging function to smooth out readings.
One LED Always Stays On :- Check your conditional logic in the code. Verify that the if-else statements properly evaluate distance ranges and control the correct LED pins.
Sensor Not Responding :- Verify the HC-SR04 has proper VCC power at 5V. Check that both TRIG and ECHO pins are correctly wired and connected to the right Arduino pins.
By finishing this project, you now know :-
How to integrate multiple sensors and outputs into one system, how to create alert levels based on sensor data, how parking assistance systems work in real vehicles, how to use conditional logic to control multiple devices, and how to provide both visual and audio feedback for safety warnings.
In Day 11, you’ll learn how to measure temperature and humidity using a DHT11 sensor and display the data on the Serial Monitor to create an environmental monitoring system.