In this lesson students will program the micro:bit to control external devices to create a traffic light sequence for a pedestrian crossing in the UK. Students will learn the basics of how the traffic lights system works and therefore will improve their knowledge of road safety.
- Learn how to program multiple external outputs with the micro:bit to work in conjunction and independently of each other.
- Gain a basic understanding of the traffic light sequence for a pedestrian crossing in the UK.
Download the Code
Click the button below to download the MakeCode editor code for this lesson. The hex file is contained in a zip folder.
Kindly refer to our download the code page for instructions on how to upload your code onto the micro:bit. Please use instructions set A.
This code can also be uploaded into the MakeCode editor.
Bi Colour LED Red/Blue
Bi Colour LED Red/Green
Bi Colour LED Red/Yellow
- MicroUSB Cable
- 4 x Connector Cable
- Connect the micro:bit to the Innovation board via the edge connector.
- Connect the speaker to ADC1 using one of the connector cables. Connect the red/blue LED to ADC2, the red/yellow LED to ADC3 and the red/green LED to IO1 using the other connector cables.
- Connect the micro:bit to a computer via the microUSB cable.
- Go to the MakeCode website on your computer and open a new project.
Time to Code
What Will Happen
When the micro:bit is powered the red/green LED will show green. If button A is pressed then the traffic light sequence will begin. The green LED will turn off and the yellow LED will light up for 3 seconds before turning off. The red LED will then show show. At the same time the speaker will beep to simulate a pedestrian crossing. This will happen for 10 seconds before the sequence continues to yellow and finally back to green.
Taking it Further
- Design a 3D model of a traffic light that in corporate the LED devices and the speaker.
- Adjust the traffic light sequence to simulate traffic lights in other countries around the world.
Keep in Touch
We would love to keep in touch with you and as a result aid you along your digital making journey.
Becoming a digital maker subscriber means you will receive exclusive offers and we will keep you up to date with new resources and kits, as well as upcoming events and workshops.
Let us know how your digital education journey is progressing. Send us pictures and videos of your awesome creations and use the hashtag below.