Add AI to Any DIY Robot
Teachable Machine is an educational web app developed by Google that simplifies the process of training a machine learning model for image, sound, and pose classification tasks. Using a computer webcam, you can easily upload photos of your training data and, within minutes, have a functioning model capable of recognizing hand gestures, objects, patterns, and more. This makes Teachable Machine a fantastic educational tool in the classroom for demonstrating the principles of machine learning and helping young students grasp the basics of Artificial Intelligence in practice.
This app acts as a bridge to connect your trained model with a Micro:Bit board. Once your model is ready, you can open it in the Teachable Micro:Bit App, connect via Bluetooth to the Micro:Bit, and send the names of detected classes to your robot, enabling you to program its behavior any way you want.
The best feature of the Teachable Micro:Bit app is that it can run on your smartphone, which is small enough to be mounted directly on your robot. This makes it very easy to create an autonomous robot with AI capabilities!
How It Works
- Train a Model in Teachable Machine
If you want to learn how to use Teachable Machine, you can check my tutorial. - Export the Model to the Cloud
Within Teachable Machine, export the model to the cloud. You will receive a link that looks something like this:https://teachablemachine.withgoogle.com/models/Jgyr546VH/
- Open the Teachable Micro:Bit App
On your laptop or mobile device, open the app and click the START image button. A prompt window will appear where you need to paste the link to your Teachable Machine model. - Allow Camera Access
Allow the browser to use your device camera. After loading the model, you should see a camera preview and the names of detected classes displayed below the camera window. - Prepare Your Micro:Bit
Use MakeCode to write a program that allows the Micro:Bit to connect to Bluetooth UART and receive string data. You can find a sample code snippet below. - Connect to the Micro:Bit
Click the robot head icon in the upper-right corner to connect to the Micro:Bit board. - Control Actions
Once the connection is established, the Micro:Bit will receive class names from the app. You can then control the robot’s actions based on these messages using your Micro:Bit code.
Micro:Bit Code Template
This code will activate bluetooth UART on the Micro:Bit board and display received strings as text on the board display.
If the app does not detect the Micro:Bit board after uploading the code make sure you are using compatible web browser (Chrome, Edge). You might also check Makecode project settings for bluetooth, it should look like this:
VERY Important Notes!
- When you train your Teachable Machine model, use class names without spaces. If you need multi-word class names, join them with underscores, like this:
this_class_name
. - When you export a model to the could and open it in Teachable Micro:Bit App it gets cached in browser memory and if try to make some modifications in the model and update it in the cloud the Micro:Bit app will still load the cached version, to prevent it open the app in new incognito window.
- Micro:Bit v1 has very little RAM memory, most of which is used by the Bluetooth protocol. Keep your code as simple as possible to avoid memory errors displayed on the Micro:Bit screen.
Saving models links
If you want to use your model multiple times and do not want to paste model link each time you open the app you can pass it as a page address parameter, for example:
Link to TM model: https://teachablemachine.withgoogle.com/models/Jgyr546VH/
Take the last part Jgyr546VH
and add it to the microbit app address like that:
https://cardboard.lofirobot.com/teachable-microbit/?model=Jgyr546VH
This way the model will load automatically after opening the app and you can access the model simply by storing this link.
Supported platforms
- Desktop web browser – Chrome, Edge, Opera
- Android
- ChromeOS
- iPhone or iPad – via Bluefy web browser
Project Ideas
- Color Ball Sorter
A robot that sorts balls based on color. - Gesture-Controlled Rover
A robot car controlled using hand gestures. - Smart Trash Bin
A bin that detects plastic and paper using a camera. - Smart Gate
A gate that opens only for specific cars. - Basic Line Follower Robot
Note: This project is tricky because Teachable Machine performs image classification, which is suitable for distinguishing objects like apples and bananas but not for detecting line positions on a screen. For this, you would typically use linear regression. However, you can create a “proof of concept” line tracker using Teachable Machine.