Some people really like eating specific M&M colors… You could spend hours sorting your packs of M&M’s into color specific piles, or you could build a machine to do it for you.
That’s exactly what [ReviewMyLife] decided to do, and it’s quite impressive! He’s using a rotating hopper to release M&M’s into a chute one-by-one, and then an iPhone to perform color recognition as the M&M falls past it. That information is then communicated over Bluetooth to the Arduino which actuates a high-speed electromagnetic gate to force the M&M down the right chute for sorting.
The machine works surprisingly well for a prototype that was hot glued together out of foam board, but fear not, he plans to upgrade it now that the proof of concept has been confirmed. He’s hoping to get rid of the iPhone and replace it with a Raspberry Pi for starters, 3D print some of the parts, and consolidate its power supply. Currently he’s using three separate supplies to power the Arduino, electromagnets, and the hopper motor — not very efficient!
Also it’s not very good at sorting brown M&M’s. They look too much like a cross between orange and a shadow on the iPhone. He thinks a bit of work on the image recognition software and maybe some LED lights to help the camera might do the trick.
We’ve seen some systems done like this before, including one that can sort tiny little beads! OCD readers eat your hearts out!
I wish I had the time and skill to waste my life doing pointless but interesting little inventions like this. 2 kids kinda takes the wind/energy out of my sails …. On a daily basis. They’re worth it though and seeing these things o. hackaday gives you a little faith in the future of humanity.
I don’t even have kids yet and there still isn’t time left on the day. Note to college kids, do more projects and watch less tv. You may never have that much free time again.
Never have this much free time? I must be doing it wrong.
Agreed. I’m on an mechatronics course. What is this “free time” people speak of, and where can this mythical thing be found?
I study automatics and I like to waste the little free time I have on fisting and stretching *that* muscle.
Oddly enough last night I was thinking that a modified M&M sorter is what I’d need to sort ABS bottlecaps for making reprap filament….
Where do you get ABS bottle caps? I thought they were all made of PP.
Cool project… but the upgrade will add pi because?
It’s like if you have an Arduino or a Pi in it hackaday will probably cover it, but if you arbitrarily stuff both in there they have to cover it…
Haven’t I seen an arduino use a camera before? I would swear I have even seen color detection done before. Why can’t it do the whole thing? Why do you need bluetooth? Why do you need a Pi?
What’s next an electron probing microscope connected to a super computer by way of satellites?
Don’t mean to be a party pooper, I just would find it much more interesting to revise by using less or incorporate more features.
Best case scenario 20MHz of a “slow” Atmel chip that Arduino uses with 640*480=307200 pixels to clock out gives you one frame every 15ms on a very good day, add to that some processing (on the fly as the Arduino does not have enough memory to store this data) and you’re at about 1-5seconds/frame. I’m impressed by the speed of the processing here, unless the RPi does processing at a really low level it won’t reach the same speeds (source: I’ve worked on RPi and done image processing on it). An Arduino and RPi really complete each other, one does high level processing the other takes care on I/O and you can make anything happen on budget.
In fact, you don’t need to scan for 640×480 pixels. When sensing single-colored object, single pixel sensing (probably something like this http://www.ams.com/eng/Products/Light-Sensors/Color-Sensor) is good enough.
Around 1998 or 1999 I saw high-school project – color playing balls sorting machine, based on old intel 8051 (much slower than AVR in Arduino) and three photodiodes, each equipped with red, green and blue filters.
What jaromirs said basically. I am aware this is fast, and that the arduino can’t handle high resolution images quickly(at all) but you need a small amount of pixels.
My whole point really is that with this simple feature set, a Pi is a huge waste. Add features or use hardware within range of actual needs. I am not advocating using a 555 timer, but an Pi is beyond overkill.
If you use that hardware why not analyze the shape, do quality control inspection, analyze if the logo is visible, or something else interesting. If you use a Pi why do you need an arduino still?
My colleague (ReviewMyLife) made this out of a series of conversations we had at work. We’ve all seen M&M sorters before but the speed of existing designs have been somewhat lacklustre. There’s definitely room for improvement on this design but it’s probably the fastest project online. The gate array can be further compacted by a circular ‘flower’ arrangement with the gates pushing their respective chutes into the centre on close. That’ll also give each gate the same time to react to the color recognition instruction from the iPhone as the the fall distance is the same.
Just to re-iterate, this prototype does indeed use an arduino, iPhone and bluetooth but that’s not the end design. ReviewMyLife wants to reduce this down to just a Pi and a camera but wanted a proof of concept for the hopper and gate array first… give him time to reduce it down whilst improving the real innovative parts of this design.
Looking forward to the next prototype mate!
My colleague (ReviewMyLife) made this out of a series of conversations we had at work. We’ve all seen M&M sorters before but the speed of existing designs have been somewhat lacklustre. There’s definitely room for improvement on this design but it’s probably the fastest project online. The gate array can be further compacted by a circular ‘flower’ arrangement with the gates pushing their respective chutes into the centre on close. That’ll also give each gate the same time to react to the color recognition instruction from the iPhone as the the fall distance is the same.
Just to re-iterate, this prototype does indeed use an arduino, iPhone and bluetooth module but that’s not the end design. ReviewMyLife wants to reduce this down to just a Pi and a camera but wanted a proof of concept for the hopper and gate array first… give him time to reduce it down whilst improving the real innovative parts of this design. As discussed, it might not be possible to replace the iPhone with a Pi and camera due to color recognition speeds, but maybe an android alternative might be a welcome addition.
Looking forward to the next prototype mate!
I did something like this with my students: https://www.youtube.com/watch?v=o7nQGBxo6sQ
The most challenging part was ensuring that you only get one M&M. Also we used the ones with the peanut in it, which made it extra hard.. But you don’t need an iPhone for that. We just used an Arduino with some colored LEDs and photo transistors.
This can turn useful for those interested in working with Van Halen :)
http://www.snopes.com/music/artists/vanhalen.asp
Would build one to reject red and blue. If only there was a way to add tan M&M to get a bowl of classic colors.
Red M&M’s *are* part of the classic color mix. You must not have been around for the Red Scare of the 70’s — red dye #2, that is.
http://www.livescience.com/33017-why-were-red-mms-discontinued-for-a-decade.html
Well, didn’t know that. I was born early ’70s and I can only remember M&M not having red until mid 80’s Still, give me tan color. It’s the only way to get “Cinamon” flavored candy ;)
http://www.snopes.com/food/ingredient/bugjuice.asp
Claim: The red food colorants cochineal and carmine are made from ground bugs.
TRUE
real life bettlejuice indeed!?
Is there a way to sort out the terrible cheap ass grainy chocolate too? Tried M&M’s for the first time a couple of months back, never again.
I think one’s choice of candy coated chocolate depends on what one had when they were a kid. A couple years ago, I tried the candy coated chocolate called “Smarties” in most countries, and didn’t like it. (The two, while sharing a common description, are totally different)
They use a system for sifting cranberries where they fall past a color detector and air jets shoot the bad ones into the reject bucket.
Eat way to do this without the fast reflex processing would be to embed color sensors into a cog that accepts one at a time and can turn to dump it left or right.
Take a simple photodiode and an RGB LED. While the RGB is normally switched all colors on. you can detect when the M&M is in front of the photodiode. Now switch all three colors seperately fast. and you can detect the color. No need for such an overpowered iphone killer. And no need for a shitduino btw.
Here’s a bit more explanation on some of the decisions:
I did first try a basic colour sensor attached directly to the Arduino. But those simple colour sensors are really slow and need calibration (this at least applies to the ones that are cheap and are available for the Arduino – I’m sure a factory quality one may be better!).
Single pixel analysis would only work if the M&M was static and held in front of the sensor (these sensors are too slow to detect an M&M in free fall – never mind spot its colour). These sensors spray out a continuous signal – so you can’t just read ‘the colour’. You have to sample the individual values you are getting back from it for long enough to get a stable reading. And that’s just for one colour sensor (the green for example). You then have to do the same for the red, blue and white sensors.
I wanted to spot the M&M and detect its colour whilst it was falling so I needed something faster.
From looking at a single pixel you can’t even be sure of the colour. M&Ms aren’t flat objects – they are curved and so have a range of colours around them. You can’t tell for certain if you are looking at a light part of the red, or a darker part of an orange M&M, or maybe a lighter part of the brown for example. The colours of each M&M aren’t unique – the colour ranges overlap. You need to be able to sample a larger part of the M&M to get a better chance of figuring out the colour.
This is also why the camera is placed a bit back from the chute – to give it a wider field of view so that it can find the M&M which is falling somewhere in front of it. To guarantee that you could spot it from close up you’d need a faster camera.
To improve the speed the software doesn’t analyse the whole camera image – for performance reasons it analyses a vertical strip about 20 pixels wide. I was using the high speed 120 FPS iPhone 5S camera to give me the best chance of spotting the M&M.
I’ve measured the muzzle velocity of bullets with 2 photodiodes. So you can’t tell me that they are too slow… The thing what is slow is your arduino…
I think the Arduino colour sensor is quite slow as well – I guess it is made for the Arduino! So slow + slow = even slower :)
With the right kit and software some amazing sorting is possible. This industrial pea sorter is pretty awesome – it blows defective peas out of the air! https://www.youtube.com/watch?v=DogZJmThRSE
Likely that color sensor connects to the Arduino via I2C. That protocol is convenient for attaching multiple peripherals using a single set of shared pins, which helps keep wiring simple; but for that convenience, speed is sacrificed. A sensor that produces native analog outputs will be a *lot* faster.
An example of modifying your setup to use such a color sensor:
1) Create a narrower section of the chute where the M&M will be roughly centered.
2) At the measurement point, shine a IR LED through a hole in the left side of the chute. Mount a phototransistor in a hole in the right side. When the M&M breaks the beam, it’s time to read the color sensor. (Bonus points if you detect this using an interrupt, so you don’t have to continuously poll in a loop.)
3) Mount the color sensor and a white LED on the front window of the measurement point. The white LED could be on all the time, or just when a measurement is taken.
Also a tip for the software side. You’re probably trying to detect color by comparing the RGB values against minimum and maximum thresholds, like this:
If R>192 and G<64 and B<64 Then MMColor=Red
(and so on for other colors)
And as you've found, it's hard to come up with a set of thresholds that accurately detect color when the M&M may be tilted. It can be very helpful to first convert RGB to another color system, like HSL (Hue, Saturation, Luminance). This is easier to compare because Hue represents the basic color all by itself. Saturation represents how vivid the color is – most will be high, but brown in particular will be low. And Luminance represents the brightness or amount of shadowing caused by M&M tilt, which can probably be ignored completely. Try taking a photo of some M&Ms, and in a photo editing program (Photoshop, GIMP, etc.) examine some pixel values in HSL. You'll quicky see how Hue is more predictable for a particular color of M&M, regardless of shadowing or where on the M&M you pull the pixel from.
But can it sort between Skittles, Reese’s Pieces, and M&Ms?
http://imgur.com/kXfGutB
I don’t know who you are or where you got that from but that is freaking hilarious. +10000 for putting me in tears and almost drowning while drinking my soda.
M&M do not taste sufficiently different because of their shell. Now sorting liquorice is an more interesting engineering challenge because of the shapes and mechanical side of handling it. They do taste very differently.
I believe the important question here that nobody’s asking is, does this work with peanut M&M’s?