You'll create a mini traffic light system using an Arduino microcontroller and a sound sensor. When it detects an ambulance siren, it automatically turns all traffic lights RED and gives the ambulance a clear GREEN path — just like real cities do!
1 How Does It Work?
🔊
Hear the Siren
A sound sensor detects the ambulance's loud siren sound frequency
🧠
Arduino Thinks
The Arduino microcontroller reads the sensor and runs our smart code
🔴🔴
All Stop!
All regular traffic lights switch to RED to stop cars safely
🟢
Ambulance Goes!
The ambulance lane gets a GREEN light and a clear road to speed through
🌍
Fun Fact!
Real cities like Amsterdam and Singapore use systems just like this! Emergency vehicles save 2-3 minutes per journey — and in heart attacks, every minute matters. Your project could help save lives someday!
2 See It In Action! (Simulator)
🎮 Interactive Traffic Simulator
Normal Traffic
🚑
Ambulance Lane
🟢 Normal traffic mode — all lights working normally
3 Parts You Need 🛒
🎛️
Arduino Uno
Quantity: 1 — The brain!
🔴
Red LEDs
Quantity: 3 — Stop lights
🟡
Yellow LEDs
Quantity: 3 — Caution lights
🟢
Green LEDs
Quantity: 3 — Go lights
🔊
Sound Sensor (KY-037)
Quantity: 1 — Hears the siren
⚡
220Ω Resistors
Quantity: 9 — Protect LEDs
🧩
Breadboard
Quantity: 1 — No soldering!
🔌
Jumper Wires
Quantity: 20+ — Connect everything
💻
USB Cable + Computer
With Arduino IDE installed
⚠️ Safety First!
Always ask a parent or teacher to help you with electronics. Never connect anything to mains electricity — we only use safe USB power from your computer! 😊
4 Circuit Wiring Guide 🔌
🚦 TRAFFIC LIGHT 1 (Lane A — Normal Traffic)
Red LED (+)
→ Pin 2
with 220Ω resistor
Yellow LED (+)
→ Pin 3
with 220Ω resistor
Green LED (+)
→ Pin 4
with 220Ω resistor
All LED (–)
→ GND
Ground rail
🚑 TRAFFIC LIGHT 2 (Ambulance Lane)
Red LED (+)
→ Pin 5
with 220Ω resistor
Yellow LED (+)
→ Pin 6
with 220Ω resistor
Green LED (+)
→ Pin 7
with 220Ω resistor
All LED (–)
→ GND
Ground rail
🔊 SOUND SENSOR (KY-037)
VCC pin
→ 5V
Power
GND pin
→ GND
Ground
DO pin
→ Pin 8
Digital signal
AO pin
→ A0
Analog (optional)
🔧
Wiring Tip for Kids!
Think of resistors like speed bumps for electricity! They slow down the current so your LEDs don't burn out. The long leg of an LED goes to the + pin, and the short leg goes to – (ground). Red wire = power, Black wire = ground!
5 Upload Steps 📲
1
Download Arduino IDE
Go to arduino.cc and download the free Arduino software for your computer (Windows, Mac, or Linux all work!).
2
Plug in your Arduino
Connect your Arduino Uno to your computer using the USB cable. The power light should turn ON — that means it's working!
3
Select the right board
In Arduino IDE, click Tools → Board → Arduino Uno. Then click Tools → Port and select the COM port that appeared.
4
Copy & paste the code
Copy the code from Section 6 below and paste it into the big white area in Arduino IDE.
5
Verify (Check for errors)
Click the ✔️ checkmark button. If it says "Done compiling" — great! Ask an adult to help if there's an error.
6
Upload to Arduino!
Click the → arrow (Upload) button. The lights on your Arduino will blink fast — the code is loading!
7
Test it!
Clap loudly near the sound sensor or make a siren sound — watch the traffic lights respond! Adjust the blue dial on the sensor to change sensitivity.
6 The Arduino Code 💻
Every line has a comment (the grey text with //) explaining what it does!
// ============================================
// 🚨 EMERGENCY VEHICLE PRIORITY SYSTEM
// For Kids! Learn Arduino + save lives 🚑
// ============================================// --- PIN SETUP for Traffic Light A (Normal) ---constintredA = 2; // Red LED for normal trafficconstintyellowA = 3; // Yellow LED for normal trafficconstintgreenA = 4; // Green LED for normal traffic// --- PIN SETUP for Traffic Light B (Ambulance) ---constintredB = 5; // Red LED for ambulance laneconstintyellowB = 6; // Yellow LED for ambulance laneconstintgreenB = 7; // Green LED for ambulance lane// --- SOUND SENSOR ---constintsoundPin = 8; // KY-037 digital output pin// --- TIMING ---intnormalDelay = 3000; // Normal phase: 3 secondsintemergencyHold = 8000; // Keep ambulance green for 8 seconds// ============================================
// SETUP — Runs ONCE when Arduino turns onvoidsetup() {
pinMode(redA, OUTPUT);
pinMode(yellowA, OUTPUT);
pinMode(greenA, OUTPUT);
pinMode(redB, OUTPUT);
pinMode(yellowB, OUTPUT);
pinMode(greenB, OUTPUT);
pinMode(soundPin, INPUT);
Serial.begin(9600);
Serial.println("System Ready! Listening for sirens...");
}
// ============================================
// LOOP — Runs FOREVER (normal traffic cycle)voidloop() {
if (digitalRead(soundPin) == HIGH) {
Serial.println("🚨 EMERGENCY DETECTED! Clearing the road!");
emergencyProtocol();
return;
}
// PHASE 1: Lane A gets GREENsetLight(redA, yellowA, greenA, LOW, LOW, HIGH);
setLight(redB, yellowB, greenB, HIGH, LOW, LOW);
waitAndCheck(normalDelay);
// PHASE 2: Yellow warning for Lane AsetLight(redA, yellowA, greenA, LOW, HIGH, LOW);
waitAndCheck(1500);
// PHASE 3: Lane B gets GREENsetLight(redA, yellowA, greenA, HIGH, LOW, LOW);
setLight(redB, yellowB, greenB, LOW, LOW, HIGH);
waitAndCheck(normalDelay);
// PHASE 4: Yellow warning for Lane BsetLight(redB, yellowB, greenB, LOW, HIGH, LOW);
waitAndCheck(1500);
}
// ============================================
// EMERGENCY FUNCTION — activates on siren!voidemergencyProtocol() {
// Flash yellow on ALL lights as warningfor (int i = 0; i < 3; i++) {
setLight(redA, yellowA, greenA, LOW, HIGH, LOW);
setLight(redB, yellowB, greenB, LOW, HIGH, LOW);
delay(400);
allOff();
delay(200);
}
// All normal traffic RED, ambulance GREEN!setLight(redA, yellowA, greenA, HIGH, LOW, LOW);
setLight(redB, yellowB, greenB, LOW, LOW, HIGH);
Serial.println("🟢 AMBULANCE LANE IS CLEAR!");
delay(emergencyHold);
Serial.println("✅ Resuming normal traffic.");
}
// HELPER: Set a traffic light statevoidsetLight(int r, int y, int g, int rv, int yv, int gv) {
digitalWrite(r, rv);
digitalWrite(y, yv);
digitalWrite(g, gv);
}
// HELPER: Turn all LEDs offvoidallOff() {
for (int p = 2; p <= 7; p++) digitalWrite(p, LOW);
}
// HELPER: Wait but keep checking for sirens!voidwaitAndCheck(int ms) {
int elapsed = 0;
while (elapsed < ms) {
if (digitalRead(soundPin) == HIGH) {
emergencyProtocol();
return;
}
delay(50);
elapsed += 50;
}
}
7 Questions Kids Ask 🙋
❓ Why do ambulances need a green light so fast?
When someone is having a heart attack, every minute matters. Studies show that for every minute without treatment, survival chances drop by about 10%. Saving just 2 minutes can make a huge difference!
❓ What if a car horn triggers it by mistake?
Great question! You can adjust the sensitivity dial on the KY-037 sensor so only very loud, high-pitched sounds trigger it. Real city systems use frequency analysis or IR sensors to be even more accurate.
❓ Can I add more traffic lights?
Yes! The Arduino Uno has 13 digital pins, so you can control up to 4 traffic lights (4 × 3 = 12 pins + 1 for sensor). For even more, use an Arduino Mega with 54 digital pins!
❓ How do real city traffic systems work?
Real systems use GPS tracking in the ambulance, infrared transmitters, or 4G/5G networks. The ambulance sends a signal to a central server, which remotely changes all lights along the entire route!
8 Make It Even Cooler! 🚀
📺
Add LCD Screen
Show a message like "EMERGENCY!" when the ambulance is detected
🔔
Buzzer Warning
Add a buzzer that beeps when switching to emergency mode
🌡️
IR Sensor
Use an infrared sensor instead — more accurate than sound alone
📱
WiFi Alert
With ESP8266 module, send a phone notification when triggered!
Comments
Post a Comment