Benjamin M. Holden

Writing › AI at home

Post · November 2026

Teaching AI to Find LEGO Pieces So My Son Could Build

My son opened every bag of a 500-piece LEGO set and mixed the pieces together. I used AI and a few free tools to build a phone guide that finds the bricks for each step.

A toy figure staring in panic at a table covered in loose bricks
Cover image edited with AI (Google Gemini).

My son got a LEGO set with over 500 pieces that was rated for older kids. We talked about it before he opened it, and he decided he didn't want to build it from the instructions. He just wanted the pieces and to have fun.

So he opened every bag and mixed everything together.

Then he looked at the pieces, saw how cool they were, saw the picture on the box, and changed his mind. Now he really wanted to build it. And he was upset, because the pieces were everywhere and he had no idea where to begin.

My plan, and why the instructions didn't help

My first idea was simple: spread everything out on the coffee table so every piece is easy to see, then use the instructions to put the LEGO bricks with the correct steps.

Not having built many LEGO in my life, I did not know the instructions don't work that way. The back of the book has an index with every brick's long ID number and how many are in the set. But the instruction steps just show a picture of the bricks they need. Without looking at each instruction step page there was no real way to sort the 500 bricks.

"Could Claude just look at the table?"

From my previous doorbell project I remembered that Claude can look at pictures and find objects. Maybe it could find the bricks for each step and circle them.

I took a photo of the whole table, a couple of close-ups and a couple of photos of the instruction pages, and just asked Claude. With almost no instructions, just looking, it did surprisingly well. It missed a couple of bricks and got a couple wrong, but it was useful, and it showed us a way to work with everything mixed up.

Claude's first try: the bricks for one step, circled on a photo of the table
Claude's first try: the bricks for one step, circled on a photo of the table

That night we did a few steps and a small GUI page to make it easy to view on the phone: the step from the book, with each brick circled on a photo of the table. Then my son went to bed. I stayed up and kept going.

What it turned into

xkcd 974: The General Problem
xkcd 974, “The General Problem” by Randall Munroe.

By the end it was a small website on my phone that walks through every page of the book:

Find the table. A free image-processing tool, OpenCV, finds the tabletop in an overhead photo by its wood color and straightens it, so everything else lines up. Users can also manually crop the corners.

Find the table: the tabletop found in the overhead photo, corners marked
Find the table: the tabletop found in the overhead photo, corners marked

Find every piece. OpenCV also outlines every piece on the table in a couple of seconds.

Find every piece: everything OpenCV outlined, straightened to the table
Find every piece: everything OpenCV outlined, straightened to the table

Name every piece. Each piece is cropped and sent to Brickognize, a free website that identifies a LEGO part from a photo. I expect it to charge someday, since every picture costs them computing time, so the reusable version is designed to fall back to Claude alone, which is still pretty good.

Name every piece: Brickognize names each close-up crop, with how sure it is
Name every piece: Brickognize names each close-up crop, with how sure it is

Match it to the set. The names are checked against the parts list in the back of the book, so the site knows which bricks belong to the set and how many of each it has found.

Match it to the set: green is in the set, amber unsure, red not part of this set or no answer
Match it to the set: green is in the set, amber unsure, red not part of this set or no answer

Then the guide itself:

Swipe to flip through 5 screens

Tap a brick: how many the set has, how many were found, and where they are on the table.
Tap a brick: how many the set has, how many were found, and where they are on the table.
A page of the book, with each brick it needs labelled.
A page of the book, with each brick it needs labelled.
One step: each brick, its bag, and where it is on the table.
One step: each brick, its bag, and where it is on the table.
The inventory: every brick in the set, needed, found and used.
The inventory: every brick in the set, needed, found and used.
Setup: every piece found in the overhead photo, ringed on the table.
Setup: every piece found in the overhead photo, ringed on the table.
1 / 5

Where the AI was wrong, and how we caught it

Most of the evening was correcting things, and that's the part I'd want someone else to know before trying this.

I also looked at tools other people have built. Two open-source projects on GitHub detect LEGO bricks in photos: lego-detector expects the pieces on a lit white panel, and lego-identification only sorts by color and size. I also tried MobileSAM, a lighter version of Segment Anything, Meta's tool for outlining every object in a photo. It worked better, but it was too much compute and time for this use: a 5.6 GB install and about nine minutes per photo on my computer. The plain image-processing tool did the same table in under two seconds.

At one point I asked Claude, "Are we over engineering this?" We were writing more and more code to split apart the big white plates that sat touching in the glare. There were fewer than 20 of them. Claude picked them out by eye instead, and Brickognize confirmed each one.

This is how I generally work with AI. I use AI to build scripts that lean on local "free" tools to do the initial screening. Then I use AI on the back end to check the edge cases that a quick algorithm or small compute cannot handle.

Did he need it?

Honestly, no.

Turns out humans are much better at object detection than computers. After the night before showed him how to find the pieces, he went right to work. He probably asked for help a handful of times. Most of the time he found the pieces himself, and when he got stuck, what he needed was me looking over his shoulder for a minute. The website was gold-plated and over-engineered.

But it was a fun project, and the starfighter got built.

Try it

Here is a working copy of the guide, built around a made-up rover drawn by code instead of a real set. Tap through it: tick bricks as you find them, open the inventory, and finish a page to hear the fanfare. To build one for your own set, the code is on GitHub.


LEGO® is a trademark of the LEGO Group, which does not sponsor, authorize or endorse this site. Brick identification by Brickognize; part pictures in the screenshots from Rebrickable. Comic by Randall Munroe, xkcd.com, used under CC BY-NC 2.5.

Get new posts by email or RSS

More to read

Benjamin M. Holden

Ben Holden is an environmental engineer. Outside work he does home automation, AI projects and a lot of do-it-yourself projects. God, family and his kids are at the center of all of it. More about me · LinkedIn

Subscribe