Raspberry Pi LEGO sorter

Raspberry Pi is at the heart of this AI–powered, automated sorting machine that is capable of recognising and sorting any LEGO brick.

And its maker Daniel West believes it to be the first of its kind in the world!

Best ever

This mega-machine was two years in the making and is a LEGO creation itself, built from over 10,000 LEGO bricks.

A beast of 10,000 bricks

It can sort any LEGO brick you place in its input bucket into one of 18 output buckets, at the rate of one brick every two seconds.

While Daniel was inspired by previous LEGO sorters, his creation is a huge step up from them: it can recognise absolutely every LEGO brick ever created, even bricks it has never seen before. Hence the ‘universal’ in the name ‘universal LEGO sorting machine’.


There we are, tucked away, just doing our job


The artificial intelligence algorithm behind the LEGO sorting is a convolutional neural network, the go-to for image classification.

What makes Daniel’s project a ‘world first’ is that he trained his classifier using 3D model images of LEGO bricks, which is how the machine can classify absolutely any LEGO brick it’s faced with, even if it has never seen it in real life before.

We LOVE a thorough project video, and we love TWO of them even more

Daniel has made a whole extra video (above) explaining how the AI in this project works. He shouts out all the open source software he used to run the Raspberry Pi Camera Module and access 3D training images etc. at this point in the video.

LEGO brick separation

The vibration plate in action, feeding single parts into the scanner

Daniel needed the input bucket to carefully pick out a single LEGO brick from the mass he chucks in at once.

This is achieved with a primary and secondary belt slowly pushing parts onto a vibration plate. The vibration plate uses a super fast LEGO motor to shake the bricks around so they aren’t sitting on top of each other when they reach the scanner.

Scanning and sorting

A side view of the LEFO sorting machine showing a large white chute built from LEGO bricks
The underside of the beast

A Raspberry Pi Camera Module captures video of each brick, which Raspberry Pi 3 Model B+ then processes and wirelessly sends to a more powerful computer able to run the neural network that classifies the parts.

The classification decision is then sent back to the sorting machine so it can spit the brick, using a series of servo-controlled gates, into the right output bucket.

Extra-credit homework

A front view of the LEGO sorter with the sorting boxes visible underneath
In all its bricky beauty, with the 18 output buckets visible at the bottom

Daniel is such a boss maker that he wrote not one, but two further reading articles for those of you who want to deep-dive into this mega LEGO creation:


Niels avatar

This is SO IMPRESSIVE. It looks like a lifetime project, but the maker isn’t that old yet and has finished it already!

Stefan Misch avatar

I wonder if I can borrow this machine for a few days. ?

Timothy J avatar

Can I borrow it after you do?

Langerosso avatar

This is just amazing. Cool project.

Justin Simms avatar

Jacques Mattheij built something like this four years ago:


P avatar

Which is also mentioned a few seconds into the video.

foo avatar


I wonder if would be possible to create a “LEGO sorter Zero”, to classify images without human supervision, just watching different images of the bricks.

Baraka avatar

What about a machine to get the pieces of a desired set from the available stock? :)

James Carroll avatar

Such wonderful engineering.

Will avatar

Great project! Any idea what the chances are of it making a mistake?

Timothy J avatar

Would really like to see this go to market… Even if it isn’t made of Lego to keep the cost down.

Strony WWW Kłodzko avatar

Awesome! I also use LEGO with my Arduino but RPi is more advanced!

Sam Muncy avatar

You area genius. The Lego company should create your machine as a Lego model and pay you a gazillion dollars! I am going to watch for your beast model.

Harry avatar

Daniel West, take a bow. This is such a great idea and is beautifully made! Genius.

Max avatar

Does this work with raspberry pi 0 w? I really want this but I don’t have that lego/money/more money – it’s absolute genius!

Comments are closed