Traffic Lights

Teachers - want real traffic lights in your classroom?

Real Traffic Lights

GPIO Support Services is pleased to announce that we have been given a set of real traffic lights that we can demonstrate in schools and colleges. This includes a complete traffic signal (Red, Amber & Green). With this children can write the code for the Traffic Light Project and see it working in action on full size hardware. If you would like us to come along to your school with these (no cost to the school & we are DBS checked) please get in touch.

A word of warning – real traffic lights are not small! – you will need a room with lots of space.

Welcome to the starter project for the gPiO box, as this is the first project we’ve included lots of detail.

There are a number of expanding text boxes like the one below  providing you with additional information such as curriculum links, videos that take you through building the model step by step and code examples for Scratch, Python and other languages. If you have not worked with the Raspberry Pi GPIO pins and or the gPiO box before we recommend that you watch the In the classroom video first.

Click box on right for Curriculum Links

KS2 Computing POS
design and write programs that accomplish specific goals, including controlling or simulating physical systems; solve problems by decomposing them into smaller parts
use sequence, selection, and repetition in programs; work with variables and various forms of input and output; generate appropriate inputs and predicted outputs to test programs
pupils should work in a range of relevant contexts [for example, the home, school, leisure, culture, enterprise, industry and the wider environment].
understand and use electrical systems in their products [for example, series circuits incorporating switches, bulbs, buzzers and motors]
apply their understanding of computing to program, monitor and control their products.


This is the starter project for the gPiO box


To program a set of traffic lights

Learning objectives

You will be able to:

  • set up and use a Raspberry Pi and gPiO interface.
  • connect electrical components (LEDs) to the output terminals of the gPiO interface.
  • program Scratch to switch outputs on and off in a prescribed sequence.
  • use loops in your script to repeat actions many times.

Design Brief

Using three LEDs, create a traffic light model and write a program to control a set of traffic lights in the following sequence:

red > red + amber > green > amber > and so on.

You will need a processing device (computer), an interface to connect the components to the computer and a power supply.

A simple traffic light model can be made from three coloured LEDs, connect the:

· Red LED to output 1

· Amber LED to output 2

· Green LED to output 3

Hot tip: Traffic lights use this sequence


red > red + amber > green > amber > and so on.

Making the model

You can also watch the video

Connecting to the gPiO Box

The traffic light model consists of three LEDs. Connect the:

· Red LED to output 1

· Amber LED to output 2

· Green LED to output 3

Watch the video below to see how to make the connections to the gPiO box.

Scripts & Code


If you use Flowol(TM) in your school you can download this flowchart from the Code Library. Version 4 and above of Flowol can be used with the gPiO Box, so that you can use this flowchart to control physical devices directly. For more information on using Flowol with the gPiO Box please contact us.



This is the Scratch2 version of this project.



Many children find it difficult to move from a block based language like Scratch to Python or other text based langauages. A fantastic new option is Edublocks that combines the visual aspects of Scratch with the syntax of Python.

Python Code


The suggested next project is the Automated Lighthouse