// Define pins for North traffic light
const int redNorth = 23;
const int yellowNorth = 22;
const int greenNorth = 21;
// Define pins for East traffic light
const int redEast = 19;
const int yellowEast = 18;
const int greenEast = 17;
// Define pins for South traffic light
const int redSouth = 16;
const int yellowSouth = 15;
const int greenSouth = 14;
// Define pins for West traffic light
const int redWest = 13;
const int yellowWest = 12;
const int greenWest = 05;
// Timing constants (in milliseconds)
const int greenTime = 15000; // 15 seconds
const int yellowTime = 3000; // 3 seconds
const int redTime = 15000; // 15 seconds
void setup() {
// Initialize pins for North traffic light
pinMode(redNorth, OUTPUT);
pinMode(yellowNorth, OUTPUT);
pinMode(greenNorth, OUTPUT);
// Initialize pins for East traffic light
pinMode(redEast, OUTPUT);
pinMode(yellowEast, OUTPUT);
pinMode(greenEast, OUTPUT);
// Initialize pins for South traffic light
pinMode(redSouth, OUTPUT);
pinMode(yellowSouth, OUTPUT);
pinMode(greenSouth, OUTPUT);
// Initialize pins for West traffic light
pinMode(redWest, OUTPUT);
pinMode(yellowWest, OUTPUT);
pinMode(greenWest, OUTPUT);
// Start with North-South green, East-West red
digitalWrite(greenNorth, HIGH);
digitalWrite(redEast, HIGH);
digitalWrite(redSouth, HIGH);
digitalWrite(redWest, HIGH);
}
void loop() {
// North-South Green, East-West Red
digitalWrite(greenNorth, HIGH);
digitalWrite(redSouth, HIGH);
digitalWrite(redEast, HIGH);
digitalWrite(redWest, HIGH);
delay(greenTime);
// North-South Yellow
digitalWrite(greenNorth, LOW);
digitalWrite(yellowNorth, HIGH);
digitalWrite(yellowSouth, HIGH);
delay(yellowTime);
// All Red (Safety pause)
digitalWrite(yellowNorth, LOW);
digitalWrite(redNorth, HIGH);
digitalWrite(yellowSouth, LOW);
digitalWrite(redSouth, HIGH);
delay(1000); // 1 second safety pause
// East-West Green, North-South Red
digitalWrite(greenEast, HIGH);
digitalWrite(greenWest, HIGH);
digitalWrite(redNorth, HIGH);
digitalWrite(redSouth, HIGH);
delay(greenTime);
// East-West Yellow
digitalWrite(greenEast, LOW);
digitalWrite(greenWest, LOW);
digitalWrite(yellowEast, HIGH);
digitalWrite(yellowWest, HIGH);
delay(yellowTime);
// All Red (Safety pause)
digitalWrite(yellowEast, LOW);
digitalWrite(redEast, HIGH);
digitalWrite(yellowWest, LOW);
digitalWrite(redWest, HIGH);
delay(1000); // 1 second safety pause
// Repeat the cycle
}