Home / Hands-on activities / State Machine Traffic Light

Coding activity

State Machine Traffic Light

Build a traffic light from paper! Learn that it goes green, then yellow, then red, then back to green — always in the same order. Practice following the pattern and acting out what cars do at each color.

BuildingAbout 30 minutesScreen-freeParent help expected

Materials and setup

How this changes by age

Pre-K (ages 3–4)

Build a traffic light from paper! Learn that it goes green, then yellow, then red, then back to green — always in the same order. Practice following the pattern and acting out what cars do at each color.

Difficulty 1 of 3

Steps

  1. Cut out three circles: red, yellow, green. Glue them on a black rectangle to make a traffic light.
  2. Hold up green: 'Green means GO! Walk around the room.' Yellow: 'Yellow means SLOW DOWN!' Red: 'Red means STOP!'
  3. Practice the sequence: green, yellow, red, green, yellow, red. The child acts out each.
  4. Ask: 'Can we go from green straight to red? No! It always goes green, yellow, red in order.'
  5. Play Traffic Light Simon Says: hold up a color, everyone does the action. Switch colors in the correct order.
  6. Tell a grown-up one thing that surprised you.

Learning objectives

  • Build a model of a traffic light and identify each color's meaning
  • Follow a fixed sequence of states in the correct order
  • Understand that some things always follow the same pattern

Kindergarten (ages 5–6)

Build a working traffic light with paper and a spinner! Learn about states and transitions — each color is a state, and there are rules for changing from one state to the next. Draw a state diagram!

Difficulty 2 of 3

Steps

  1. Build a traffic light with flaps: fold paper so you can reveal one color at a time.
  2. Draw a state diagram: three circles (Green, Yellow, Red) with arrows showing the transitions between them.
  3. Act it out: 'We are in GREEN state. After 10 seconds, we TRANSITION to YELLOW. After 3 seconds, transition to RED.'
  4. Add a crosswalk button: 'IF button pressed AND light is GREEN, THEN transition to YELLOW sooner.'
  5. Play: one person is the traffic light (follows the state diagram), others are cars and pedestrians.
  6. Tell a grown-up one thing that surprised you.

Learning objectives

  • Draw a state diagram showing states and transitions between them
  • Follow state transition rules including timed and event-based triggers
  • Understand that a system can only be in one state at a time

Early elementary (ages 6–8)

Design a full intersection with traffic lights! Create state machines for two roads that coordinate so traffic flows safely. Add pedestrian signals, left turn arrows, and emergency vehicle overrides.

Difficulty 2 of 3

Steps

  1. Build two traffic lights from cardboard — one for each road at an intersection.
  2. Design the state machine: when Road A is green, Road B must be red. Draw the full state diagram with all transitions.
  3. Add timing: Green = 15 seconds, Yellow = 3 seconds, Red = 18 seconds (to allow overlap for safety).
  4. Add a pedestrian signal: Walk and Don't Walk states. When does it change? How does it coordinate with the car lights?
  5. Emergency override: IF ambulance detected THEN all lights go red except the ambulance's road goes green. Draw this on your state diagram.
  6. Simulate your intersection for 5 full cycles. Verify no two roads are green at the same time!
  7. In one sentence, tell a parent or sibling what surprised you today.

Learning objectives

  • Design coordinated state machines where multiple systems interact safely
  • Add complex transitions including timed, event-based, and priority overrides
  • Verify system correctness by tracing through all possible states

Upper elementary (ages 8–10)

Master finite state machines by designing complex systems beyond traffic lights. Model a vending machine, elevator, or game character as a state machine. Prove your design handles all possible inputs correctly.

Difficulty 3 of 3

Steps

  1. Choose a system to model: vending machine, elevator, or video game character. Define all possible states.
  2. For a vending machine: states might be Idle, Accepting Coins, Selecting Item, Dispensing, Making Change. Define every transition between states.
  3. List all possible inputs: insert coin, press button, item out of stock, cancel. For EACH state, define what happens for EVERY possible input.
  4. Create a state transition table: rows = states, columns = inputs, cells = next state and action taken.
  5. Test edge cases: What if someone inserts a coin and then cancels? What if the selected item is out of stock? Does your machine handle these correctly?
  6. Build the physical model from cardboard and demonstrate it working through 5 different scenarios, following your state diagram exactly.
  7. In one sentence, tell a parent or sibling what surprised you today.

Learning objectives

  • Design a complete finite state machine with defined states, inputs, and transitions
  • Create a state transition table that handles every possible input in every state
  • Verify system correctness by testing edge cases and unusual input sequences

Safety and evidence note

Read the full activity before beginning. An adult should supervise tools, heat, food, outdoor work, movement, and experiments as appropriate. Completion records that the activity was done; the child’s explanation, work sample, photo, or demonstration is stronger evidence of learning than a completion check alone.

Related coding activities

Browse all 575 activities · Explore course syllabi