Micro:Bit Step Counter

You need:

  1. Micro:Bit (with power pack)
  2. Micro USB Cable
  3. Computer that the non-Micro USB end of the can be plugged in

Start by opening the BBC Micro:Bit MakeCode page.

Click on new project and name it ‘Step Counter’ then press the Create button.

Open the ‘Basic’ menu and drag a ‘Show String’ block out and put it in the ‘On Start’ block

Next, open the ‘Input’ menu and drag out the ‘On Shake’ Block and put it in the window.

Open ‘Variables’ and make a variable and name it ‘Steps’. Drag the ‘Set Steps to 0’ block into ‘On Start’ below the ‘Show String’ block.

Open ‘Variables’ again and drag the ‘Change Steps By 1’ block into the ‘On Shake’

Right now it should look like this:

Now we’ve got the complicated part! We’ve got to make a system where it checks for steps recorded and shows the number of steps recorded if 1 or more has been recorded.

Open the Logic menu and drag the ‘If/Else’ block into the ‘Forever’ block. Open the ‘Logic’ menu again and drag the ‘0<0’ Block over ‘True’ in the If/Else block. It should look like this now:

Open the ‘Variables’ menu and drag ‘Steps’ over the first 0 in the 0<0 block. Replace the second 0 with 1 and click on the < and select > from the other menu. The ‘Forever’ block now look like this:

Open the ‘Basic’ menu and drag the ‘Show Number’ block into If like this:

Open the variables menu. Drag the ‘Steps’ block over the 0 in the ‘Show Number’ block. Your code should look like this:

Now we need to transfer the code to the Micro:Bit. Plug the cable into your computer at one end and your Micro:Bit on the other.

Click the ‘Download’ button:

It will guide you through getting it onto the Micro:Bit.

You could attach it to yourself in many ways including using tape!

Email us a photo of yours at: projects@tec-kid.co.uk

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.