// Define the pin numbers for the LEDs
const int greenPin = 13; // Green LED
const int redPin = 2; // Red LED
const int yellowPin = 4; // Yellow LED
const int buzzerPin = 14; // You may need to change this based on your board
void setup() {
// Set the LED pins as outputs
pinMode(greenPin, OUTPUT);
pinMode(redPin, OUTPUT);
pinMode(yellowPin, OUTPUT);
pinMode(buzzerPin, OUTPUT);
}
void loop() {
// Blink the traffic light sequence 5 times
for (int i = 0; i < 5; i++) {
// Green - Go
digitalWrite(greenPin, HIGH);
digitalWrite(redPin, LOW);
digitalWrite(yellowPin, LOW);
tone(buzzerPin, 1000); // Turn on the buzzer at 1000 Hz
delay(2000); // Stay green for 2 seconds
noTone(buzzerPin); // Turn off the buzzer
// Yellow - Prepare to stop
digitalWrite(greenPin, LOW);
digitalWrite(redPin, LOW);
digitalWrite(yellowPin, HIGH);
delay(1000); // Wait for 1 second
tone(buzzerPin, 1500); // Turn on the buzzer at 1500 Hz
delay(1000); // Stay yellow for 1 second
noTone(buzzerPin); // Turn off the buzzer
// Red - Stop
digitalWrite(greenPin, LOW);
digitalWrite(redPin, HIGH);
digitalWrite(yellowPin, LOW);
delay(1000); // Wait for 1 second
tone(buzzerPin, 2000); // Turn on the buzzer at 2000 Hz
delay(2000); // Stay red for 2 seconds
noTone(buzzerPin); // Turn off the buzzer
}
// After blinking 5 times, you can add additional logic or leave the loop empty.
// The Arduino will continue running the loop function indefinitely.
}