Source: https://mokxi.com/teachers/traffic-light-lab
Updated: 2026-11-09

Ready-to-teach lab

# Arduino traffic light lab: three LEDs, one sequence

This Arduino traffic light lab runs green, yellow and red LEDs through a timed sequence, and it is where students first meet a function of their own and a program with states.

Ages 11 and up, after blink. About 45 minutes. Students read and change an Arduino sketch.

Open this lab Assign to my class

The lesson

## Objective and parts

### By the end, students can

- Control several outputs in a fixed sequence.
- Read a function with parameters and say what calling it does.
- Change the timing of a program and add a new step to it.

### Parts, already on the bench

- An Arduino Uno
- A green LED on pin 3, a yellow LED on pin 4 and a red LED on pin 5
- Three 220 ohm resistors, one for each LED

Nothing to hand out or collect: the circuit opens built and wired.

Steps

## What students do

Each step is short enough to read out. Students work in the simulator beside this page.

Open this lab

- Open the lab and press Run. Time each color with a watch.
- Open the serial monitor. The sketch prints the name of each state as it starts.
- Open the code and find the lights() function. What do its three values mean?
- Make green last eight seconds and yellow one second.
- Add a new phase: red and yellow lit together for one second before green, as signals in the United Kingdom do.
- Add a flashing yellow mode: yellow blinks five times before the sequence starts again.

Questions

## Questions for students

Hand these out as they are. The expected answers are under the list, for you.

- How long is one full cycle in the sketch as it opens?
- What does a call such as lights(HIGH, LOW, LOW) do?
- Why does each LED have its own resistor, and not one shared by all three?
- While delay(5000) runs, can the sketch notice anything else, such as a button?

Answer key for the teacher

- Twelve seconds: green for 5, yellow for 2 and red for 5.
- It sets all three LEDs at once: the first value is green, the second yellow, the third red. So this turns green on and the others off.
- Each LED needs its own current limit. Sharing one resistor would change the brightness whenever more than one LED is lit.
- No. delay stops the whole program. A crossing with a button has to check the button during the wait.

Go further

## For students who finish early

- Add a pedestrian button that shortens the green.
- Build a second set of lights for the crossing road and keep the two from being green together.

Your class

## Give this lab to every student

Assign to my class puts this circuit on each student’s class page as a starter. They change their own copy and hand it in, and the work comes back to you in one list.

The class tools are free for 30 days for one class of up to 20 students, with no card. Opening and running the lab needs no account and stays free.

Assign to my class Start a free class

More labs

## The other labs in the set

Ohm's law Circuits. 40 min. Series and parallel Circuits. 45 min. Voltage divider Circuits. 40 min. LED and resistor Circuits. 30 min. RC circuit Electronics. 50 min. Transistor switch Electronics. 45 min. Logic gates Electronics. 40 min. Arduino blink Arduino. 35 min. Button and LED Arduino. 40 min. Ultrasonic distance Arduino. 45 min. Servo sweep Arduino. 40 min. All labs The whole set on one page.
