A step counter or pedometer tracks the number of steps you take! This project will walk you through how to code your micro:bit to track your activity. You can also boost your comfort and range using a CHARGE pack for your micro:bit!
Start by adding a variable under the Variables drawer and name it steps.
Add a “Set steps to 0” block to “on start”
Input drawer: add “on shake”
Variables drawer: add “change steps by 1” to “on shake” codeblock
Input drawer: add “on button A pressed”
Basic drawer: add “show number 0” to “on button A pressed” codeblock
Variables drawer: grab the steps variable block and drop it onto the 0 in the “show number” block.
Plug in your micro:bit, pair, download your code and test!
Or experiment with the finished code here:
Use the Step Counter:
Now attach the micro:bit to your ankle, turn on the CHARGE or battery pack and track your steps!
Make it better:
You might have noticed that the LEDs stay on after you press button A to check your steps or that it’s only tracking half your steps. Consider what you could edit in the code to clear the screen after a couple seconds or count 2 steps each time the micro:bit shakes.