3. Traffic light

Traffic Light

The traffic light project is a bit like "Hello world!" of control technology. It is a great project to get children started. They are all familiar with the traffic light and fully understand what it needs do.

Half the battle with any project you teach in school is finding a context that is relevant to the children's lives and that they fully understand. Even better if that context serves a useful function or solves a practical problem.

Task:

Program a set of traffic lights.


The model:

All you need for the model is a red, yellow and green LED with about 30 cm of wire attached to each leg of the LED.

To make it easier for the children to correctly connect the LEDs to the pins:

Use a red wire (on the longer leg of the LED) to indicate positive - this will connect to the pin side of the circuit.

Use a black wire (on the shorter leg of the LED) to indicate negative - this will connect to the GND side of the circuit.

A very simple traffic light model can be made from 3 LEDs and a piece of card. For a more permanent model some wood is used to support the lights.

Follow this link for model making ideas.

Algorithm:

forever:

when pedestrian presses button (A):

green light off, amber light oN

pause for 2 seconds

amber light off, red light on

display a tick (walk)

pause for 8 seconds (to allow pedestrians to cross)

amber light on

pause for 2 seconds

amber light off

green light on (cars may pass)

display a cross (don't walk)

N.B. See the Output page for information on using LEDs with the micro:bit.

A very basic traffic light model can be made by holding or taping a red, orange and green LED together. Take care not to cause a short circuit.

Using a strip of wood or MDF and a block of wood, a simple support can be made to hold the LEDs.


MakeCode editor script: