Program and Build Your Own Traffic Lights

3d printing ages 11+ chibitronics Classroom coding digital technologies Laser LED LEDs logic programming traffic lights years 7 and 8

This project uses visual block programming to model the logic of a traffic light and scale this logic to make two traffic lights work in tandem. You can do this solely in a web browser, or push your code onto a Chibi Chip and use conductive tape to incorporate this with physical models designed from a variety of mediums including 3d printing or laser cutting.

In this project, you will learn:

  • How to create an algorithm for paired traffic light logic in block programming (MakeCode) on tablet, phone, or computer
  • How to create structured data state tables to help model events and logic
  • Apply what we know to use conductive tape and coloured light stickers to make traffic lights with 3d-printing, cardboard, or wood

You will need:

  • A computer with a web browser that can connect to You can manage without any other hardware if you want to just do the exercise in MakeCode, but it will be more fun to program hardware and make your own lights!
  • A Chibitronics Chibi Chip
  • A Chibi-clip (optional but will make it easier to remove and reattach your Chibi Chip easily for multiple classes)
  • Conductive tape
  • Coloured Chibitronics sticker lights with 2 x red, 2 x yellow, and 2 x green for each pair of traffic lights. You can also use standard coloured LEDs.
  • A design for two traffic lights that will fit your stickers, either a drawing on paper, or cut-outs from cardboard, wood, or some 3d-printed traffic lights (you don’t necesarily need this to get started, but it’s a great way to take the exercise to a physical working model). For 3d design, you can get a free account at TinkerCAD for primary-aged kids or Fusion360 for high school and above.

Step 1: Create a single traffic light

Let’s start with a simple single traffic light. A traffic light cycles through red, amber, and green lights but even using 3 different colours will still work. We can represent our the 3 states of our traffic light with a state table.

State Red LED D0 Amber LED D1 Green LED D2
1 off off on
2 off on off
3 on off off
  • Go to your web browser and visit

  • To match the algorithm represented by our state table, we need to select 3 pins on the Chibi Chip for our red, amber, and green lights. These will be D0, D1, and D2. Create a variable called states

    create state variable

  • Let’s model each state. Look at the state table and you’ll see that one light is on for each state. We can arrange the blocks to set state to a number and then switch on the specific light that we need for that state. Here are the 3 states represented with a 2 second pause for each.
    block programming traffic light states

  • Traffic lights need to loop so let’s put our states into a forever loop.

    block coding traffic light states loop

Watch the Chibi Chip on the left of the screen cycle through the 3 lights, and make sure it looks right. If not, go back and check that your blocks look the same as the pictures.

Chibi chip simulator for makecode

Step 2: Extend our truth table to use 2 traffic lights

Here is our previous state table that shows 3 states with 1 traffic light

State Red LED D0 Amber LED D1 Green LED D2
1 off off on
2 off on off
3 on off off

We can add another traffic light to our state table - T1 is the first traffic light and T2 is the second traffic light. These traffic lights are arranged on different streets of an intersection (they need to work together to make sure traffic runs smoothly).

T1 T1 T1 T2 T2 T2
State Red LED D0 Amber LED D1 Green LED D2 Red LED D3 Amber LED D4 Green LED D5
1 off off on on off off
2 off on off on off off
3 on off off off off on
4 on off off off on off

Note: When one traffic light changes to amber, the other traffic light stays red - this gives the traffic enough time and warning to stop, before the traffic from the other street gets the green light to go. For this reason, we will need a forth state.

  • Set up the forth state and add it to our forever loop.

    Makecode traffic light loop 4 states

  • Following our new state table we can add the different on/off signals for our second traffic light using D3, D4, and D5. Using our variable to keep track of state makes things a lot easier, even though the variable doesn’t really do anything. Imagine how much harder this would be without our state table. Here is the updated forever loop with 4 states and two sets of traffic lights.

    Makecode visual coding two traffic lights

  • Now all that remains is to connect your conductive tape with 3 different coloured light stickers for each traffic light set. You could use red, yellow, and green. From here, you can either draw some traffic lights on paper or card, or cut out some and stand them up. If you have access to a 3d printer or laser cutter, you could even design some fancier traffic lights and arrange them on a model intersection! Or you can search for community contributed traffic light 3d models for printing here.

You can find out more about the Chibitronic supplies here and get some conductive tape here.

Older Post Newer Post