Closeup of a Charge for micro:bit wrapped around a child's ankle wearing crocs.

Introducing the Step Counter

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!

What you need:

With CHARGE for micro:bit

  • micro:bit (V1 or V2)
  • USB cable
  • Chromebook, laptop, or desktop
  • CHARGE w/ wrist strap

Without CHARGE

  • micro:bit (V1 or V2)
  • USB cable
  • Chromebook, laptop, or desktop
  • power bank or battery pack
  • wrist strap, clips, or elastic bands

Code your Step Counter:

  1. Open makecode.microbit.org
  2. Start by adding a variable under the Variables drawer and name it steps.
  3. Add a “Set steps to 0” block to “on start” 
  4. Input drawer: add “on shake” 
  5. Variables drawer: add “change steps by 1” to “on shake” codeblock
  6. Input drawer: add “on button A pressed”
  7. Basic drawer: add “show number 0” to “on button A pressed” codeblock
  8. Variables drawer: grab the steps variable block and drop it onto the 0 in the “show number” block.
  9. 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.