Cnipbotics
Home
CoursesPricingContact
All Projects
Beginner

Traffic Light Simulator

Build a miniature traffic signal that cycles through Green, Yellow, and Red using three LEDs and an Arduino Uno, learning to wire LEDs with resistors and write timed sequences in Arduino code.

Arduino Uno R3, Red LED, Yellow LED, Green LED, 220Ω Resistors, Breadboard, Jumper Wires
Traffic Light Simulator

Traffic Light Simulator

Learning Objectives

  • Understand the basic principles of traffic signal control
  • Wire LEDs with current-limiting resistors on a breadboard
  • Write an Arduino sketch with delay() to sequence LED states
  • Relate real-world timing constraints to embedded programming

Overview

The Traffic Light Simulator is the classic first Arduino project. You will build a miniature traffic signal that cycles through Green → Yellow → Red using three LEDs and an Arduino Uno. Along the way you'll learn how to protect LEDs with resistors, write a timed sequence in C++, and debug your circuit with a multimeter.

Good to Know

Real traffic lights use programmable logic controllers (PLCs) with much more complex state machines that account for pedestrian crossings, emergency vehicle overrides, and adaptive timing based on traffic density. Your Arduino sketch is a simplified model of this same idea.


Components Required

ComponentQuantitySpecification
Arduino Uno R31ATmega328P, 5 V logic
Red LED15 mm, standard
Yellow LED15 mm, standard
Green LED15 mm, standard
220 Ω Resistor3¼ W, 5% tolerance
Breadboard1Half-size (400 tie points)
Jumper Wires6+Male-to-male, 20 cm
USB Cable (Type-B)1For upload and power

Circuit Diagram

Step 1
Wire the LEDs

Connect each LED anode (+) through a 220 Ω resistor to the corresponding Arduino digital pin:

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

Connect all LED cathodes (−) to the breadboard's GND rail, which connects to Arduino's GND pin.

ACTIVITY

Resistor Color Code Challenge

Before wiring, identify each 220 Ω resistor using the color code: Red – Red – Brown – Gold. Use a multimeter in resistance mode to verify the value is between 209 Ω and 231 Ω (5% tolerance band).


Arduino Sketch

Step 2
Write the Code
// Traffic Light Simulator
// Pins
const int RED_PIN    = 8;
const int YELLOW_PIN = 9;
const int GREEN_PIN  = 10;
 
// Timing (milliseconds)
const int GREEN_TIME  = 5000;
const int YELLOW_TIME = 2000;
const int RED_TIME    = 5000;
 
void setup() {
  pinMode(RED_PIN,    OUTPUT);
  pinMode(YELLOW_PIN, OUTPUT);
  pinMode(GREEN_PIN,  OUTPUT);
}
 
void loop() {
  // GREEN phase
  digitalWrite(GREEN_PIN,  HIGH);
  digitalWrite(YELLOW_PIN, LOW);
  digitalWrite(RED_PIN,    LOW);
  delay(GREEN_TIME);
 
  // YELLOW phase
  digitalWrite(GREEN_PIN,  LOW);
  digitalWrite(YELLOW_PIN, HIGH);
  delay(YELLOW_TIME);
 
  // RED phase
  digitalWrite(YELLOW_PIN, LOW);
  digitalWrite(RED_PIN,    HIGH);
  delay(RED_TIME);
}

Good to Know

delay() blocks the entire microcontroller — the Arduino cannot do anything else while waiting. In a production traffic controller, engineers use non-blocking timers (via millis()) so the processor can handle pedestrian buttons and sensor inputs simultaneously.


Testing Your Circuit

Step 3
Upload and Observe
  1. Open Arduino IDE and paste the sketch above.
  2. Select Tools → Board → Arduino Uno and the correct Port.
  3. Click Upload (→ arrow).
  4. Observe the LED sequence: Green (5 s) → Yellow (2 s) → Red (5 s) → repeat.
ACTIVITY

Timing Experiment

Modify GREEN_TIME to 2000 and RED_TIME to 8000. Re-upload and observe how the light cycle changes. Discuss: why do real intersections use longer red phases on main roads?


Troubleshooting

| Symptom | Likely Cause | Fix | |---------|-------------|-----| | LED doesn't light | LED inserted backwards | Flip the LED (longer leg = anode/+) | | All LEDs stay off | Wrong pins in code | Check const int values match wiring | | LED very dim | Resistor too high | Use 220 Ω, not 2.2 kΩ | | Upload fails | Wrong port selected | Tools → Port → select your COM port |


Extension Challenges

ACTIVITY

Pedestrian Button

Add a push button to pin 2. When pressed, extend the RED phase by 5 seconds to simulate a pedestrian crossing request. Use digitalRead() inside the loop.

Explore more projects

View All Projects
Stay updated

Subscribe to
our newsletter

Get the latest curriculum updates, project ideas, and school program announcements delivered to your inbox.

Ready to get started?

Bring structured robotics to your school

Schedule a DemoView Curriculum
200+
Schools nationwide
4.8★
Teacher satisfaction
4
Class levels covered
100%
NEP 2020 aligned
CnipboticsCnipbotics

India's structured robotics curriculum for CBSE schools — Class 7 to Class 10.

CurriculumClass 7 — DiscoveryClass 8 — ExplorationClass 9 — EngineeringClass 10 — InnovationCBSE Chapter Mapping
ProgramsBrowse CoursesPricing & KitsRequest a DemoAbout Us
CompanyAbout UsContactPricing
Get in touch

Questions about curriculum, pricing, or ATL lab setup?

Contact Us

School partnership

info@cnipbotics.com

© 2026 Cnipbotics. All rights reserved.

TermsPrivacyCookiesAccessibility