Arduino project using an HC-SR04 ultrasonic sensor to control a 3-LED stoplight and a passive buzzer based on object distance.
This project demonstrates:
- Digital I/O control
- Passive buzzer PWM/tone control
- Real-time distance measurement
- Modular code and clean embedded design
- Simple distance-based alert system
- Arduino UNO R3
- HC-SR04 Ultrasonic Sensor
- 1 × Green LED
- 1 × Yellow LED
- 1 × Red LED
- 3 × 220Ω Resistors
- 1 × Passive Buzzer
- Breadboard & Jumper Wires
| Component | Arduino Pin |
|---|---|
| Green LED | 7 |
| Yellow LED | 6 |
| Red LED | 5 |
| Passive Buzzer | 2 |
| HC-SR04 TRIG | 9 |
| HC-SR04 ECHO | 10 |
| GND | GND |
- Green LED → Pin 7 → 220Ω resistor → GND
- Yellow LED → Pin 6 → 220Ω resistor → GND
- Red LED → Pin 5 → 220Ω resistor → GND
- Passive Buzzer → Pin 2 → GND
- HC-SR04: VCC → 5V, GND → GND, TRIG → 9, ECHO → 10
- Distance > 20 cm → Green LED ON, buzzer silent
- Distance 10–20 cm → Yellow LED ON, medium beep
- Distance < 10 cm → Red LED ON, fast beep
The buzzer frequency increases as the object gets closer, creating a real-time proximity alert system.
// (Paste your final TrafficLight.ino code here)