Skip to content


Low energy step counter

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

Step 1: Make it

What is it?

Make a step counter with longer-lasting batteries.

micro:bit with blank display attached to shoe

How it works

  • Like the Step counter project this program uses the accelerometer to count a step every time the micro:bit is shaken and stores the total number in a variable called steps.
  • Keeping the LED lights on the micro:bit turned on requires more power. This program saves energy by only showing the step count when you press button A.
  • This means that the batteries will last longer, saving money, creating less waste and helping the environment.

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

1from microbit import *
4while True:
5    if accelerometer.was_gesture('shake'):
6        steps += 1
7    if button_a.is_pressed():
8        display.scroll(steps)

Step 3: Improve it

  • Modify the program so button B sets the counter back to 0.
  • Measure the length of your step and get micro:bit to multiply this by the number of steps to calculate the distance you’ve walked.
  • Think of ways of adapting other projects to make the batteries last longer.