Students code with CreateAI's Machine Learning blocks (in the simulator with practice actions, then on their own model) to build an activity tracker.
Load these into Waypoints Prepare: choose Load URL and paste the copied address, or download the file and import it. In Prepare, the worksheet's Teacher edition shows the answers; the student copy hides them.
Predict and Run 8 min · Investigate 8 min · Modify 12 min · Make 12 min · Own model 5 min
The idea: the model estimates an action several times a second. on ML … start runs when the estimate changes to that action (once per stretch, not once per jump); on ML … stop runs when it changes away, with how long it lasted; unknown is the estimate when no action reaches its recognition point (CreateAI's word for the confidence threshold). is ML … detected and certainty are there for programs that check in forever.
Practice actions: a trained model only exists inside the project CreateAI makes, so this lesson's editor loads the Machine Learning blocks with six practice actions (from this site's own small extension) and the simulator's ML panel lets students choose the action. Real models use the same blocks with the actions students trained. Running the model on a micro:bit needs a V2.
This lesson has not yet been tried in the live MakeCode editor: check the ML panel appears beside the simulator before class.
Start and stop events, and a sensible response to unknown. Ask what the program should do when the model isn't sure.
| What you will see | A question to ask | The fix |
|---|---|---|
| There is no ML panel. | Is the editor full screen? Is the simulator running? | Open the editor full screen and restart the simulator. |
| The count goes up only once. | Did the action change between jumps? | Choose another action (still) in between. |
| Running time stays 0. | Did running stop? The stop event runs when the estimate changes away. | Choose running, then still, then press A. |
One possible solution for each task. Other correct programs are fine.

ml.onStart(ml.event.Jumping, function () {
jumps += 1
basic.showNumber(jumps)
})
ml.onStart(ml.event.Still, function () {
basic.showIcon(IconNames.Asleep)
})
ml.onStopDetailed(ml.event.Running, function (duration) {
running += duration
})
input.onButtonPressed(Button.A, function () {
basic.showNumber(Math.round(running / 1000))
})
let running = 0
let jumps = 0

ml.onStart(ml.event.Jumping, function () {
jumps += 1
basic.showNumber(jumps)
})
ml.onStart(ml.event.Still, function () {
basic.showIcon(IconNames.Asleep)
})
ml.onStart(ml.event.Unknown, function () {
basic.showString("?")
})
let jumps = 0

ml.onStart(ml.event.Still, function () {
basic.showIcon(IconNames.Asleep)
})
ml.onStart(ml.event.Walking, function () {
basic.showArrow(ArrowNames.East)
})
ml.onStart(ml.event.Running, function () {
basic.showIcon(IconNames.Rabbit)
})
ml.onStart(ml.event.Jumping, function () {
jumps += 1
basic.showNumber(jumps)
})
ml.onStart(ml.event.Unknown, function () {
basic.clearScreen()
})
ml.onStopDetailed(ml.event.Running, function (duration) {
running += duration
})
input.onButtonPressed(Button.A, function () {
serial.writeValue("jumps", jumps)
serial.writeValue("running", Math.round(running / 1000))
})
let running = 0
let jumps = 0
Stretch: Use certainty (%) ML jumping in forever to show a bar of how sure the model is.
Support: Give the jump count; students add the other actions.
Why does on ML jumping start run once during three jumps in a row?
It runs when the estimated action changes to jumping; three jumps in a row are one stretch of jumping.
Next: the capstone, your own AI sorter. Real world: fitness trackers, fall detection, sports coaching sensors.