A micro:bit step counter is a wearable computer project that connects coding, movement, and health. The micro:bit can sense motion with its built-in accelerometer, then use that motion to estimate when a step happens. Students can wear it on a lanyard, power it with a battery pack, and read the step total on the LED display.
This project matters because it turns an everyday fitness tool into something you can build, test, and improve yourself.
In MakeCode, the program usually checks the accelerometer reading again and again. When the motion goes above a chosen threshold, the code adds 1 to a step variable and shows the updated number on the LEDs. Good step counters also avoid counting the same step many times by adding a short pause or checking for a clear motion change.
Testing the design while walking, jogging, and standing still helps students tune the code so it counts real steps more accurately.
Key Facts
- A micro:bit has a built-in accelerometer that measures changes in motion along the x, y, and z directions.
- A variable can store the step count, such as steps = 0 at the start of the program.
- A simple rule is: if acceleration > threshold, then steps = steps + 1.
- The LED display can show the number of steps using show number steps.
- A pause after each detected step helps prevent double counting from one footstep.
- A USB cable loads the code onto the micro:bit, while a battery pack lets the step counter work when worn.
Vocabulary
- micro:bit
- A small programmable computer with buttons, sensors, lights, and pins that students can use to make electronic projects.
- Accelerometer
- A sensor that detects motion, tilt, and changes in speed.
- Variable
- A named place in a program that stores a value that can change, such as a step count.
- Threshold
- A chosen limit that a measurement must pass before the program takes an action.
- LED display
- A grid of small lights on the micro:bit that can show numbers, letters, icons, and patterns.
Common Mistakes to Avoid
- Setting the threshold too low, which is wrong because small shakes or normal body movement may be counted as steps.
- Setting the threshold too high, which is wrong because gentle walking steps may not be strong enough to get counted.
- Forgetting to reset steps to 0 at the start, which is wrong because the program may show an old or unexpected value.
- Counting every high accelerometer reading without a pause, which is wrong because one step can create several quick sensor readings and be counted more than once.
Practice Questions
- 1 A student walks 120 real steps, but the micro:bit counts 150 steps. How many extra steps did it count, and should the threshold probably be raised or lowered?
- 2 A program starts with steps = 0. It detects motion above the threshold 8 times, then the reset button sets steps back to 0, then it detects 5 more steps. What number should the LED display show?
- 3 Your step counter counts steps while you are standing still and swinging the lanyard. Explain one code change and one wearing change that could make the counter more accurate.