6131

A traffic light is a good beginner project for learning Arduino because it uses simple parts, clear timing logic, and easy-to-understand code. With only three LEDs, a few resistors, and an Arduino Uno, you can build a small traffic signal model that follows the same basic sequence used on real roads: red, green, yellow, and then back to red.

What You Will Learn

By completing this project, you will understand how to:

  •  Connect LEDs to Arduino digital pins 
  •  Use resistors to protect LEDs 
  •  Control LED states with digitalWrite()
  •  Create timing sequences with delay()
  •  Build a repeating control loop in Arduino code 
These same basic ideas are used in many larger electronics projects, including control panels, warning indicators, automation systems, and simple embedded devices.
Components Needed

You only need a few common parts:

Component   Quantity
Arduino Uno | 1
Breadboard | 1
Red LED | 1
Yellow LED | 1
Green LED | 1
220Ω resistor | 3
Male-to-male jumper wires | Several
USB cable | 1

The 220Ω resistors are used to limit current through the LEDs. Without resistors, the LEDs may draw too much current and become damaged.
How the Traffic Light Sequence Works

 A basic traffic signal uses three colors:

Light   Meaning
Red | Stop
Yellow | Prepare to stop or wait for the next signal
Green | Go

For this Arduino model, the sequence will be:

  1.  Red LED turns on for 5 seconds. 
  2.  Green LED turns on for 5 seconds. 
  3.  Yellow LED turns on for 2 seconds. 
  4.  The cycle repeats continuously. 
This is not a full real-world traffic controller, but it is enough to demonstrate the core logic behind a timed signal system.
Arduino Traffic Light Wiring

In this example, the LEDs are connected to Arduino digital pins 9, 8, and 7.

LED Color   Arduino Pin
Red LED | Pin 9
Yellow LED | Pin 8
Green LED | Pin 7
LED negative legs | GND

Each LED should be connected in series with a 220Ω resistor. The longer leg of the LED is the positive side, and the shorter leg is the negative side.
Wiring Steps

Place the three LEDs on the breadboard with enough space between them. Connect the positive leg of each LED to a 220Ω resistor, then connect the other side of each resistor to the matching Arduino pin.

Connect the negative leg of each LED to the breadboard ground rail. Then connect the breadboard ground rail to the GND pin on the Arduino.

Use the following pin setup:

C++

Red LED    -> Pin 9
Yellow LED -> Pin 8
Green LED  -> Pin 7
GND rail    -> Arduino GND

Check the LED direction carefully. If an LED is inserted backward, it will not light up.
Arduino Code for the Traffic Light

 Upload the following code to your Arduino Uno: 

C++

const int redLED = 9;
const int yellowLED = 8;
const int greenLED = 7;

void setup() {
  pinMode(redLED, OUTPUT);
  pinMode(yellowLED, OUTPUT);
  pinMode(greenLED, OUTPUT);
}

void setTrafficLight(bool red, bool yellow, bool green) {
  digitalWrite(redLED, red ? HIGH : LOW);
  digitalWrite(yellowLED, yellow ? HIGH : LOW);
  digitalWrite(greenLED, green ? HIGH : LOW);
}

void loop() {
  setTrafficLight(true, false, false);   // Red
  delay(5000);

  setTrafficLight(false, false, true);   // Green
  delay(5000);

  setTrafficLight(false, true, false);   // Yellow
  delay(2000);
}

This version uses a small helper function called setTrafficLight(). Instead of repeating three digitalWrite() lines every time, the function makes the code cleaner and easier to modify.
Uploading the Program

To run the project:

  1.  Connect the Arduino Uno to your computer using a USB cable. 
  2.  Open the Arduino IDE. 
  3.  Paste the code into a new sketch. 
  4.  Select Arduino Uno from the board menu. 
  5.  Choose the correct COM port. 
  6.  Click Upload
After the upload is complete, the LEDs should start switching automatically.
Testing the Circuit

When the program starts, the red LED should turn on first. After 5 seconds, it turns off and the green LED turns on. After another 5 seconds, the yellow LED turns on for 2 seconds. Then the cycle starts again.

If the circuit does not work, check these points:

Problem    Possible Cause
One LED does not light | LED may be reversed
All LEDs stay off | GND may not be connected
Wrong LED turns on | Pin wiring does not match the code
LED is very dim | Resistor value may be too high
Upload fails | Wrong board or COM port selected

Most beginner issues are caused by loose jumper wires, reversed LEDs, or mismatched pin numbers.
Project Upgrade Ideas

Once the basic version works, you can expand it in several ways:

  •  Add a pedestrian crossing light 
  •  Add a push button for crossing requests 
  •  Use a buzzer as a warning signal 
  •  Add an LCD countdown display 
  •  Build a two-way intersection traffic light 
  •  Replace delay() with millis() for better timing control 
These upgrades help you move from simple output control to more practical embedded system design.
From Breadboard Project to PCB

A breadboard is useful for learning and testing, but it is not ideal for long-term use. If the circuit needs to become a more reliable product, the next step is to turn it into a custom PCB.

For a production-ready version, the design should consider connector placement, power input, LED spacing, enclosure size, assembly method, and component availability. PCBCool can support this stage by helping with schematic review, PCB layout, BOM checking, component sourcing, PCB fabrication, and assembly.
Conclusion

The Arduino traffic light project is simple, but it teaches important electronics and programming basics. It shows how digital pins control external components, how timing works in an embedded program, and how a small circuit can simulate a real-world control system.

After completing this project, you can continue improving it with buttons, displays, buzzers, or more advanced timing logic. It is a practical first step toward building more useful Arduino and embedded electronics projects.

For the complete original version with more details, diagrams, and step-by-step guidance, please read the full guide on: Arduino Traffic Light Project.