← Code

micro:bit and the computer

A web page and a micro:bit talk over USB and radio. Graph a micro:bit's sensors, send it commands, relay messages by radio, train models on photos and on movements, and finish with an AI sorter of your own.

Start1. Send data to the computer

Talk over USB

The micro:bit sends readings to the computer as lines of text, and the computer sends it commands.

1Send data to the computerNot started

A micro:bit sends each sensor reading down the USB cable as a line of text, such as light:128. The computer turns the stream of lines into a graph.

  1. Predict
  2. Run
  3. Investigate › Names
  4. Investigate › No pause
  5. Investigate › Ben's logger
  6. Modify › Two values
  7. Modify › Faster
  8. Make
Start lesson
2Commands from the computerNot started

The computer can send lines of text too. The micro:bit reads each whole line and its program decides what the word means, so both sides must agree on every word.

  1. Predict
  2. Run it on a micro:bit
  3. Investigate › When it runs
  4. Investigate › Ben's micro:bit
  5. Investigate › Replies
  6. Modify › A new command
  7. Modify › Reply
  8. Make
Start lesson

A radio bridge

A micro:bit on the cable relays messages by radio, so the micro:bit doing the work can be anywhere in the room.

3A radio bridgeNot started

A micro:bit on the cable relays messages by radio, so the micro:bit doing the work can be anywhere in the room. The bridge passes radio to serial one way and serial to radio the other.

  1. Predict
  2. Run
  3. Investigate › Two directions
  4. Investigate › Ben's bridge
  5. Investigate › Its own messages
  6. Modify › Light too
  7. Modify › Beep
  8. Make
Start lesson

A model drives a build

Train a model in Teachable Machine, test it on photos it has never seen, then send its labels to a micro:bit.

4Train a recycling sorterNot started
5A model drives a micro:bitNot started

The board sends your model's label down the USB cable as a line of text. The micro:bit's program decides what each label does, and must also handle labels it doesn't expect.

  1. Predict
  2. Run it on a micro:bit
  3. Investigate › What is sent
  4. Investigate › Ben's sorter
  5. Investigate › Unsure labels
  6. Modify › Neither
  7. Modify › Reply
  8. Make a sorting flap
Start lesson

AI on the micro:bit

Train a model on movements with micro:bit CreateAI; it runs on the micro:bit itself, and the Machine Learning blocks act on what it recognises.

6Train movementsNot started

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.

  1. Predict
  2. What a movement looks like
  3. Train in CreateAI
  4. Investigate › A sample
  5. Investigate › A friend's run
  6. Investigate › Where it runs
  7. Improve the model › Partner test
  8. Improve the model › Not quite still
  9. Make
Start lesson
7Code with ML blocksNot started

The 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.

  1. Predict
  2. Run
  3. Investigate › Counting jumps
  4. Investigate › Unknown
  5. Investigate › Stop and duration
  6. Modify › Running time
  7. Modify › Not sure
  8. Make
Start lesson

Capstone: your own AI sorter

Choose a sorting problem, build a fair test set, train and improve a model, connect a micro:bit build, and report its limits.

8Capstone: your own AI sorterNot started

Choose a sorting problem, build a fair test set first, train and improve a Teachable Machine model until every group passes, connect a micro:bit build that acts safely on its labels, and report what it still gets wrong.

  1. Plan
  2. Milestone 1: build the test set first
  3. Milestone 2: train, test, improve
  4. Milestone 3: the build
  5. Report
Start lesson

Progress is saved in this browser only. Nothing is sent anywhere.

For teachers: Teacher guide (notes, answers, solutions, slides and worksheets)