To make your AI storytelling friend, you’ll train a machine learning,
or ML, model to recognise when a toy moves in different ways.
You’ll then combine this model with code to make different sounds and show different
icons on the micro:bit’s LED display.
Then you’ll download the model and the code to a micro:bit and use it on your toy to help tell a story.
Our story is about a bear called Lucy, but you can change the project to fit your own.
[MUSIC] This is Lucy the bear.
She wants to be a gymnast when she grows up, so every day when she wakes up, she practices her jumping.
She jumps as high as the ceiling. Then after breakfast she practices her rolling.
She rolls round and round until her whole world is spinning.
Then she takes a break and has a little nap.
To start making your AI storytelling friend, click ‘Open in micro:bit CreateAI’ to launch the project.
This project comes with 8 samples of movement data for three different actions:
jumping, rolling and sleeping.
micro:bit CreateAI collects movement data samples using the accelerometer, the micro:bit’s movement sensor.
To add your own data samples, you need to make a data collection micro:bit.
If your computer has Bluetooth enabled, then you'll just need 1 micro:bit and a USB data lead.
If you don’t have a Bluetooth connection, you’ll need to use 2 micro:bits.
Follow the instructions on screen to connect.
Once your data collection micro:bit is connected, attach it to your toy like this.
You’ll see the lines on the live graph change as you move your toy. As this project already includes quite a lot
of data samples, we suggest you add 1 sample for each action for now and collect more data later.
Click on the ‘jumping’ action so you can add more data samples to it.
You will get a countdown before a 1 second recording starts.
Click record and start moving your toy immediately to make sure you get a clean data sample.
A clean sample is one where you’re moving for the entire sample,
you don’t start late or finish moving early. Next try adding an extra data sample to the
‘rolling’ and ‘sleeping’ actions.
You’ll notice that when your toy is asleep, the x,y, and z lines change places depending on the orientation of the micro:bit.
Click ‘Train model’ to build the 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’ll see the Testing model page.
Your data collection micro:bit can now be used 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.
Move your toy in different ways to see the estimated action and the certainty bar graph change.
The percentage shows how certain, or confident, the model is that you are doing each action.
You may notice your model is not estimating some actions accurately.
In that case it’s 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.
Clean data samples also help an ML model work better so examine your data set and
identify any 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. 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 return to see your data in CreateAI at any time
using the arrow in the top left of the screen. These blocks use the model you’ve created in code.
The ‘on ML… start’ blocks react when the ML model decides your
toy is making a particular movement, or action. Depending on the action, the code shows different
icons on the micro:bit’s LED display output and plays different sounds on its speaker.
If it’s not sure what action your toy is doing – if the action is ‘unknown’ – it clears the screen.
And when each action stops, the code stops the micro:bit making any sound.
To make the code and the ML model run on your micro:bit,
you just need to download it to a micro:bit.
Press ‘Download’ and follow the instructions on screen.
Now test the finished project on a micro:bit attached to your toy.
Do the correct sounds play and icons display when your toy makes different movements?
Does it work equally well when someone else moves the toy?
If not, you can go back and collect more data from them and re-train the model.
Congratulations, you’ve trained your toy to react to different kinds of movement
using data you have collected, training an AI machine learning model, and combining it with
code to make an interactive storytelling toy! What other actions, or movements might your toy
make, perhaps as part of telling a story? Can you add them using the micro:bit and CreateAI?