Coding Ireland STEM Report 2024 Have Your Say
Microbit Robotics
Intermediate
60 mins
120 points
What you need:
Computer/laptop
Microbit
Traffic Lights Kit
Phillips Screwdriver

Pedestrian Crossing

In this lesson, you will create a pedestrian crossing simulation using your micro:bit. You'll add a button that, when pressed, simulates a pedestrian waiting to cross, and the traffic light will change to let the 'pedestrian' cross.
Learning Goals Learning Outcomes Teacher Notes Lesson Files

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 courses.

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