Using a CreateAI Model in MakeCode
CreateAI is a free, web-based tool that makes it easy to explore artificial intelligence with micro:bit. In this tutorial, we’ll show you how to use your trained CreateAI model in a MakeCode program. You’ll learn how to use your model’s predictions to control a micro:bit’s behaviour.
Materials
- micro:bit (V2)
- Power source for the micro:bit, like the CHARGE for micro:bit
- micro USB cable
- Computer with internet access
- A previously trained machine learning model from CreateAI
Instructions
A video walk-through of this tutorial is available here (stop at 5 min 20 sec):
Step 1: Open a MakeCode Project
After you’ve trained a model in CreateAI, the ‘Edit in MakeCode’ button will become available in the bottom right corner of the dashboard.

Clicking this button will automatically open a new MakeCode project with your trained model and the necessary extension already imported. Notice the new ‘Machine Learning’ block category!

Step 2: Program the micro:bit to use the model
The starter code for your project will include one event block for each action you trained. For example, if you trained the model on ‘waving’, ‘thumbs up’, and ‘jazz hands’, you should see the following:

By default, each time the model predicts a certain action is being performed, an icon will be displayed on the micro:bit’s LEDs. You can customize this by selecting a new icon from the dropdown menu in the show icon
blocks.

To add a sound output, simply drag a play tone
block from the ‘Music’ category into each event:

Step 3: Download the program to your micro:bit
Click the ‘Download’ button in the bottom left corner of the MakeCode editor. Connect your micro:bit to your computer with the micro USB cable and follow the on-screen instructions to download the program. The .hex
file will be copied to your micro:bit, and the program will begin to run.
Step 4: Test your program
Unplug your micro:bit from the computer. As long as it is connected to a power source like the CHARGE for micro:bit, the program should continue to run. Perform the physical actions you trained the model to recognize, such as waving or giving a thumbs up. Your micro:bit should respond with the icons and sounds you programmed in MakeCode!
Next Steps
Now that you know how to use your machine learning model within a MakeCode program, you can get creative! Try building a project that uses your model to control a second micro:bit using radio functionality. Check out these projects for inspiration:
Feeling Stuck? Explore the Knowledge Base for common questions and troubleshooting tips.