Automatic Lego Color Sorter

by Roan_Vandemeulebroucke in Living > Organizing

442 Views, 8 Favorites, 0 Comments

Automatic Lego Color Sorter

20240616_101245.jpg
Schermafbeelding 2024-06-12 153305.png

Tired of sorting LEGO on your own? Do you want it to be sorted for you?

Introducing the Smart LEGO Sorter, a machine that will sort Lego bricks by color to make building Lego sets easier for everyone, especially for colorblind people.

How does it work?

You put a brick at the beginning of the treadmill. That brick will move through the machine and pass a camera that will use AI to determine which color the brick is. Then it will travel further, and the flaps will sort the Lego bricks by color. For this mockup, it's sorted into two colors.

Supplies

For this instructable, you will need these things:

  • Laptop
  • Raspberry Pi 5
  • Freenove project kit for raspberry pi
  • 32gb micro sd
  • Webcam (Trust trino 720p)
  • cables
  • 1x Stepper motor
  • 2x servo motors
  • 3d prints (Files are attached with each step)
  • 4x metal pins(stiks) 3mm diameter
  • Black elastic synthetic fabric
  • 8x 8mm outerdiameter x 3 innner diameter x 4 mm bering

The price for these things is +- 220 euro. For more clearence see the pdf.

Print the Mainframe Parts

20240612_15072221-ezgif.com-video-to-gif-converter (2).gif

For this part, you will need to print some things.

You can choose the color you want.

I recommend using PLA for the 3D printer.

Gluing the Parts Together

20240605_154133.jpg

You will need to take every mainframe part and glue them together. I recommend doing it piece by piece.

Bottom Plates

20240612_173217.jpg

Print the bottom plates and glue them to the bottom of the mainframe.

Why?

I work with the bottom plates to give the frame more sturdiness so it will be a little bit stronger.

Print the Rolls and the Gear

20240612_162532.jpg
20240612_162715.jpg
20240612_173229.jpg

Here you need to print the rollers (3 times) and the gear for further construction.

I designed the gears to have a 1/3 gear ratio.


Why the 1/3 ratio?

The stepper motor has a lot of torque but not a lot of speed. I wanted to speed it up with the ratio.

Put the Bearing in the Rolls and the Treadmill Gear.

20240612_161250.jpg

I designed the prints so that the bearings will fit perfectly without any glue required.

I use the bearings so the roller has less friction to roll across the metal sticks, which in turn makes the machine run smoother.

Put the Stepper Motor in the Frame

20240612_161915.jpg

Put the stepper motor in its holder and thread the cables of the stepper motor through the small gap underneath the holder.

Running the cables through the gap will make it cleaner to look at.

Print Servo Stands

20240614_172625.jpg

Glue the servo stands like this and then glue the two servos on.

These are the little flaps that will sort the LEGO bricks after the AI detects the color

You can put the stick already on the servo's..

Fabrick Treadmill

20240614_211744.jpg

You need to stitch the black fabric together +-1meter

Rols on the Frame

20240615_195112.jpg
  1. You need to put your homemade treadmill band in the frame.
  2. Place the 3 rollers and the treadmill gear inside the rubber loop.
  3. Glue each roller into the pre-made notches.

Print the Camera Holder

20240612_164824.jpg

This is for the camera holder. You will see that I use clips; this makes the design process easier for me and makes it much easier to carry around because I can take the holder apart.

Put the Camera in the Holder

20240612_164950.jpg

Put Everything Together

20240616_101245.jpg

The four legs of the camera holdder should fit perfectly in (cameraholder mainframe) I also did it this way to make carring it around eazier.

Connect Everything

20240615_195638.jpg

Stepper Motor:

  • Just plug the connector into the connector of the Freenove kit.

Servo Motor:

  • Orange wire = Programming pin
  • Red wire = 5V
  • Brown wire = Ground
  • Make sure the servo closest to the camera holder is servo 1.

Servo 1:

  • Connect the red wire to a 5V pin and the brown wire to a GND. Connect the orange wire to GPIO16 (keypad). Note: I used extra cables to extend the servo pins.

Servo 2:

  • Connect the red wire to a 5V pin and the brown wire to a GND. Connect the orange wire to GPIO20 (keypad). Note: I used extra cables to extend the servo pins.

Computer Code

download.jpeg

This is a link to my github fot the code of the raspberry pi

Download the RPi folder and run the code app.py and ENIOY

https://github.com/howest-mct/2023-2024-projectone-ctai-VandemeulebrouckeRoan/tree/67695aa7c6d4f9d4f2211d8be84412e6e97e1b24/RPi

How Did I Make the Ai?

val_batch0_labels.jpg

Step 1.

Gather a large dataset of LEGO brick images (e.g., 300 pictures with an average of 11 bricks per photo).

Step 2.

Use Roboflow to annotate the images. Annotation involves drawing boxes around each object you want to track. For my project, I used 5 classes: Red, Orange, Blue, Green, and Yellow. I drew a box around each brick and labeled it with the appropriate class.

Step 3.

Export the annotated dataset once you’ve completed the annotations.

Step 4.

Use Python to train a model with the annotated dataset and evaluate its accuracy.

Step 5.

Once the model is trained, you can build a program around it. You can use ChatGPT to help modify the code if you need to sort different colors.