Microbit
Beginner
40 mins
Teacher/Student led
100 points
What you need:
Chromebook/Laptop/PC
Microbit
Traffic Lights Kit

Microbit Traffic Lights

In this step-by-step lesson, you'll create a Microbit project, add the Stopbit extension, and test all the lights. You'll learn about sequences in coding and program your traffic lights to display a sequence using on/off and state methods. You'll test your sequences to ensure they're working correctly.
Learning Goals Learning Outcomes Teacher Notes Lesson Files

Live Class Feed

This is a live feed of the latest activity by your students on this lesson. It will update in real-time as they work on the lesson.
Load previous activity

    1 - Create a new Microbit project

    Go to the makecode.com website and create a new Microbit project.

    2 - Add the Stopbit extension

    There are custom code blocks that we use to program our traffic lights kit. To add them to our toolbox we need to add the "stopbit" extension.

    Search for the "stopbit" extension and then click on the traffic lights kit picture.

    This will add the "Kitronik STOP:bit" category of code blocks to your toolbox.



    3 - Test all the lights

    First let's test that all the lights work on your traffic lights. Add the following code and then send it to your Microbit.

    After you have sent the code to your Microbit, test that each light works by pressing the A, B and A+B buttons. If any of the lights are flickering then make sure that the screws are tight.

    4 - What is a sequence?

    We are going to program the traffic lights to show the lights in a sequence. In coding, a 'sequence' is the order in which instructions happen. For example if you were programming a robot to put on her shoe, the sequence would be:

    1. put on her sock
    2. put on her shoe
    3. tie her laces

    For our traffic lights we are going to program them to go through this sequence:

    1. show green light for 5 seconds
    2. show yellow light for 1 seconds
    3. show red light for 2 seconds

    5 - Program the sequence using on/off

    Delete the code you have created already as we no longer need it.

    There are two different ways we can display the lights on the traffic lights. The first way is just by setting each light to either on or off.

    Add the following code to make the traffic lights forever go through the sequence. Once you've added the code, download and send it to your Microbit.

    Check that the lights are displaying in the right sequence.

    1. Green for 5 seconds
    2. Yellow for 1 second
    3. Red for 2 seconds

    Unlock the Full Learning Experience

    Get ready to embark on an incredible learning journey! Get access to this lesson and hundreds more in our Digital Skills Curriculum.

    Copyright Notice
    This lesson is copyright of DigitalSkills.org. Unauthorised use, copying or distribution is not allowed.
    🍪 Our website uses cookies to make your browsing experience better. By using our website you agree to our use of cookies. Learn more