|

Arduino Traffic Light Project: Step-by-Step Guide (2026)

Arduino Traffic Light Project: Step-by-Step Guide (2026)

Components Required

Before starting, gather the following components:

  • Arduino Uno (or any compatible board) — 1
  • Red LED — 1
  • Yellow LED — 1
  • Green LED — 1
  • 220Ω Resistors — 3
  • Breadboard — 1
  • Jumper Wires — a few
  • USB Cable (to connect the Arduino)
Arduino Uno, LEDs, resistors and breadboard components for traffic light project

Step 1: Understand the Circuit Diagram

Before wiring anything, it helps to understand the logic. Each LED will be connected to a separate digital pin on the Arduino:

  • Red LED → Pin 8
  • Yellow LED → Pin 9
  • Green LED → Pin 10

Each LED will be connected in series with a 220Ω resistor to limit current and protect the LED from burning out.

Arduino traffic light circuit diagram with red yellow green LED wiring

Step 2: Wiring on the Breadboard

Now let’s build the circuit physically:

  1. Connect the anode (longer leg) of each LED to one end of its corresponding resistor.
  2. Connect the other end of each resistor to the respective digital pin on the Arduino (8, 9, 10).
  3. Connect the cathode (shorter leg) of each LED to the breadboard’s ground (GND) rail.
  4. Connect the Arduino’s GND pin to the breadboard’s ground rail using a jumper wire.
Breadboard wiring for Arduino traffic light project with three LEDs

Tip: Double-check LED polarity (anode/cathode) before connecting. Reversed LEDs simply won’t light up.


Step 3: Writing the Code in Arduino IDE

Now open the Arduino IDE and upload the following code. Each part is explained below:

cpp

int redLED = 8;
int yellowLED = 9;
int greenLED = 10;

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

void loop() {
  // Green Light ON
  digitalWrite(greenLED, HIGH);
  delay(5000);
  digitalWrite(greenLED, LOW);

  // Yellow Light ON
  digitalWrite(yellowLED, HIGH);
  delay(2000);
  digitalWrite(yellowLED, LOW);

  // Red Light ON
  digitalWrite(redLED, HIGH);
  delay(5000);
  digitalWrite(redLED, LOW);
}

How the Code Works

  • pinMode() sets each pin as an OUTPUT.
  • Inside loop(), each LED turns ON and OFF in sequence, mimicking a real traffic signal’s timing pattern.
  • delay() controls how long each light stays on (in milliseconds).

Step 4: Upload and Test

  1. Connect the Arduino board to your computer using a USB cable.
  2. In Arduino IDE, go to Tools and select the correct Board and Port.
  3. Click the Upload button.
  4. Once uploaded, the LEDs will start cycling on and off — just like a real traffic signal.

Common Issues and Fixes

IssuePossible CauseFix
LED not lighting upReversed polarityCorrect the anode/cathode orientation
All LEDs light up togetherWrong pin numbers in codeMatch code pin numbers with circuit wiring
Upload errorWrong Board/Port selectedSelect the correct Board and Port from Tools menu

Next Steps: Level Up This Project

Once the basic version works, you can extend it further with:

  • A Push Button for a pedestrian crossing signal
  • A PIR Sensor for automatic traffic detection
  • A 4-way Traffic Signal System for controlling multiple directions

To dig deeper into Arduino functions and programming, check out the official Arduino reference documentation: Arduino Official Reference Documentation


Conclusion

The Traffic Light project is a great milestone in learning Arduino — it gives you practical experience with digitalWrite(), delay(), and basic sequential logic. If you’re completely new to Arduino and haven’t built anything before, start with our Arduino LED Blinking Project: Step-by-Step Guide to learn the basics, then come back to this project.

Similar Posts

2 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *