মূল বিষয়বস্তুতে যান
Back to Projects
BeginnerArduino Uno R3
25 minutes build

Traffic light

Three LEDs, three resistors and a function that runs the light sequence.

Interactive Simulation

Traffic lightarduino-uno
Open in Lab
UNOATmega328P: The 8-bit AVR microcontroller that runs your sketch (16 MHz, 32 KB flash, 2 KB RAM).ATmega328PUSB-B: USB connection for uploading sketches and for the Serial Monitor. Also powers the board (5 V).DC jack: Barrel jack for 7–12 V from a battery pack or adapter (centre positive).ATmega16U2: Converts USB to serial for uploads and Serial.print().RESET: Restarts your sketch from the beginning (setup() runs again).L (D13): Built-in LED connected to pin 13 (LED_BUILTIN).ON: Power indicator.5 V regulator: Turns 7–12 V from VIN/jack into a steady 5 V.16 MHz: Clock source: the microcontroller runs 16 million cycles per second.ICSP: In-circuit programming header (SPI). Used to burn a bootloader; not needed for normal uploads.220 Ω220 Ω220 Ω+++

Required Components Checklist

Assembly Steps

1

Wire the LEDs

Connect pins 12, 11 and 10 each through a 220 Ω resistor to the anode (long leg) of the red, yellow and green LED. Join all cathodes to GND.

2

Write the show() helper

One function sets all three LEDs and waits — the loop then reads like the real sequence.

3

Run and time it

Watch the Serial tab: each phase is printed. Real traffic lights run green for much longer — change the timings.

Arduino Sketch

const int RED_LED = 12;
const int YELLOW_LED = 11;
const int GREEN_LED = 10;

void setup() {
  pinMode(RED_LED, OUTPUT);
  pinMode(YELLOW_LED, OUTPUT);
  pinMode(GREEN_LED, OUTPUT);
  Serial.begin(9600);
}

void show(int r, int y, int g, int ms, String name) {
  digitalWrite(RED_LED, r);
  digitalWrite(YELLOW_LED, y);
  digitalWrite(GREEN_LED, g);
  Serial.println(name);
  delay(ms);
}

void loop() {
  show(HIGH, LOW, LOW, 3000, "STOP");
  show(HIGH, HIGH, LOW, 1000, "GET READY");
  show(LOW, LOW, HIGH, 3000, "GO");
  show(LOW, HIGH, LOW, 1000, "SLOW DOWN");
}

Challenges & Extensions

Ready to take this project further? Try these challenges:

  • •Add a pedestrian button that shortens the green phase.
  • •Rewrite it with millis() so the button is read instantly.
  • •Add a blinking yellow 'night mode' after 10 cycles.