Tutorial: BRICK SORT3R

BRICK SORT3R can sort LEGO bricks by color and size.
Figure 1: BRICK SORT3R can sort LEGO bricks by color and size.

Always wanted to sort your LEGO bricks automatically? Now you can build a robot to do it for you! BRICK SORT3R can sort LEGO bricks by color and size. This page provides building and programming instructions to build BRICK SORT3R with your EV3 set.

The sorting mechanism is obscured by the white decoration panels. Can you figure out how the robot is able to detect the color and size of a LEGO brick before you build it using the instructions below? Watch the video of the robot in action to get a better idea of what it does and how it works.

1. Requirements

  • One LEGO MINDSTORMS EV3 set (#31313) to build BRICK SORT3R.
  • Some LEGO bricks to sort:
    • Red, yellow, green and blue bricks are preferred.
    • Use 2×4 bricks and 2×2 bricks.
    • After you’ve run the example program, you can modify the program to detect other colors and brick sizes.
  • Optional:
    • A set of small buckets or bowls to sort the LEGO bricks in.
    • You can modify the program to match the size of the buckets or bowls you use (see Discovery #133)
    • You can also build buckets with your own LEGO elements, as shown in the video.
    • If you do not have any buckets to use, you can simply have the robot drop the bricks on the floor, as shown on the picture above.

2. Building BRICK SORT3R

  • To begin, select the required pieces from your EV3 set, as shown below.
Select these parts to build BRICK SORT3R
Figure 2: Select these parts to build BRICK SORT3R
  • Click the image below to start building BRICK SORT3R, or download the PDF here.
BRICK-SORTER-Build
Figure 3: Click to view the building instructions

3. Programming BRICK SORT3R

  • Download the EV3 project file by clicking here. Save the file to your computer and unpack the Zip archive.
  • Download the BRICK SORT3R program to your robot.
  • You can explore how the program works by reading the comments placed throughout the program.
program
Figure 4: Program overview

4. Running the program

  • Place some bricks in the chute, as shown in Figure 5.
  • Place the “reference” tower opposite to the bucket with big blue bricks, as shown in Figure 5. This gives the robot a fixed reference, so it knows where to find each bucket of LEGO bricks.
  • Place the robot between the buckets of LEGO bricks and the reference tower, as shown in Figure 5.
  • Start the program.
  • The robot will first drive away from the reference, and then drive towards it until the Infrared Sensor detects the reference.
  • The robot begins to sort bricks.
  • After sorting five bricks, the robot will reset itself by returning to the reference, before continuing to sort more bricks.
Position the BRICK SORT3R and the reference as shown.
Figure 5: Position the BRICK SORT3R and the reference as shown.

5. Further Exploration

Congratulations, you’ve finished your brick sorting machine! Are you curious to discover more about the design of this robot? Get started by trying some of the Discovery challenges below.

 Discovery #133: Different Bins!

You may be using differently sized sorter buckets than the custom built ones in the video. To ensure that your robot works properly, you’ll have to adjust the program accordingly. In the video, the robot must rotate the Medium Motor by 387 degrees to move the robot from one bucket to the next. You can measure the required amount of degrees with Port View (see Figure 6-4 on page 66) and turning the wheels manually. Once you’ve found the proper value for your setup, adjust your program with this value. To accomplish this, double click on the CalcPosition My Block to open it. You’ll find the 387 degrees value in the most right Math block. Increase or decrease this value as necessary.

Discovery #134: More Colors!

The example program can only sort red, yellow, green and blue bricks, but the Color Sensor can also detect black, white, and brown bricks. Can you expand the program to allow the robot to sort bricks with these colors as well?

Discovery #135: More Sizes!

The example program only distinguishes two sizes of bricks (2×4 and 2×2). Can you expand the program to allow the robot to sort more sizes? To test the program, add 2×3 and 2×6 bricks to your selection of bricks.

Discovery #136: Empty Chute!

The example program does not take any action if the robot runs out of bricks to sort. Can you expand the program to allow the robot to detect an empty chute? When the chute is empty, the robot should stop sorting and play an error sound.

Design Discovery #31: Rotational Sorting!

The current design places bricks in different buckets by driving to the left and right. Can you design a turn table base with one Medium motor for the BRICK SORT3R? This lets the robot drop bricks in different buckets placed around it. This would be a more efficient design for a factory, because it takes up less space. Hint: Use the turntable you designed in Design Discovery #18.

52 Responses
  1. John Pugh

    Just built the Brick Sorter, it’s quite brilliant! I use my EV3 kit with my two grandsons and they love it though they are slightly too young to program it yet. I have had my EV3 Home kit and Expansion Pack for a couple of weeks only so I am also quite new to it all. Your own Discovery Book is excellent and should be on everyone’s shelf. I have both the printed and Kindle versions of the book. I fully intend to crack your extra “discoveries” for the Brick Sorter but are the answers hidden anywhere on your website should I fail?
    The first design I built from the book was the Robot on the front cover, this went down very well with my grandsons especially as I had added some speech sounds using the Sound Editor to enable the Robot to call them by their names. The latter impressed all who heard it! Keep up the good work Lauren’s and thank you for all your efforts.

    1. Hi John,

      Thanks a lot for your response. I’m glad to hear you and your grandsons are having fun with the projects from the book.

      I didn’t prepare the solutions to these final Discoveries yet, but I may do so at a later time. (Feel free to use thise space to ask here for tips when you’re ready to tackle them though!)

      If you’re interested, it would be great if you shared your experiences with the book in a review on Amazon. I’ve found that reviews help other MINDSTORMS builders decide which books to get, since there are quite a few MINDSTORMS books out there.

      Thanks,

      Laurens

  2. Robin

    Hi Laurens.
    I have bought your book for my ev3 education version.
    I’m very interesting on your brick sort program.
    Is that available for education version for building? I find some pieces is not in education set.

    Thanks for your reply

    Robin

    1. Hi Robin,

      You will need some additional pieces to build it with the Education edition, or you’ll need to modify the design to account for pieces you do not have.

      To see which pieces you’ll need, compare the parts list in the Brick Sorter page above, and this parts list of the Education set (LINK).

  3. Casey Liew

    Re: Discovery #134: More Colors

    Hi Laurens.

    I got more colors of Lego Bricks so can I scan more bricks?

    Thank you for responses and reply.

    Casey Liew

  4. Arthur

    Very useful robot….Good job!

    But I think it would be more efficent if the robot sorts bricks around hin. That will cost less time. I have build it on a fixed position and changed some parts in the program Now he is sorting bricks in a circle around him.

  5. Noah Bargallo

    Hi, I love your idea, but the bricks really get out of place without the container you have in your video! Can you add instructions for your piece holder as shown in your video! It will really help! Thanks, Noah.

    1. Laurens

      You can increase it to reset only every 10 blocks, or even 20. You need to reset occasionally because when the wheels slip slightly, it has no way of knowing where to put each brick.

    1. Laurens

      There are various ways to do this, and I encourage you to explore EV3 programming throughout the book and try again afterwards 🙂

    1. Laurens

      The instructions will remain the same. Without the bins, it will just drop them at a different spot on the floor.

      You can just put the cups underneath.

  6. Ulrike Günther

    Could you please give a hint for Discovery #136.

    My first though:
    Asking for the color black (the ground of the chute is visibly and therefore no brick is in the chute) does not work. Because than I can’t sort black bricks anymore and the color sensor interpreted this kind of black as blue sometimes.

    My second thought:
    Does it have to do with the rotation of motor C? When it is over e.g. 2500 than it is not an extra big brick but empty? But it doesn’t seem to work either.

    Any hints?

    Am I on the right way or totaly wrong?

    Thanks for an answer in advanced.

    Ulrike

  7. Frederik

    I have a problem. When the robot has scanned the brick and starts to move towards the right position, it doesn’t stop to eject the brick. It just continues to move in the same direction, and i need to stop the program to stop the robot. I have no idea, what i’m doing wrong, but i hope someone can help me..?
    Frederik

  8. Ciaron and Christopher

    Dear Laurens,

    We love your book. We use it every evening. We have one question. Our brick sorter doesn’t work. It only finds small blue bricks. Do you know how to fix that?

    From
    Ciaron age 9 and Christopher age 7

  9. Dominik

    Hi Laurens,

    has this been tested with the latest brick firmware (1.09)? We have built this, downloaded the programming and uploaded it to the robot, but the robot only stops, utters “green”, opens to release a brick but does not really transport a brick further down the chute.

    We are investigating if we built something wrong but wanted to rule out any programming issues first.

    Dominik

  10. LegoMaman

    @Ciaron and Christopher: The robot sees the light from the color sensor and recognizes it directly as a color (blue and green also sometimes). Since it is programmed to turn on the motor which moves the lego pieces downwards only until it recognizes a colour, this step will actually never happen (since it already recognizes a color even without any lego brick). Remove blue and green from the possible colors (white works fine instead) and give it a try again.

  11. The Super Silly Guys

    Shutting off my side and I am not going back home tomorrow morning and then we can get back home from the office and get some rest before the day I can get to you and then we will be back in a bit and I can get some rest and I can do some dinner tonight I haven’t talk yet I will call him later if I need anything else let you go get some lunch or tomorrow morning let you go and get it and I can

  12. The Super Silly Guys

    Shutting off my side and I am not going back home tomorrow morningchcixgkxgmzgmznfxngxxmghchvlhvkg oh him and then we can get back home from the office and get some rest before the day I can get to you and then we will be back in a bit and I can get some rest and I can do some dinner tonight I haven’t talk yet I will call him later if I need anything else let you go get some lunch or tomorrow morning let you go and get it and I can

  13. Hello to ev3 world

    How do I modify it to sort 1×1, 1×2, 1×3, 1×4, 1×6, 1×8 and all those other wonderful sizes(2×2, 2×3, 2×4, 2×6, 2×8, 2×10) in ONE(yes, one) brick sorter

  14. Hello to ev3 world

    How do I modify it to sort 1×1, 1×2, 1×3, 1×4, 1×6, 1×8 and all those other wonderful sizes(2×2, 2×3, 2×4, 2×6, 2×8, 2×10) in ONE(yes, one) brick sorter thank you very much and please reply HERE AND EMAIL

    1. Ethan Mitchell

      Hello to ev3 world* That is for you to figure out. Laurens is giving you a challenge, not all of the answers.
      You probably can’t sort the 1×2, 1×4, etc. with this design, but the others you might. Maybe adding a module using the touch sensor to determine the length…

  15. Paul Spenceley

    I have just made the brick sorter, and downloaded the program, but it keeps getting both the size and colour of bricks wrong 🙁 Sometimes it does not move bricks forward enough, and then it seems to ‘guess’ a colour. It is only getting about half of the bricks right. Any ideas what I may have done wrong, please?

Leave a Reply