Close
0%
0%

Colour sorting machine for Lego

Automatically sort random Lego pieces by colour!

Public Chat
Similar projects worth following
This promises to be my toughest project yet - a machine for automatically sorting Legos by colour: - random sizes and shapes - fast (at least one piece per second average) - compact (some other machines take up the whole room!) - no cameras, Raspberry Pi's or AI here! Just good, old-fashioned low-tech goodness. - minimalist design: as few moving parts as possible - low budget (something anyone can build at home)

The machine has eight basic functions:

  1. a hopper and chute to accept bulk Lego pieces of approximately the correct maximum size
  2. a drum feeder to extract a few pieces at a time for onward processing
  3. a vibratory feeder to help separate pieces from each other
  4. a 'slippery slope' feeder to encourage the pieces to stop tumbling and instead slide at a constant rate and constant orientation past the sensors 
  5. a 'light gate' sensor to detect the presence of an approaching piece
  6. a colour sensor (and light source) to measure the colour of a piece
  7. a microprocessor to perform a colour classification function, plus control the motors etc.
  8. a rotary diverter to guide the piece into the correct output bin

A key function of the machine, and something which is critically important to reliable sorting, is to tease apart pieces from each other, and separate them sufficiently that they can be diverted into different bins if necessary. Otherwise two or more might end up (incorrectly) in the same bin. This separation function is performed in three ways:

  • The drum feeder only scoops a few pieces in each bucket, and the bucket is curved so that pieces are released slowly, not all at once. The drum feeder sets the overall processing rate too.
  • As the pieces drop onto the vibratory feeder, partly helped by a sloping ramp, they are scattered along its length somewhat.
  • The vibratory feeder is designed to vibrate with an amplitude sufficient to make the pieces 'dance' about, not just move them along. Also it vibrates only a little at the uphill end, and much more at the lower end, so that pieces further along therefore tend to 'dance' more and accelerate towards the sensor, spreading them apart as they go.

The RGB value from the colour sensor is matched to one of 30 or so distinct Lego brick colours (determined by measuring a reference set of bricks). Each matched colour has an output bin number associated with it, so that e.g. all the different greens go in the 'GREEN' bin.

Finally, the diverter is designed to be short and have very low mass (low inertia). It limits the overall machine throughput because it determines a) how long a piece takes to transit between sensor and output bin, and b) how quickly it can move around to the next bin if required.

vee_channel_vibrator_mount_large_v2.stl

larger mount to take a 280 motor

Standard Tesselated Geometry - 104.96 kB - 07/06/2025 at 13:40

Download

controller_case-Rear.stl

Case (rear) for the screen

Standard Tesselated Geometry - 727.43 kB - 07/06/2025 at 13:39

Download

controller_case-Front.stl

Case (front) for the screen

Standard Tesselated Geometry - 765.32 kB - 07/06/2025 at 13:39

Download

drum_feeder_scoop_v3.stl

latest (smaller) scoop design

Standard Tesselated Geometry - 4.57 kB - 07/06/2025 at 13:38

Download

PDQ_ILI9341_config.h

header file to accompany Lego_display.ino

h - 2.40 kB - 07/06/2025 at 13:38

Download

View all 20 files

  • 1 × NEMA 17 stepper motor model 17HS3404-Z
  • 1 × A4988 stepper driver module
  • 1 × TCS34725 colour sensor module
  • 1 × Arduino Nano or compatible clone
  • 1 × small dc motor (e.g. "280" size) for vibe feeder

View all 14 components

  • RGB vs HSL vs HSI

    RobG13 hours ago 0 comments

    I got a bit sidetracked.

    The new vibe feeder is under way, but stalled waiting for parts to arrive from the east.

    In the meantime I've added a window over the colour sensor and, as predicted, the sensing got messed up and the machine wouldn't sort properly any more. So that prompted a whole bunch of work looking at the RGB sensor again:

    - a proper calibration routine to scale the sensor outputs so that they are better matched and less affected by changes in ambient lighting.

    - a dive into alternative colour spaces, such as HSV, HSI and HSL which, at least to my eye, seem to make the sample data easier to classify: white, grey and black have low saturation and can be distinguished by their brightness, and the other colours can mostly be classified by ranges of hue. I was able very quickly to put together a decision-tree classifier in HSL-space which, on a sample set of 2700+ bricks, achieves about 90% accuracy. Most of the remaining errors come down to the big variations in lighting each brick receives while it tumbles past the sensor. If I could slow them down and stop them tumbling, that should improve.

    - a bit of research into other classifiers, such as k-NN and SVM, which might do better, but I'm not sure I can justify the effort just yet.

    Right now the machine works really well. I can leave it pretty much unattended and it...well...sorts bricks!

  • A new vibe feeder

    RobG11/14/2025 at 15:27 0 comments

    I'm going to run this part as a separate mini-project I think, until it's working, and then integrate it back into the rest of the machine.

    The idea is twofold:

    1. Make a short section of Vee channel which works much more like a traditional vibratory feeder than the current 'jiggler'. By that, I mean the pieces are simply transported along, rather than subjected to significant upward impulses to try to get them to untangle and separate. That's such a useful function that I have to keep it, but this new feeder is in addition. Assuming high-frequency, small vibrations, it should be possible to transport them along a horizontal section of channel and, crucially, switching off the vibrations should cause them to stop dead in their tracks. This excellent article describes what I mean.
    2. Then, fit the end of the feeder with another light sensor to detect the precise moment a piece topples off the end. The vibrator can then be temporarily switched off - just a few 100 milliseconds - to give the piece a chance to get on its way past the colour sensor, before resuming the flow.

    I'm hoping this stop-start mechanism will enlarge the spacing between the pieces enough for them to be dealt with individually. Thanks to this recent HAD article, I've now learnt there's a word for this: "singulator". Nice.

    So I've bought a small solenoid (the sort that is used as a simple out-in piston actuator) and I'm going to attempt driving it at a few 10's of Hz or more using PWM to see if it will work as a vibrator/driver.

    Watch this space!

  • And there's more...

    RobG11/14/2025 at 15:17 0 comments

    OMG this is the project that just won't die...

    I had the machine out again the other day and tried to use it to actually sort some Lego for once (rather than as a cute demo for some school kids). It still has niggly problems that I want to fix:

    • the colour sensor is currently 'open air' - there's no window - so all kinds of fluff and dust, not to mention actual Lego, gets stuck in it.
    • pieces, of all sizes, still come through in two's and three's all too often, degrading the sorting accuracy somewhat
    • the very smallest pieces often don't slide all the way past the colour sensor; the gradient of that part of the Vee channel isn't steep enough and with so little momentum they stop until a bigger piece hits them from behind and nudges them along.

    So, I've been thinking. Add a window over the colour sensor, and deal with whatever fallout comes from that. Shorten and steepen the final stage chute so that small pieces don't get stuck. And in the middle, maybe add a second vibratory feeder - with a twist. More on that in the next logs.

    To date, I've modified the sensor to add a window made from a thin, curved piece of clear acrylic. It seems to be very good at keeping debris and Lego out of the sensor, but it's knocked the colour-classifier out of whack. Presumably everything now has a slight tint or something, which will need re-calibrating out.

  • Latest video

    RobG07/06/2025 at 13:33 0 comments

  • More updates and improvements

    RobG07/06/2025 at 13:27 0 comments

    The drum scoops are redesigned to be smaller so that fewer pieces are dropped each time. Also I've gone back to six scoops instead of twelve, which leaves gaps between the scoops which is useful when there are only a few bricks left in the drum. 

    Here are just a few of the scoop designs I've tried along the way: 

    Also, after much coding, a bit of soldering, and the design and print of a case, the TOUCH CONTROLLER! 

  • Updates!

    RobG06/07/2025 at 17:26 0 comments

    So it's been a while since the last log, and the machine has had many outings to school STEM events and the like. It has mostly worked really well, and got lots of interest and sparked lots of discussion - which was the whole point.

    However, I've had some ideas for improvements. Some of those were implemented today:

    - swapped out the vibrator motor for a larger one (a "280") since the original one got pretty warm and wore out too fast.

    - added control of the stepper driver's nENABLE pin so that the stepper current can be switched off between moves to save power and stop it getting too hot. I think the shaft was previously getting so hot the 3D-printed PLA part attached to it actually melted slightly.

    - added serial commands to start/stop the machine, adjust motor speeds, and read out a count of bricks in each bin.

    The last item is there so that in the near future I can put together a touch-screen controller with a real-time display of brick counts, plus the option to tweak the speeds, stop it if there's a problem, etc. Watch this space...

  • Ready for first demos

    RobG06/16/2024 at 06:14 0 comments

    A bit more tidying up, addition of a hopper and chute to load Legos into the drum, some fine tuning of the angles and software and it's done!

    It's not perfect but it is really fun to watch. The main remaining issue is that the scoops inside the drum sometimes pick up quite a few pieces, which then overwhelm the vibe feeder and they end up tailgating each other past the sensor. Something to tweak later. I'd also like to add a touchscreen with start/stop buttons and some readouts of brick counts, speeds, etc. Other ideas in the comments please! 

  • It's alive!

    RobG05/23/2024 at 06:10 0 comments

    First time putting together all the parts:

  • Coming together now

    RobG05/20/2024 at 07:17 0 comments

    I've chopped up something like 2.5metres of 2020 aluminium extrusion and turned it into a more permanent, more rigid frame for the drum feeder, vibration feeder and sensor head:

    The drum is belt driven from a DC motor/reducer gearbox running at about 200rpm. I needn't have worried about the belt wandering off the drum - it's absolutely fine, without any need for additional guides or track to keep it centred. 

    Everything's adjustable - angles, clearances, etc. - so the next steps are to do some tuning to get it feeding reliably and quickly, before finally integrating it with the diverter and output bins.

  • Drum feeder (2)

    RobG05/13/2024 at 08:08 0 comments

    The drum feeder is looking good now. After a bit of trial and error making paddles/scoops from card I've committed to a 3D printed design that works well enough for a first attempt. Physically positioning all the various parts was getting really tricky using the wooden lash-up so have also started the 'finished' build in 2020 profile and M5 fittings.

    I think I'll try a belt-drive to power it, from a DC motor and reducing gearbox. Only problem with a belt is that the drum has a slight draft to the sides, meaning that the belt will undoubtedly tend to wander off...

View all 22 project logs

Enjoy this project?

Share

Discussions

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates