/*
* Arduino UNO Traffic Light Control System
* MakeMindz.com — Beginner Embedded Systems Tutorial
*
* Simulates a real traffic signal using 3 LEDs:
* Green LED → Pin 3 → GO (5 seconds)
* Yellow LED → Pin 2 → SLOW (2 seconds)
* Red LED → Pin 1 → STOP (5 seconds)
*
* Each LED is connected via a 220Ω current-limiting resistor.
* Total cycle time: 12 seconds (repeating)
*/
const int greenPin = 3; // Green LED → Digital Pin 3
const int yellowPin = 2; // Yellow LED → Digital Pin 2
const int redPin = 1; // Red LED → Digital Pin 1
void setup() {
// Configure all LED pins as digital outputs
pinMode(greenPin, OUTPUT);
pinMode(yellowPin, OUTPUT);
pinMode(redPin, OUTPUT);
}
void loop() {
// ── Phase 1: GREEN — Vehicles GO ──────────────────
digitalWrite(greenPin, HIGH); // Turn green ON
delay(5000); // Hold for 5 seconds
digitalWrite(greenPin, LOW); // Turn green OFF
// ── Phase 2: YELLOW — Vehicles SLOW DOWN ──────────
digitalWrite(yellowPin, HIGH); // Turn yellow ON
delay(2000); // Hold for 2 seconds
digitalWrite(yellowPin, LOW); // Turn yellow OFF
// ── Phase 3: RED — Vehicles STOP ──────────────────
digitalWrite(redPin, HIGH); // Turn red ON
delay(5000); // Hold for 5 seconds
digitalWrite(redPin, LOW); // Turn red OFF
// Cycle restarts automatically — loop() repeats forever
}