Overview
Ever wondered how a smartwatch or fitness band counts your steps? In this project, you're going to build your very own step counter using a micro:bitThe micro:bit is a tiny programmable computer, about the size of a matchbox, made for learning to code. It has two buttons, a grid of little red LED lights and built-in sensors that can detect movement, light and temperature.Full entry →!
Inside your micro:bit is a clever little sensor called an AccelerometerAn accelerometer is a tiny part inside the micro:bit that senses movement, like tilting, shaking or being turned over. It turns that movement into numbers your code can react to.Full entry →. It can feel when the micro:bit moves. We'll use it to spot every step you take, add them up, and show the total on the LED MatrixThe LED matrix is the grid of little red lights on the front of the micro:bit. By switching them on and off in patterns, your code can show numbers, letters and tiny pictures.Full entry → (the grid of lights on the front).
The best bit? When you're done, you'll have a real working fitness tracker you can pop on and take outside. Don't worry if something doesn't work first time, that's all part of coding. Let's give it a go!
What you'll learn
- How a light sensor measures the light around it
- How to use an if/else block to make a decision
- How to switch an RGB LED on and off automatically
What you'll need
- The micro:bit MakeCode editor
- micro:bit
- micro USB cable
- battery pack for the micro:bit (optional)
Key words
Variable
A variable is something that can change. Think of it like a labelled box: you pop something inside, and the label tells you what it is. You can swap what's inside whenever you like.
Real-world example: A variable called score might start at 0, then change to 1, 2 and 3 as you collect points in a game.
Accelerometer
An accelerometer is a tiny part inside the micro:bit that senses movement, like tilting, shaking or being turned over. It turns that movement into numbers your code can react to.
Real-world example: A bit like the sensor in a games controller that knows when you tilt it to steer, the accelerometer notices when the micro:bit moves.
LED Matrix
The LED matrix is the grid of little red lights on the front of the micro:bit. By switching them on and off in patterns, your code can show numbers, letters and tiny pictures.
Real-world example: Like a mini scoreboard made of dots, the LED matrix lights up to spell out your step count.
Forever loop
A forever loop repeats its instructions again and again without ever stopping (until you switch off or reset). It's perfect for anything you want to keep happening over and over.
Real-world example: Like a clock's second hand that keeps ticking round and round, a forever loop keeps running the same steps over and over.
Button
A button is a switch you press to tell your project to do something. The code can check whether it's being pressed or not.
Real-world example: Pressing a doorbell is just like pressing a button, one press sends a signal that makes something happen.
Navigating to the MakeCode Editor
On a Computer
- Open your favourite web browser. We recommend either Google Chrome or Microsoft Edge.
- In the Address bar type makecode.microbit.org.
- Select New Project and give it the name MicroFit.

On a Tablet or Phone
- Open the micro:bit app. If you don't have the app yet you can download it from your devices app store by searching for micro:bit.
- Select Create Code.
- Select New Project and name it MicroFit.
Set up the Code Area
- Select the
on startblock and drop it on the bin icon to delete it. - Select Input. Select a
on shakeblock and drop it within the code area. - Select Input. Select a
on button A pressedblock and drop it within the code area.

Change Steps by 1
- Select Variables, choose Make a Variable, and name it steps.
- Snap a
change steps by 1block inside theon shakeblock.
Every time the micro:bit detects a shake, it adds one to your steps VariableA variable is something that can change. Think of it like a labelled box: you pop something inside, and the label tells you what it is. You can swap what's inside whenever you like.Full entry →.

Show the number of steps
- Select Basic, then snap a
show numberblock inside theforeverblock. - Select Variables, then snap a
stepsblock onto theshow numberblock, where it says 0.
This Forever loopA forever loop repeats its instructions again and again without ever stopping (until you switch off or reset). It's perfect for anything you want to keep happening over and over.Full entry → keeps running and shows your step count on the LED MatrixThe LED matrix is the grid of little red lights on the front of the micro:bit. By switching them on and off in patterns, your code can show numbers, letters and tiny pictures.Full entry →

Reset the steps to zero
Select Variables, then snap a set steps to 0 block inside the on button A pressed block.
Now, pressing ButtonA button is a switch you press to tell your project to do something. The code can check whether it's being pressed or not.Full entry → A on the micro:bit resets your step VariableA variable is something that can change. Think of it like a labelled box: you pop something inside, and the label tells you what it is. You can swap what's inside whenever you like.Full entry → back to zero.

Downloading Your Code
Using a Computer
- Select the three dots next to Download.
- Select Connect Device.
- A pop-up will show you how to connect the micro:bit to the computer. Keep following the on-screen instructions.
- Select BBC micro:bit XXX and select Connect. The XXX is your own micro:bit's name, so don't worry if it looks a little different.
- Select Download.

Using a tablet or phone
- Select Download.
- Follow the on-screen instructions to pair the micro:bit with the micro:bit app.
Once you've finished the on-screen steps, your code downloads to your micro:bit.
Run it and Watch
Shake the micro:bit to watch your steps go up. Pop a battery pack on, attach the micro:bit to your wrist or ankle, and head outside to see how many steps you can rack up!
Dont Have a microbit We can test it on the MakeCode editor by selecting the white dot next to shake on the micro:bit simulator and watch our steps counter climb everytime we select the dot.

Try it yourself
Challenge: Set yourself a step goal! Add an if block inside the forever loop to check when steps reaches a target, like 20. When you hit it, make the micro:bit show a happy face or play a sound to celebrate, then press button A to reset and go again.
Stuck? Quick fixes
| Problem | Try this |
|---|---|
| The number doesn't go up when I shake it | Check your change steps by 1 block is inside the on shake block. Give the micro:bit one firm, clear shake. |
| The count jumps up by lots at once | A big wobble can look like several shakes. Try one single, definite shake each time. |
| Nothing shows on the LED matrix | Make sure the steps variable is snapped inside the show number block, and that show number is inside the forever block. |
| The number doesn't change straight away when I shake fast | That's okay, it's still counting! The micro:bit can't show the new number while the last one is still scrolling. Stop shaking for a moment and your latest total will pop up. |
| Button A won't reset the steps | Check the set steps to 0 block is inside the on button A pressed block. |
| My code won't download to the micro:bit | Use a data USB cable (not a charge-only one), make sure the micro:bit is paired, and try a different USB port. |