-
To create your AI activity timer, you
will train a machine learning, or ML, model
-
to recognise when you’re doing
different movements or activities.
-
You’ll then combine that model with some
ready-made code for an activity timer,
-
before downloading it to your
micro:bit and using it in real life.
-
Click ‘Open in micro:bit CreateAI’ to launch the project.
-
This project comes with 6 samples of movement
data for walking, 6 samples of movement data
-
for jumping up and down, and 6 samples of
movement data for staying fairly still.
-
You will add more samples by
recording your own movement data.
-
micro:bit CreateAI collects movement data
samples using the accelerometer,
or movement sensor, on the micro:bit.
-
You will wear a micro:bit and battery pack on your wrist or ankle
-
so that you can move freely
to record your own movement data samples.
-
To get started, connect the
ankle-worn micro:bit to CreateAI.
-
We call this the data collection micro:bit.
-
If your computer has Bluetooth enabled then you will just need 1 micro:bit with a battery pack and a USB data lead.
-
If you don’t have a Bluetooth connection,
you’ll be prompted to use 2 micro:bits.
-
The second micro:bit will remain
connected to the USB cable and act as
-
a radio link to the data collection micro:bit.
Follow the instructions on screen to connect.
-
Once your micro:bit is connected, you will see the lines on the live graph change as you move your micro:bit about.
-
You’re now ready to add your own movement data samples.
-
As this project already includes some data samples,
-
we suggest you just add 1 more sample for each action for now, and spend more time collecting and analysing data later.
-
Make sure your data collection micro:bit is attached to the inside of the ankle, with button B on top.
-
To add data to a specific action,
select it by clicking on it.
-
You will get a 3 second countdown
before a 1 second recording starts.
-
Click record and start moving right away
to ensure you get a clean data sample.
-
A clean sample is one where you
are moving for the entire sample,
-
you don’t start late or finish moving early.
-
Next try adding an extra data sample to the ‘jumping’ data set and the ‘being still’ data set.
-
Select them by clicking on the action, then click record and jump or stay quite still as you record the samples.
-
You’ll notice on the 'being still' samples
that the x,y,z lines change places depending on the angle of the attached micro:bit.
-
We don’t have a lot of data right now, but we do have enough to train our own machine learning model using CreateAI.
-
So click ‘Train model’ to use the
current data to build an ML model.
-
The tool now builds a mathematical model that should recognise different actions when you move your micro:bit.
-
As soon as the model has been trained, you will see the Testing model page.
-
Now use the data collection micro:bit to test how well the model is working.
-
It should still be connected to the tool, and you’ll see that as you move it, CreateAI is estimating what action you are doing.
-
Try out each of the actions to see
both the estimated action and the certainty bar graph change.
-
The % on the certainty bar graph shows how confident the model is that you are doing each action.
-
You may notice your model is not estimating
some actions accurately, or maybe it is
-
working well for one action but not the other,
so after exploring how it is currently working,
-
it is a good idea to click on ‘Edit
data samples’ and improve your model.
-
Machine learning models usually work best with
MORE data, so record some extra samples for each
-
of the actions, or focus on collecting more data
for the action that was problematic in testing.
-
You can record one sample at a time or
you can record 10 samples in sequence.
-
Clean data samples also help an ML model work
better so examine your data set and identify any data samples that could confuse the model.
-
You can delete these by pressing X.
-
Once you’ve added more data and checked your data set, click ‘Train model’ again to use your amended data set.
-
Then test the model again on the ‘Testing model’ page.
-
Once you’re happy with how the ML model is behaving, you can use it with the ready-made project code.
-
Click on ‘Edit in MakeCode’ to see the code
blocks in a special version of Microsoft MakeCode.
-
You can always return to CreateAI using
the arrow in the top left of the screen.
-
These code blocks use the model you
have created within an exercise timer.
-
The code uses 3 variables to keep track
of how long you've been doing each action.
-
When the program first runs it
sets these timer variables to 0.
-
The 'on ML start' blocks are triggered when the ML
model decides you have started a specific action.
-
They show different icons on the micro:bit's LED display depending on the action it has estimated you are doing.
-
The 'on ML stop' blocks are triggered when the ML model decides you have finished an action,
in this case walking, jumping or being still.
-
Code inside each block clears the screen and
adds the duration of the action that has just
-
finished to the variable storing
the total times for each action.
-
The ML model works with the code to allow you
to view the total time spent on each action.
-
Press button A to see the estimate
of how long you were walking.
-
Press button B to see how long the
model estimated you were jumping.
-
To see the estimated duration you have
been still press A and B together.
-
The timer counts in milliseconds, thousandths of a second, so the number shown is divided by 1000 to show a time in seconds.
-
To make your AI activity timer run on your micro:bit, you just need to download this code to a micro:bit.
-
If you don’t have another micro:bit available,
simply replace the code currently on the data collection micro:bit with the project code.
-
Now you can test the project out in real life.
-
Do the correct icons display
when you are exercising or not?
-
You can test if the timer code is working
well with the model in 3 easy steps:
-
Press the reset button.
Jump for 30 seconds.
-
Then press button B.
You should see the number 30 scroll across your display.
-
You’re now ready to connect to CreateAI,
-
collect your own data, use it to train, test and
improve a machine learning model, and then you
-
can combine this model with the ready-made
code and try it out on your own micro:bit.
-
If you’re looking for ways to personalise this even more try adding some different actions like running or dance steps.
-
Enjoy!