Skip to main content

Step Counter

Main Image
Information Technology

Learners create a Micro:bit step counter using Make Code.

What You Need

Guide:

Safety Notes

  • Ensure you are familiar with Let's Talk Science's precautions with respect to safe delivery of outreach to youth. 
  • Refer learners to this Micro:bit safety guide, on how to use the equipment safely

What To Do

  • Learners can work independently, or in groups of two to three. Ask educator to group learners, if applicable. 
  • Learners visit Microsoft Make Code website to develop the code for the counter, following the instructions below: 

Part 1: Make a step counter—Instructions 

Blocks 

Click on the ‘New Project’ button under My Projects and give your project a name. 

 

Delete the on start block and the forever block.https://makecode.microbit.org/28908-31820-65101-57564 

Graphical user interface, application

Description automatically generated with medium confidence

Create a variable.  

 

Under Variables, select Make a Variable 

Graphical user interface, application

Description automatically generated

Type in the name steps and click on the OK button. 

Graphical user interface, application

Description automatically generated

 

You will now have a variable called ‘steps’.  

Graphical user interface

Description automatically generated

Under Variables, click and drag a change steps by block onto the screen.  

 

You will note that it is shaded out at this point.  

Graphical user interface, text, application

Description automatically generated

Under Input, select the on shake block and drag it onto the screen. Click on the change steps by block and snap it into the on shake block.  

Graphical user interface

Description automatically generated

PRO Tip: Always pull in a block from the right-hand side.  

If you click on the small downward arrow beside the word steps, you will see that the variable steps is checked.  

Graphical user interface

Description automatically generated

Now every time you shake the Micro:bit it will increase the number of steps by one.  

 

At this time, you cannot see the number of steps. For this, you need to add code to display a number.  

Graphical user interface

Description automatically generated

 

Under Basic, click and drag a show number block onto the screen and place it under the change steps by 1 block. 

Graphical user interface

Description automatically generated

 

Under Variables, click and drag on the steps variable block onto the screen and snap it into the show number block where the 0 is.  

Graphical user interface, application

Description automatically generated

Notice how the steps variable is shaped like a puzzle piece that fits into the show number block.  

You can now test the code using the virtual Micro: bit beside your working area by clicking on the white circle beside the word SHAKE. You should see the number go up by one each time you click SHAKE.  

 

Save your work and upload the code to the Micro:bit.  

 

Part 2: Showing a message—Instructions 

Blocks 

In this next part you will add a way to give the user an encouraging message.  

 

Under Input select the on button A pressed and drag it into the empty space on your working area.  

Graphical user interface

Description automatically generated

Did you know? In coding, a “string” is a sequence of characters that can contain letters, numbers and punctuation.  

Under Basic, select the show string block and snap it into the on button A pressed block.  

 

 

Graphical user interface, text, application, chat or text message

Description automatically generated

Change the word “Hello!” in the show string block to a word or phrase of encouragement, such as “Keep going!” 

 

You can test this to see if it works by clicking on the A button on the Micro:bit simulator. You should see the words scrolling across the screen.  

Graphical user interface, text, application, chat or text message

Description automatically generated

Duplicate the show number block from Part 1 by right-clicking on the block and selecting Duplicate from the top of the menu. Drag the block so that it is beneath the show string block. 

Graphical user interface, text, application, chat or text message

Description automatically generated

Save your work and upload the code to the Micro:bit.  

 

Part 3: Clearing the screen—Instructions 

Blocks 

Under Input, select the on button A pressed block and drag it into an empty space on your working area. In the pull-down menu, change on button “A” pressed to on button “B” pressed block.  

Duplicate the show number block from Part 1 by right- clicking on the block and selecting Duplicate from the top of the menu. Snap it into the on button B pressed block.  

Under Basic, select the pause (ms) block and place it beneath the show number block. Adjust the value to 1000 ms (1 second).  

Graphical user interface, text, application, chat or text message

Description automatically generated

Under Basic and … More select the clear screen block. Snap it in beneath the pause block.  

 

Save your work and upload the code to the Micro:bit.  

Graphical user interface, text, application, chat or text message

Description automatically generated

Part 4: Resetting step counter—Instructions  

Blocks  

Under Input, select the on button A pressed block and drag it into the empty space on your working area. In the pull-down menu, change on button “A” pressed to on button “A+B” pressed.  

To have the display reset to 0, under Variables, select the set steps to block and snap it into the on button “A+B” pressed block.  

Make sure the variable is still called ‘steps’. 

 

 

To display the value 0 to the user, duplicate the show number block from Part 1. Drag the block so that it is beneath the set steps to block.  

Graphical user interface, application

Description automatically generated

You can test this to see if it works but click A+B button on the simulator. A zero (0) should be displayed. 

 

Save your work and upload the code to the Micro:bit. 

 

In this activity, learners will take their digital skills to the next level by using Microsoft Make Code to develop the code for their own Micro:bit step counter. The Micro:bit has a built-in accelerometer sensor, which measures acceleration, allowing learners to track changes in movement, like steps. Accelerometers can be found on devices such as smartphones and step counters. Through this activity, learners further develop computational thinking skills, critical thinking, testing and evaluation skills, which better prepare learners for the real and the digital world. 

Staying healthy is important—whether you are on Earth or in space. Eating nutritious foods, exercising, refraining from smoking, etc. are all great ways for people to stay healthy—astronauts, too! On long duration missions, astronauts aboard the ISS must exercise approximately two hours a day! This keeps their muscles and bones strong and healthy for when they return to Earth. 

In this activity, learners will use Microsoft Make Code  to develop the code for their own Micro:bit step counter, taking advantage of built-in accelerometer sensor. They can further extend their learning by participating in physical challenges, like how astronauts exercise in space, to test the accuracy of their step counters. 

As technology advances, it is more important than ever that people contribute to the digital world. Through this activity, learners further develop computational thinking skills, critical thinking, testing and evaluation skills, which better prepare learners for the real and the digital world. Being able to think critically is an important skill to have that helps learners become constructive citizens and interact with the world in meaningful ways.  

  • Learners can watch this video: Physical Activity in Space, in which David Saint-Jacques explains how astronauts exercise in space. 
  • Learners can watch this video: Canadian Bio-Monitor Smart Shirt System, in which David Saint-Jacques explains how the Canadian Bio-Monitor smart shirt system works. 
  • Learners can turn their Micro:bits into wearable step-counters. For this activity, learners would need to use the Micro:bit battery pack, as well as additional material such as: 
    • Scissors 
    • Washi or duct tape 
    • Velcro circles 
    • Decorative stickers, gems, etc. 
  • Learners can follow a Design & Build process to create their wearable step-counters and use them during physical activity time to assess their durability and comfort. 
  • Encourage learners to predict the number of steps before doing a physical activity and then check their results when done. How close were their predictions? 

What's Happening?

In this activity, learners will take their digital skills to the next level by using Microsoft Make Code to develop the code for their own Micro:bit step counter. The Micro:bit has a built-in accelerometer sensor, which measures acceleration, allowing learners to track changes in movement, like steps. Accelerometers can be found on devices such as smartphones and step counters. Through this activity, learners further develop computational thinking skills, critical thinking, testing and evaluation skills, which better prepare learners for the real and the digital world. 

Why Does it Matter?

Staying healthy is important—whether you are on Earth or in space. Eating nutritious foods, exercising, refraining from smoking, etc. are all great ways for people to stay healthy—astronauts, too! On long duration missions, astronauts aboard the ISS must exercise approximately two hours a day! This keeps their muscles and bones strong and healthy for when they return to Earth. 

In this activity, learners will use Microsoft Make Code  to develop the code for their own Micro:bit step counter, taking advantage of built-in accelerometer sensor. They can further extend their learning by participating in physical challenges, like how astronauts exercise in space, to test the accuracy of their step counters. 

As technology advances, it is more important than ever that people contribute to the digital world. Through this activity, learners further develop computational thinking skills, critical thinking, testing and evaluation skills, which better prepare learners for the real and the digital world. Being able to think critically is an important skill to have that helps learners become constructive citizens and interact with the world in meaningful ways.  

Investigate Further

  • Learners can watch this video: Physical Activity in Space, in which David Saint-Jacques explains how astronauts exercise in space. 
  • Learners can watch this video: Canadian Bio-Monitor Smart Shirt System, in which David Saint-Jacques explains how the Canadian Bio-Monitor smart shirt system works. 
  • Learners can turn their Micro:bits into wearable step-counters. For this activity, learners would need to use the Micro:bit battery pack, as well as additional material such as: 
    • Scissors 
    • Washi or duct tape 
    • Velcro circles 
    • Decorative stickers, gems, etc. 
  • Learners can follow a Design & Build process to create their wearable step-counters and use them during physical activity time to assess their durability and comfort. 
  • Encourage learners to predict the number of steps before doing a physical activity and then check their results when done. How close were their predictions?