top of page

LED Traffic Light
System

The basic concept of an LED traffic light system using an Arduino is to simulate the operation of a traffic signal at an intersection. The system controls three LEDs (red, yellow, and green) to mimic the sequence of a standard traffic light, with each LED representing a different signal (stop, get ready, and go).

​​

How It Works:

​

LEDs Represent Traffic Lights:

Red LED: Represents the stop signal.


Yellow LED: Represents the caution or ready-to-stop signal.


Green LED: Represents the go signal.
Sequential Operation:

The LEDs are controlled in a specific sequence to replicate the functioning of a traffic light:
Green LED turns on for a period (indicating "Go").


Yellow LED turns on for a short period (indicating "Prepare to stop").


Red LED turns on for a longer period (indicating "Stop").
After the red light, the cycle repeats, starting with the green light.

Materials Anchor

Materials

traffic material.jpg

To build a simple LED traffic light system with an Arduino Uno, you'll need the following materials:

Components:

 

1) Arduino Uno (or compatible board):

  • The microcontroller that controls the LEDs and manages the timing for the traffic light sequence.

​​

2) 3 x LEDs

  • Red LED: For the stop signal.

  • Yellow LED: For the caution signal.

  • Green LED: For the go signal.


3) 3 x 220 ohms Resistors

  • One resistor for each LED to limit the current and protect the LEDs from burning out.

​​

4) Breadboard

  • A platform to easily connect and organize your components.

​​

5) Jumper Wires

  • Used to connect the components together on the breadboard and to the Arduino.

​​

6) USB Cable (Type-A to Type-B)

  • Connects the Arduino to your computer for programming and power.

Setup Anchor

Basic Setup

Fritzing_breadboard_GREY.png
Fritzing_schematic_GREY_TRUE.png

1) Connecting the LEDs:

  • Insert LEDs into the Breadboard:

​​

  • Place the Red, Yellow, and Green LEDs on the breadboard in a row. The anode (long leg) of each LED should be connected to a separate digital pin on the Arduino.

​

  • Connect the LEDs:

​

  • Red LED Anode (long leg): Connect to digital pin 11 on the Arduino.

 

  • Yellow LED Anode: Connect to digital pin 12.

 

  • Green LED Anode: Connect to digital pin 13.

 

  • Cathodes (short leg) of all LEDs: Connect each to one end of a 220-ohm resistor.

 

  • Connect the other end of each resistor to the GND (ground) rail on the breadboard.


2) Power and Ground Connections:


Connect the GND pin on the Arduino to the GND rail on the breadboard. This common ground will be used for the LED cathodes.

​

Code
Code.webp

CODE BREAK-DOWN

Code Break Down
  • Define LED Pins

    Three constants, redLED, yellowLED, and greenLED, are defined and assigned to pins 13, 12, and 11, respectively. These variables specify which pins on the Arduino each LED is connected to.

​

  • The setup Function

    This function runs once when the Arduino is powered on or reset.

    • pinMode(redLED, OUTPUT);, pinMode(yellowLED, OUTPUT);, and pinMode(greenLED, OUTPUT); configure pins 13, 12, and 11 as output pins, which allows the Arduino to control the LEDs connected to these pins.

​

  • The loop Function

    The loop function runs continuously after setup completes. This function implements the traffic light sequence by turning each LED on and off with specified delays:

    • First, digitalWrite(greenLED, HIGH); turns on the green LED, and delay(10000); keeps it on for 10 seconds (10,000 milliseconds). Then digitalWrite(greenLED, LOW); turns the green LED off.

​

    • Next, digitalWrite(yellowLED, HIGH); turns on the yellow LED, and delay(2000); keeps it on for 2 seconds (2,000 milliseconds). Then digitalWrite(yellowLED, LOW); turns the yellow LED off.

​

    • Finally, digitalWrite(redLED, HIGH); turns on the red LED, and delay(8000); keeps it on for 8 seconds (8,000 milliseconds). Then digitalWrite(redLED, LOW); turns the red LED off.

​​​

bottom of page