< Return to Video

Simple AI exercise timer step-by-step video

  • 0:02 - 0:08
    To create your simple AI exercise timer, 
    you’ll train a machine learning (or ML) model. 
  • 0:08 - 0:15
    This model will recognise when you’re 
    exercising and when you’re not exercising.
  • 0:15 - 0:24
    You’ll then combine the model with some 
    ready-made code for an exercise timer...
  • 0:24 - 0:29
    before downloading it to your 
    micro:bit and using it in real life.
  • 0:29 - 0:36
    Click ‘Open in micro:bit CreateAI’ to launch the project. 
  • 0:36 - 0:41
    The project comes with 3 samples 
    of movement data for exercising
  • 0:41 - 0:45
    and 3 samples of movement 
    data for not exercising.
  • 0:45 - 0:51
    You’ll need to add more samples by 
    recording your own movement data.
  • 0:51 - 0:56
    micro:bit CreateAI collects movement 
    data samples using the accelerometer  
  • 0:56 - 1:02
    (or movement sensor) on the micro:bit.
    You will wear a micro:bit and battery  
  • 1:02 - 1:09
    pack on your wrist or ankle, so that you can move 
    freely to record your own movement data samples. 
  • 1:09 - 1:13
    To get started, you need to set 
    up the data collection micro:bit. 
  • 1:13 - 1:22
    Connect the wrist-worn micro:bit to CreateAI.
    If your computer has Bluetooth enabled then you  
  • 1:22 - 1:29
    will just need 1 micro:bit and a USB data lead.
    If you don’t have a Bluetooth connection,  
  • 1:29 - 1:34
    you’ll be prompted to use 2 micro:bits.
    The second micro:bit will remain connected  
  • 1:34 - 1:40
    to the USB cable and act as a radio 
    link to the data collection micro:bit.
  • 1:40 - 1:43
    Follow the instructions on screen to connect.
  • 1:44 - 1:47
    Once your data collection micro:bit is connected
  • 1:47 - 1:53
    you’ll see the lines on the live graph 
    change as you move your micro:bit about.
  • 1:53 - 1:58
    You’re now ready to add your 
    own movement data samples.
  • 1:58 - 2:04
    As this project already includes some 
    data samples, we suggest you just add  
  • 2:04 - 2:13
    1 more sample for each action for now, and spend 
    more time collecting and analysing data later.
  • 2:13 - 2:17
    Decide what ‘exercising’ 
    action you are going to do. 
  • 2:17 - 2:23
    This could be running, walking briskly, 
    jumping, boxing, dancing, or any other exercise. 
  • 2:23 - 2:30
    Make sure the micro:bit is attached to 
    the wrist or ankle that will be moving.
  • 2:30 - 2:34
    To add data to a specific action, 
    select it by clicking on it. 
  • 2:34 - 2:40
    You will get a 3 second countdown 
    before a 1 second recording starts. 
  • 2:40 - 2:45
    Click record and start moving right away 
    to ensure you get a clean data sample. 
  • 2:45 - 2:49
    A clean sample is one where you 
    are moving for the entire sample,  
  • 2:49 - 2:55
    you don’t start late or finish moving early.
    Next try adding an extra data sample  
  • 2:55 - 3:01
    to the ‘not exercising’ data set.
    Select it by clicking on the action,  
  • 3:01 - 3:06
    then stay still, or only move very 
    slightly as you record the sample. 
  • 3:06 - 3:11
    You’ll notice that the x,y,z 
    lines change places depending  
  • 3:11 - 3:15
    on the angle at which you hold your micro:bit.
  • 3:15 - 3:18
    The project doesn’t have a lot of data right now, 
  • 3:18 - 3:24
    but we have enough to train our own 
    machine learning model using CreateAI. 
  • 3:24 - 3:30
    So click ‘Train’ to use the 
    current data to build an ML model.
  • 3:30 - 3:35
    The tool now builds a mathematical 
    model that should recognise different  
  • 3:35 - 3:39
    actions when you move your micro:bit.
    As soon as the model has been trained,  
  • 3:39 - 3:44
    you’ll see the Testing model page.
    Your data collection micro:bit can now  
  • 3:44 - 3:50
    be used to test how well the model is working.
    It should still be connected to the tool,  
  • 3:50 - 4:00
    and you’ll see that as you move it, CreateAI 
    is estimating what action you are doing.
  • 4:00 - 4:05
    Try out different levels of exercising or 
    not exercising to see both the estimated  
  • 4:05 - 4:12
    action and the certainty bar graph change.
    The % on the certainty bar graph shows how  
  • 4:12 - 4:17
    confident the model is that 
    you are doing each action.
  • 4:17 - 4:22
    You may notice your model is not estimating 
    some actions accurately, or maybe it is  
  • 4:22 - 4:29
    working well for one action but not the other,
    so after exploring how it is currently working,  
  • 4:29 - 4:35
    it’s a good idea to click on ‘Edit 
    data samples’ and improve your model.
  • 4:35 - 4:41
    Machine learning models usually work best with 
    more data, so record some extra samples for each  
  • 4:41 - 4:49
    of the actions, or focus on collecting more data 
    for the action that was problematic in testing.
  • 4:49 - 4:54
    You can record 1 sample at a time or 
    you can record 10 samples in sequence.
  • 4:54 - 4:59
    Clean data samples also 
    help an ML model work better 
  • 4:59 - 5:06
    so interrogate your data set and identify any 
    data samples that could confuse the model. 
  • 5:06 - 5:12
    You can delete these by pressing x.
    Once you’ve added more data and checked  
  • 5:12 - 5:18
    your data set, click Train model 
    again to use your amended data set. 
  • 5:18 - 5:27
    Then test the model again on 
    the ‘Testing model’ page.
  • 5:27 - 5:30
    Once you’re happy with how 
    the ML model is behaving,  
  • 5:30 - 5:34
    you can use it with the ready-made project code.
  • 5:34 - 5:41
    Click on 'Edit in MakeCode' to see the code blocks 
    in a special version of Microsoft MakeCode.
  • 5:41 - 5:49
    You can always return to CreateAI using 
    the arrow in the top left of the screen.
  • 5:49 - 5:55
    These code blocks use the model you 
    have created within an exercise timer.
  • 5:55 - 6:00
    The code uses two variables to keep track 
    of how long you've been exercising and how  
  • 6:00 - 6:04
    long you've not been exercising.
    When the program first runs it sets  
  • 6:04 - 6:09
    these timer variables to 0.
    The 'on ML start' blocks are  
  • 6:09 - 6:15
    triggered when the ML model decides you have 
    started either exercising or not exercising. 
  • 6:15 - 6:19
    They show different icons on the 
    micro:bit's LED display depending  
  • 6:19 - 6:26
    on the action it has estimated you are doing.
    The 'on ML stop' blocks are triggered when the  
  • 6:26 - 6:33
    ML model decides you have finished an action, 
    in this case exercising or not exercising. 
  • 6:33 - 6:38
    Code inside each block clears the screen and 
    adds the duration of the action that has just  
  • 6:38 - 6:43
    finished to the variable storing 
    the total times for each action.
  • 6:43 - 6:50
    The ML model works with the code to allow you 
    to view the total time spent on each action. 
  • 6:50 - 6:55
    Press button A to see the total time you have 
    been exercising and press button B to see the  
  • 6:55 - 7:01
    total time you have been inactive.
    The timer counts in milliseconds,  
  • 7:01 - 7:08
    thousandths of a second, so the number shown 
    is divided by 1000 to show a time in seconds.
  • 7:08 - 7:13
    To make your simple AI exercise 
    timer run on your micro:bit, you  
  • 7:13 - 7:19
    just need to download this code to a micro:bit.
    If you don’t have another micro:bit available,  
  • 7:19 - 7:26
    simply replace the code currently on the data 
    collection micro:bit with the project code.
  • 7:26 - 7:31
    Now test the project out in real life.
    Do the correct icons display  
  • 7:31 - 7:37
    when you are exercising or not?
    You can test if the timer code is working  
  • 7:37 - 7:42
    well with the model in 3 easy steps:
    Press the reset button.
  • 7:42 - 7:46
    Exercise for 30 seconds.
    Then press button A.
  • 7:46 - 7:50
    You should see the number 30 
    scroll across your display.
  • 7:50 - 7:55
    You’re now ready to connect to CreateAI, 
    collect your own data, use it to train,  
  • 7:55 - 8:00
    test & improve a machine learning model.
    And you can then combine this model with  
  • 8:00 - 8:06
    the ready-made code and try 
    it out on your own micro:bit.
Title:
Simple AI exercise timer step-by-step video
Description:

more » « less
Video Language:
English
Team:
Microbit_Educational_Foundation
Duration:
08:08
Microbit_Educational_Foundation edited English subtitles for Simple AI exercise timer step-by-step video

English subtitles

Revisions