Skip to content

Activity

Step counter

Beginner | MakeCode, Python | Accelerometer, LED display | Human body, Performance tools, Sensors, Variables

Step 1: Make it

What is it?

Turn your micro:bit into a step counter (or pedometer) to help you track how active you are - and learn some coding at the same time!

girl pointing at micro:bit step counter on another girl's shoe

How it works

  • Like the Dice project this program uses the micro:bit’s accelerometer to make something happen.
  • It counts how many times the micro:bit has been shaken. It stores this number in a variable called ‘steps’.
  • Variables are used by computers to store information that may change, such as the number of steps you’ve taken.
  • Every time the micro:bit accelerometer input senses a shake, the program increases the variable by 1, and shows the new number on the LED display output.

What you need

  • micro:bit (or MakeCode simulator)
  • MakeCode or Python editor
  • battery pack (optional)
  • something to attach the micro:bit to your shoe or leg – string, tape or Velcro.

Step 2: Code it

Step 3: Improve it

  • Add a button to reset the steps to 0.
  • Add a graphical representation of how many steps you’ve taken.
  • Measure the length of your average step and get your micro:bit to multiply this by the number of steps to calculate the distance you’ve walked.