← micro:bit and the computer

Train movements

A movement is a short recording of x, y and z acceleration. micro:bit CreateAI learns the shape of those recordings from your samples, so it tells movements apart by how they move, and the model then runs on the micro:bit itself.

A smartwatch counts your steps and knows when you start running, without a camera and without sending anything to a computer. A small model on the watch reads its motion sensor.

In Teachable Machine the model learned from photos and ran on the computer. In micro:bit CreateAI it learns from movements, measured by the micro:bit's motion sensor (the accelerometer), and the finished model runs on the micro:bit.

You need: a micro:bit (a V2 to run the model on the micro:bit later), a battery pack, and Chrome or Edge. CreateAI connects by Bluetooth, or by radio through a second micro:bit plugged into the computer; it shows you which.

WidthMore contexts, same idea.
PredictRead the code and say what it will do before you run anything. A wrong guess is fine: it shows you what to look for.

Predict

You train four actions: still, walking, running and jumping, with the micro:bit on your wrist. Which two will the model mix up most?

RunRun it and compare the result with your prediction.

What a movement looks like

This logger sends x, y and z acceleration 20 times a second. Run it, open Show data, and tilt the simulated micro:bit with the mouse. Each movement is a pattern in three lines.

The program as blocks
Show as code
motion.ts
basic.forever(function () {
    serial.writeValue("x", input.acceleration(Dimension.X))
    serial.writeValue("y", input.acceleration(Dimension.Y))
    serial.writeValue("z", input.acceleration(Dimension.Z))
    basic.pause(50)
})
Try it yourselfYour edits are saved in this browser.
It takes a few seconds to load. Your work in this step is kept.

Run TypicalRun it and compare the result with your prediction.

Walk and run

Hold the micro:bit (still plugged in) at your side. Walk on the spot for five seconds, then run on the spot. Compare the waves.

Try it yourselfYour edits are saved in this browser.

Download the logger to a micro:bit, connect it, and record yourself walking on the spot, then running on the spot.

Use the board. This ticks when you get there.

RunRun it and compare the result with your prediction.

Train in CreateAI

  1. Open micro:bit CreateAI and start a new session. Follow its steps to connect your micro:bit; put it in the battery pack on your wrist or in your hand.
  2. Make four actions: still, walking, running and jumping. Record at least three samples of each (a sample is one second of movement).
  3. Click Train model, then test it: the testing page shows the action it estimates and how sure it is.

InvestigateTrace how each line of code connects to what you see.

Investigate

What does CreateAI record in one sample?

Your model knows your running. A friend runs with the micro:bit held differently, and it says walking. What is the fix?

The Teachable Machine sorter ran on the computer. This model runs on the micro:bit. Which is true?

ModifyChange the code on purpose and check the result.

Improve the model

Swap micro:bits with a partner. Test each other's models: do each action three times. Add samples of the actions it got wrong (yours and theirs), retrain, and test again.

Real "still" includes fidgeting and shifting your weight. Record still samples that include those.

MakeBuild something new using what you have learned. Expect a few tries; that is normal.

Make

Finish an activity model that recognises still, walking, running and jumping for someone who didn't train it: three times in a row for each action. Keep the CreateAI session open (or save it): next lesson you code with it.

For teachers

Students see movements as data (x, y and z over time), train an activity model in micro:bit CreateAI, and improve it until it works for someone who didn't train it. About 50 minutes.

Open the teacher guide: answers, solutions, slides and a worksheet.

Students will be able to

Before class

The idea: a movement is a short recording of the accelerometer's x, y and z readings. CreateAI's model learns the patterns in the samples it is given (a sample is about a second), so the lessons from the recycling sorter carry over: the model knows only its examples, and variety (other people, other ways of holding it) is the fix. The new part is where the model runs: on the micro:bit itself, with no camera, computer or connection.

CreateAI (createai.microbit.org) is free and needs no account. In Chrome or Edge it connects by Bluetooth with one micro:bit, or by radio through a second micro:bit on a USB data cable if the computer has no Web Bluetooth. iPads and Android tablets use the CreateAI app. Any micro:bit can collect data and train; running the model on the micro:bit (next lesson) needs a V2. School device policies can block Web Bluetooth or WebUSB: test one device before class.

Without micro:bits: the logger runs in the simulator (tilt it and use Show data), but training needs real micro:bits; run the CreateAI steps as a demonstration.

Running the lesson

  1. Predict: most get walking and running. Ask: what is different about them?
  2. Walk and run: put two students' graphs side by side.
  3. Train: three samples each is the minimum; more, varied samples are better.
  4. Improve: the partner test is the recycling sorter's messy bench again.

The hard part (on purpose)

Collecting enough varied samples per action. When everything is recognised as one action, ask how many samples each has and how different they are.

When students get stuck

Stretch and support

Stretch: Add a fifth action (such as star jumps) and find which existing action it gets confused with.

Support: Train in pairs: one moves, one records.

Where it leads

Next: code with the model, using the Machine Learning blocks. Real world: fitness trackers, fall detection for older people, gesture controls in game controllers.

What each step is for

Now you can
Next lesson7. Code with ML blocksThe Machine Learning blocks run code when the model's estimated action changes. on ML start runs once when an action begins, not again while it carries on, and unknown means no action is sure enough.