Arduino Traffic Light Project: Simple Wiring and Code Guide
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.
- 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
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.
Light Meaning
Red | Stop
Yellow | Prepare to stop or wait for the next signal
Green | Go
For this Arduino model, the sequence will be:
- Red LED turns on for 5 seconds.
- Green LED turns on for 5 seconds.
- Yellow LED turns on for 2 seconds.
- The cycle repeats continuously.
LED Color Arduino Pin
Red LED | Pin 9
Yellow LED | Pin 8
Green LED | Pin 7
LED negative legs | GND
C++
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.
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.
- Connect the Arduino Uno to your computer using a USB cable.
- Open the Arduino IDE.
- Paste the code into a new sketch.
- Select Arduino Uno from the board menu.
- Choose the correct COM port.
- Click Upload.
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.
- 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
For the complete original version with more details, diagrams, and step-by-step guidance, please read the full guide on: Arduino Traffic Light Project.
Build This Project
Bring this design to life with the Elektor PCB Service, powered by Eurocircuits. Upload the project files and order professionally manufactured PCBs or assembled boards through a proven European production platform.
Supporting KiCad, Eagle, Gerber, and ODB++ formats, the service is suitable for everything from prototypes and validation builds to series production and volume manufacturing.
Made in Europe. Fast. Reliable. Professional.

Discussion (0 commentaire(s))