Arduino Traffic Lights
This is a simple traffic light project that simulates the behaviour of European traffic lights:
First Red. Then Red + Yellow. Then Green. Then Yellow.
This repeats over and over. You can tweak the times for each stage in the code.
The Circuit
Parts List
D1
Green LED
D2
Yellow LED
D3
Red LED
R1
220 Ω
R2
220 Ω
R3
220 Ω
U1
Arduino UNO
The Layout
Code for the Arduino:
void loop() {
// Red light ON
digitalWrite(greenPin, LOW);
digitalWrite(yellowPin, LOW);
digitalWrite(redPin, HIGH);
delay(5000); // Red for 5 seconds
// Red and Yellow ON together
digitalWrite(greenPin, LOW);
digitalWrite(yellowPin, HIGH);
digitalWrite(redPin, HIGH);
delay(2000); // Red + Yellow for 2 seconds
// Green ON
digitalWrite(greenPin, HIGH);
digitalWrite(yellowPin, LOW);
digitalWrite(redPin, LOW);
delay(5000); // Green for 5 seconds
// Yellow ON
digitalWrite(greenPin, LOW);
digitalWrite(yellowPin, HIGH);
digitalWrite(redPin, LOW);
delay(2000); // Yellow for 2 seconds
}