Create Your Own Fitbit

We are all familiar with Fitbit and other smart watches even our phones counting our steps throughout the day. Let’s use a micro:bit to code our own.

What You Will Learn

How to

  • Create and use a variable.
  • The micro:bit shake function.
  • Use a while True loop.
  • Display a number on the LED matrix.
  • Use the button function.

What You Will Need

  • 1 x micro:bit.
  • 1 x micro USB cable.
  • 1 x Battery pack for the micro:bit (optional).

Coding

  1. Open your favourite browser ( we recommend Google Chrome) Within the address bar of the browser type python.microbit.org and press Enter . This will load the Python coding editor.
  2. Click on Line 4 and type steps = 0 and press Enter . This creates a variable called steps and sets it to 0.

    What is a variable

    Think of a variable as a box that stores information that can be used throughout our program. We give variables a descriptive name so we and others can understand what is going on within our program.

  3. Delete the text on lines 7-9 .
  4. Type the following code starting on line 7 .
    Code so far

Completed Code:

Completed Code

Now that we have completed the code we need to download it to the micro:bit.

Downloading the Code

  1. Take the micro USB cable and connect the micro:bit to the computer.
  2. Click on Connect . Click on your micro:bit and click connect again.

You have created your own Fitbit step counter why not connect a battery pack and strap your micro:bit to your ankle and go for a walk and see how many steps you have done at the end.