Step 1: Make it
What is it?
A step-counter you can make more accurate by tailoring it to your own walking style.
How it works
- The Step counter and Low energy step counter projects use the ‘shake’ gesture to count steps; the micro:bit uses several accelerometer sensor readings to decide if the micro:bit has been shaken.
- You may find that the ‘shake’ gesture isn’t triggered every time you take a step, or that it’s triggered too easily, leading to inaccurate counting of steps.
- The accelerometer input measures forces in units called ‘milli-g’. The Earth’s gravity is 1000 milli-g and can be measured by the micro:bit when it’s not moving (at rest).
- This program uses more accurate accelerometer readings of forces to decide whether to increase the step counter by 1.
- In this program, if the force is greater than 1500 milli-g (> 1500), the steps variable is increased by 1. 1500 milli-g is the threshold – the point at which a force will trigger a step to be counted.
- You may need to change the 1500 number to make the step counter more accurate – but you can decide what threshold to use, whereas with the ‘shake’ gesture the threshold has been decided for you by the people who designed the micro:bit.
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 or Velcro.
Step 2: Code it
Step 3: Improve it
- Make your batteries last longer by changing the program so it only shows the number of steps when you press button A.
- 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.
- The accelerometer can measure forces in 3 dimensions, called the X, Y and Z axes. You can modify the code to choose which axis to measure, depending on which way up you fix your micro:bit to your leg or shoe.