Arduino Traffic Light Project: Circuit and Code
Build the signal at your school gate. Green to go, yellow to slow down, red to stop.
Parts you need
- Arduino Uno
- Red, yellow, green LEDs
- 3 × 220Ω resistors
Wiring
- Pin 12 → red LED
- Pin 11 → yellow LED
- Pin 10 → green LED
- All short legs → GND rail
Arduino code
int red = 12;
int yellow = 11;
int green = 10;
void setup() {
pinMode(red, OUTPUT);
pinMode(yellow, OUTPUT);
pinMode(green, OUTPUT);
}
void loop() {
digitalWrite(green, HIGH);
delay(3000);
digitalWrite(green, LOW);
digitalWrite(yellow, HIGH);
delay(1000);
digitalWrite(yellow, LOW);
digitalWrite(red, HIGH);
delay(3000);
digitalWrite(red, LOW);
}
Goal and tip
Goal: Light up all three colors in order.
Tip: Try this: make the green light stay on for 5 seconds.