M&M Sorter is a LEGO Mindstorms EV3 Machine that operates four motors and one color sensor to sort by color a bag of M&M placed on a storage tray and move them using threads into sorted buckets so you can eat from your favorite color. Best thing since slice bread if you ask me!
Two EV3 sets and one NXT 2.0 later here it is my very first and truly LEGO Mindstorms Creation: The EV3 M&M Sorter.
This video shows how the machine works ( with real M&M )
Well, you have seen the machine working and now it is time for me to explain how it works and show you how to build it. To build this color sorting machine you will need 1 EV3 brick, four larger motors ( although you could still try to do something with just 3 Large motors and one medium motor ) and lots of brick parts.
The Design process
So, after a few failing attempts that I didn’t recorded I decided to design it before building, so here is the initial design.
There are three different parts on the machines.
To the top left you have the bucket where you place the color balls and a thread that takes balls from the bottom of it to the top of the bucket.
The challenge here is creating something that can take balls from the bucket one at a time and it doesn’t stop working until there are no balls on the bucket.
So to achieve this I added a few pairs of pegs to the thread so it can grab balls from the bottom of the bucket. Due to the way the thread moves, it will just allow a single ball most of times.
On the top of the bucket we have the color sensor that will tell what color each ball is.
It really looks like this step is a simple one but it isn’t. Or you correctly face the sensor to the balls and keep it at a good distance or it will read wrong colors. So the goal is to keep the sensor around 5mm away of the balls and 90º to the moving thread.
And finally on the right we have another thread that moves on a corridor with moving doors that will push ball into buckets.
I decided to create this using moving doors because it looks like the simplest approach. When the color sensor reads a color, it will turn a motor that moves the door around its axis about 60º, then we wait a bit and turn it back -60º.
As you see the design is slightly more complex than the sorter machine that I built. I decided to remove the second thread and just use gravity to do the work. I save one motor with this and so the design can be kept on a single EV3 unit.
Building: First approach
So I started building but as I have said, this is my first serious Mindstorms MOC, so as I wasn’t really sure it would work, I created a simpler version that just sorts two color.
The Bucket has slopped walls so the balls go to the bottom, and the thread using the pegs takes one at a time to the top. Then the ball is read by the Color sensor and falls into the sorting tray that it is inclined so the ball will roll till the lowest end. When a color is read one of the two Large motors would be operated and a one of the doors will move to drive the ball towards the bucket. If the ball isn’t one of the two sorted colors it will just exits the tray on its lowest end.
The Motors are placed over their side so the axle and the motor are as most aligned as possible. Unfortunately this configurations left room only for two motors but it works!
Watch it working.
Building: Final approach
So after I knew that it could be done ( by me ) I decided to rework the sorting part. If you see the video, you will see that the bucket isn’t working exactly as I was expecting but it has a decent fail rate. Sometimes no ball will be taken from the bucket and sometimes two balls will travel on the thread. I can live with that fail rate but definitively for my next sorting machine I will try something different on this part.
So I reworked the motors part to make room for another motor so it can sort four different colors. As you recall there was not physical room for another motor so I had to redesign it.
I decided to place motors over its base and just use three more flexible joints.
Also if you see the picture I run out of room for a third rotating door, so I had to build the final door in a different ( and maybe better ) way than the others.
This machine was a pleasure to code compared to my two last projects, the EV3 Pong or the Line Follower. The program is quite simple.
It just turns on the A motor and then wait for a color to be read from color sensor, then it just send a command to turn 60º to the corresponding motor, wait a bit and turns it back -60ª.
You can download the EV3 file here.
EV3 Source Code file
How it works
Let me explain you how it works using the final version. Don’t hesitate to ask if you have any doubt.
The thread works with a L motor attached to the side and geared down to move the thread slower but more powerful. Really, we don’t need speed for this task. With the configuration you are seeing and working at full speed you get quite close to the top performance possible.
In order to retrieve balls from the bucket the thread has pegs that “grabs” one ball from the bucket. The idea is that due the way it is built only one ball can be retrieved. It has been a bit surprising that when the bucket is full the thread can get two balls at a single time. Things you will see my friend Sancho! ( as Don Quijote once said ).
At first I built a not quite satisfactory way of detecting balls using a touch sensor until I realized I can still use the color sensor for that tasks. So the color sensor is in a wait block for a color to be detected and then it just do an set of tasks once the color is known.
I had many issues with the color sensor until I found this optimal location. If you don’t place it completely perpendicular to the thread it will get wrong readings and false positives that can really turn down the machine quite soon.
So in this position it has a 100% success on ball color reading as you can see on the videos. How it works? It just emit color light from a LED and then read the reflected light to guess the color and as it works a 1000 samples per second you can’t outperform it with the thread.
This part is closely related to the motors. The original idea was that at each side of the corridor there were buckets where balls were pushed. I had to give up on the both sides approach because I had to place the motors just below it and there was so little room…
If you see the door it is just three beams with a long axle on the middle. If you turn the axle to one side it will move the door to that side, pushing balls to that bucket and it you turn it to the other side, it would push balls to the bucket just in front. One motor two colors… but I said I just gave up on the idea.
So the door is moved just to one way and push the balls into the bucket. I added a small add-on so the door is always on the right position.
I placed the motors this way because I think they would perform best. I have done use of the flexible joints that are used in Unimog and 4×4 Crawler transmission to move the axles. I am still really bad at gearing with technic… but I am improving.
It is quite challenging to do it with gears because the ramp is inclined a bit and so it won’t work easily with gears.
Hope you like it. I certainly have enjoyed building it and solving problems that I have found on the way. If you have any questions drop me a line ( if you do in the following days chances are high that I haven’t take the machine apart yet.