Microbit Robotics
Beginner
60 mins
Teacher/Student led
120 points
What you need:
Chromebook/Laptop/PC
Microbit
Traffic Lights Kit
Phillips Screwdriver

Pedestrian Crossing

In this step-by-step lesson, you'll create a pedestrian crossing simulation using the MakeCode editor and micro:bit. You'll attach STOP:bit traffic lights, add the stopbit extension, create a 'seconds' variable, and program the traffic lights sequence. You'll also learn to detect button presses and download your code to the micro:bit for testing.
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 - New project and attach traffic lights

    Create a new project in the MakeCode editor for micro:bit by visiting https://makecode.microbit.org/.

    In this lesson, you will be using the STOP:bit traffic lights. Make sure to attach the STOP:bit traffic lights to your micro:bit before starting the 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 - Create the seconds variable

    We will need a variable in this project called 'seconds'. This will store the amount of seconds until the light turns green.

    Create a variable called 'seconds'.

    4 - Show the red light

    Now, let's set up the traffic lights. We want to show the red light at the start and a X on the microbit to indicate it is not safe to cross the road. Add the following code:

    5 - Button press detection

    Next, you'll detect when the button A on the micro:bit is pressed to simulate a pedestrian waiting to cross. Add the following code:

    This code does the following:

    • Set seconds to 5.
    • In a loop which goes while seconds is greater than 0, shows the number of seconds, subtracts 1 from the seconds variable and then waits 1 second.

    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 Coding Ireland. 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