A LEGO Robot That Sorts Bricks from Minifigs
Train a phone to tell a LEGO brick from a minifigure, then let one motor point at the answer. This is a pointer, not a machine that drops bricks into bins.
At a glance
The title says “sorts.” The lesson we are following points. A phone decides “brick” or “minifigure.” A motor turns to show which one it picked. If you want bins, a ramp, and color sorting, that is the 2020 science-fair project, and it uses Arduino, not these steps. Doing both in one afternoon is how instructions get invented. This page does one of them.
Tools (and their age limits)
| Tool | What it’s for here | Account age / who logs in | Free? |
|---|---|---|---|
| LEGO SPIKE | One hub that can run the lesson. Other Pybricks hubs work too. You need one motor on port A and a beam so you can see it point. | No child account required by the lesson. You handle the hub. | The lesson does not name a price. Use a set you already have if you can. |
| Teachable Machine | Image model, two classes | You run it. The homepage does not state an age. It offers an on-device option so camera data need not leave the computer. The Pybricks steps upload the model to get a share code, which is not the on-device path. | No price on the homepage we read. |
| Pybricks | Connects the phone’s classification to the motor | You follow the lesson, including its earlier “smart sensors” page, which this one says to read first. We did not re-check that intro page’s account rules. | Not stated on the classification page. |
Who does what
Kid does
- Sorts a pile into “brick” and “minifigure” with their eyes, before the computer does
- Chooses different bricks and different minifigs so the photos are not all one red 2x4
- Holds a piece in front of the phone at test time
- Says whether the motor pointed the right way
Parent does
- Reads the Pybricks smart-sensor intro, then this lesson
- Takes or supervises the photos, with faces out of frame
- Trains, exports, and copies the model code without a trailing slash
- Connects the motor and runs the program
Materials
- LEGO bricks and minifigures you are willing to photograph
- A phone with a camera. The lesson says to train with the same camera you will use later.
- A computer for Teachable Machine
- A Pybricks hub, a motor on port A, and a beam. SPIKE Prime is named as one option. The full robot in the photos is optional.
Steps
- Parent Read the smart-sensor intro the lesson points to, so the phone can talk to the hub. We are not repeating clicks we did not re-open.
- Kid Make two piles and look at them. The computer will only learn the difference you photograph.
- Together Take a lot of photos with the phone you will use on the robot. The lesson’s set was 26 brick photos and 45 minifigure photos. Change the background. Include some shots with a hand and some without. Skip any shot with a face.
- Parent In Teachable Machine, image project, name the two classes, upload the photos, and train. Export, leave the defaults, and upload the model until you get a share link.
- Parent Copy the model code without the trailing slash. The lesson’s example code is
0zj3KVdmj. That is their model, not yours. Use the code from your own upload. - Parent Run the lesson’s program with your code. Category 0 is the brick in their example and category 1 is the minifigure. The motor goes to 0 degrees or to 180. If your class order is swapped, the pointer will be swapped. Fix the order rather than trusting the number.
- Kid Test pieces the model has not already seen, and pieces it has. Watch the confidence if the program shows it. The lesson says confidence runs from 0 to 100. Their sample program uses only the category, not the confidence.
- Together When it is wrong, add photos of that kind of piece and train again.
Copy-paste prompts
Photo plan for bricks and minifigs
Before you open the camera
I'm a parent training a Teachable Machine image model to tell LEGO bricks from LEGO minifigures, then pointing a single motor at the result, as in the Pybricks classification lesson. My child is [AGE]. Please give us a photo checklist: two classes only, several photos of each, different backgrounds, some photos with a hand in frame and some without, taken with the same phone we will use later. Tell us to keep faces out of the photos. Do not add a third class. Do not invent a price or a part number.What you’ll end up with
A motor that points to one side or the other. Not two bins. The science-fair machine, the Bichromatic Brick Sorter, did use containers, a ramp, and color. It is linked above so you can read it. It is not this build.
Safety box
- Age guidance: you are there for 10–12. Small LEGO pieces are a choking hazard for little kids. This page is not for ages 3–5. Safety & Ages hub
- No faces in the training photos. Hands are optional, and the lesson asks for both.
- Uploading the model creates a share link. Do not put a child’s name in the class names or the file names.
- Motors move. Keep fingers off the beam when the program runs.
- Do not buy a kit from a price we invented. Neither source lists one.
- Their example model code is an example. Training on your own photos is the project. Using only their code teaches their objects, not yours.
Age adaptations
| Age | How it works | Tips |
|---|---|---|
| 10–12 | They sort and pose the pieces. You handle export and the hub. | Start with very different objects, a brick and a minifig, before you try two similar bricks. |
| 13+ | They can run the train and export while you watch for faces and for the trailing slash. | Ask what would happen if every photo had the same table. Then change the background. |
Variations & next projects
- Confidence: the lesson explains the second number. Their sample ignores it. A later edit could refuse to point when confidence is low. Do that only after the basic pointer works, and only if you can read the program in front of you.
- Color bins are the Society for Science project. Read that page before you start cutting cardboard. We are not writing those steps from a summary.
- No hub: you can still train the image model and test it in Teachable Machine. The motor is the part that needs the hardware.
Source & inspiration
The steps follow the Pybricks lesson: a phone runs a Teachable Machine image model, the program receives a category number and a confidence from 0 to 100, and a motor on port A points one way for a brick and the other way for a minifigure. The lesson's example model used 26 brick photos and 45 minifigure photos, with different backgrounds and some photos that include hands. It says you do not have to build the whole robot, and that SPIKE Prime can be the hub. The Society for Science story is a different machine: two middle schoolers, a ramp, a laptop camera, two bins, Arduino, and red versus green bricks, based on Teachable Machine's Tiny Sorter. We do not mix that hardware into these steps. Prices are not in either source.
Inspired by:
- Pybricks, “Classification with machine learning”
- Society for Science, “Two middle schoolers use AI to sort LEGO” (November 6, 2020)
Facts checked against:
More in this neighborhood
One project in your inbox every week. No fluff.
TODO: connect a weekly-project email service. This form is a placeholder. It does not send or store your address. No third-party signup is wired up.