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
R1,R2,R3
220 Ω
U1
Arduino UNO
D1
Green LED
D3
Red LED
D2
Yellow LED
How To Build
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
}