M&Ms and Skittles sorting machine

For more information, also visit the Reddit thread for this project (Q&A in the comments).

This project, the M&Ms and Skittles sorting machine, was on my to-do list for a long time. I finally managed to complete the project after working on it for several months in my free time. The machine uses an Arduino microcontroller, stepper motors, an RGB colour sensor and 3D-printed parts to sort several types of candy by their respective colours. The video below shows the machine in action:

The machine sorts M&Ms and Skittles by colour by performing optical measurements using the colour sensor. It can be modified to sort any type of coloured object, as long as the individual pieces have a regular shape and similar dimensions. It takes approximately 2-3 minutes to sort a 300 g bag of Skittles / M&Ms and the mechanism sorts about 2 pieces per second. The machine is 250 mm in diameter and approximately 300 mm in height.

I decided to base my machine on a similar mechanism that I found on YouTube (lots of credit to them!), which uses a rotating wheel to scan the pieces of candy. After deciding on the details, I started designing the machine from scratch using CAD software and I implemented my own improvements in the process.

I started working on this machine in May 2016 and only finished it in December of that same year. It took a lot of time to design and build the machine, and I kept optimizing the parts and software after the first prototype was done. Including all prototypes and spare parts, I spent nearly €500 on this machine. Well worth it, considering everything I learned.

The sorting process

While in the hopper, candy pieces are constantly mixed to prevent clogging at the inlet of the upper feed tube. The scanner consists of a small wheel with four slots which are spaced 90 degrees from each other. After a piece enters a slot, the wheel, which is powered by a stepper motor, rotates 90 degrees. The RGB sensor then takes three measurements which take 30 milliseconds each. The Arduino controller then determines the item colour (based on reference data) and positions the exit tube (also using a stepper motor) to guide the piece to the correct container. Just before the exit tube reaches its target position, the wheel turns another 90 degrees to drop the piece. The process then repeats. During the process, visual feedback is provided using the LED strip that encircles the machine.

Designing and building the machine

After the concepting phase, every part of the machine was modelled using CAD software: Siemens NX10 in my case. After finishing the models, they were sent to a 3D printing company for production. Above, an exploded view of the machine is shown.

After receiving the printed parts, I assembled them and added the electronics to perform tests. This resulted in a list of bugs which had to be corrected for a second iteration. Some parts did not fit together properly because of tolerance issues. Also, candy would get stuck at the bottom of the hopper and in the exit tube for various reasons. All of that was fixed in the second design iteration.

The problem with the exit tube was easily fixed by increasing the slope of the tube. The clogging issue was much harder. After considering some different solutions, I eventually came up with a de-clogging device which uses a rotating hopper with indents in the side. This mixes the pieces and prevents them from getting stuck.

After finishing the 3D-printed parts, I was ready to start designing an enclosure for the machine. I decided the machine should have a cylindrical shape with regular features all around the outer shell. This allows a spectator to enjoy watching the machine at work from any angle.

Inspired by the Pibow case for the Raspberry Pi, I designed the enclosure to consist of a stack of seperate pieces with a fixed height of 9 mm. This applies to the whole body, except for the upper part, which is a large piece of PVC tubing. All layered pieces consist of MDF wood, which is lasercut according to digital drawings.

The two bottom layers serve as a base for the machine. The second layer has six slots for the bowls that’ll hold the sorted pieces. The small holes are for wiring and structural reinforcement purposes.

The top part of the machine rests on three periodically spaced pillars. One pillar consists of fourteen wooden pieces which are glued together.

The pillars are assembled using threaded rod as a guide. Glue is applied between each layer. After the stack is done, it is pressed together using threaded rod and bolts. After drying, the pillars are sanded to smoothen them ahead of a paint job.

Besides the three small pillars, a holder for the lower stepper motor is glued to the base of the machine.

Before gluing, the pillars are aligned with the middle plate of the machine by running threaded rods and pieces of copper tube through the holes shown before. The copper tubing is permanently glued in place, the threaded rod is not.

After the glue dries, the individual pieces of the machine are painted using a base layer and multiple layers of white spray paint.

The stepper motor for the exit tube is now ready to be mounted. Its wires are routed through the base of the machine and then go up again through one of the pillars.

The scanning mechanism as well as the LEDs are attached to the middle plate of the machine. In the image above, I’ve glued six WS2812B leds to the middle plate to shine down on the bowls that hold the candy. They are covered by a piece of opaque acrylic to diffuse the light. Later, an outwards-facing strip of LEDs will be glued to the wooden ring for additional lighting effects.

A barrel connector is attached to the base of the machine. Its wires are routed upwards through a pillar in the same way as the stepper wires. The machine takes 12V power from an external source.

The middle plate is only held in place by the threaded rod and copper guides. Glueing it in place would make it impossible to remove the exit tube and stepper motor from their mount.

This is the upper frame part of the machine. As described before, it’s a piece of PVC tubing. After sanding and degreasing, a base layer of paint is applied. After that dries, a few coats of white paint are applied such as was done with the other parts.

For each of the three threaded rods, two guides are glued to the inside of the PVC ring to keep it in place when the machine is assembled. The part is then stacked on the bottom part of the machine. In the image above, a plywood ring is also visible. This prevents light from the LED strip (which is directly below) from interfering with the colour measurements.

The brain of this machine consists of four PCBs – two Arduino Nanos and two EasyDrivers. One Arduino handles the scanning and colour recognition process, while the other one handles the animations for the LEDs. The EasyDrivers drive the stepper motors, since the Nano can’t do this by itself. The individual boards are plugged in using their pin headers which allows for easy replacements if one fails. It also greatly reduces the wiring mess, since each of the four boards are electrically connected.

As discussed earlier, the scanner has a rotating wheel with four slots. On the right side, a color scanner is mounted to measure color. The rotating wheel is powered by a stepper motor, but to be able to precisely position the wheel in front of the sensor, a microswitch is used which closes when a slot lines up with the sensor.

To achieve this, a small disc with four notches rotates in sync with the wheel. As soon as one of the notches in the disc hits the microswitch, the software knows to stop rotating the wheel and start the measurements.

The scanner part is mounted on the middle plate of the machine using four bolts. To reduce noise caused by vibrations, small pieces of vinyl are placed between the wood and the plastic.

The circular LED strip is glued to the middle plate of the machine. It has exactly 32 RGB leds. It will be used to show rainbow patterns when the machine is in stand-by, and it will display measured colour during the sorting process.

Between the upper frame part and the middle plate, there’s a opaque ring that diffuses the light from the LED strip behind it.

There are two pushbuttons on top of the machine with built-in LEDs. The left one is used to start and stop the sorting process whereas the right button is used to toggle between M&Ms and Skittles.

After connecting all wires, this is wat the wiring situation looks like. As is shown, a buck converter was also introduced to reduce the 12V input voltage to 5V for the LED strips, Arduinos and mixer servo.

Finally, the top plate is put in place and it is secured by putting cap nuts on the threaded rods. The funnel is also added. The machine is now ready to sort M&M’s and Skittles!

This concludes the build log of my sorting machine. Thanks for reading it!

If you have any suggestions, remarks, questions or anything else, feel free to contact me and I’ll get back to you as soon as possible.

This work is licensed under a Creative Commons Attribution-Noncommercial 4.0 International-license.

78 thoughts on “M&Ms and Skittles sorting machine”

  1. This is awesome! I’m not sure if you have ever heard of an online retail shops called ThinkGeek.com but you should pitch this idea to them. I would totally buy one of these, depending on price of course.

    1. I completely agree! A kit would be awesome!

      I can’t think of a better way to get kids into STEM projects. It would also be great if the micro controllers were not coded as an extra bonus to the project.

      Build and code! Excellent!


  2. I’d love some more details on how the sorting mechanism works at all. I didn’t quite get how the pieces are separated, why there was clogging and how the clogging was fixed. Maybe some closeup of the 3D printed pieces? Maybe even 3D Files? Thank you!

  3. Finally, the world no longer has to eat a mixed bag of Skittles without relying on a 4 year old to sort them for you. Now with wonder tech (and a very nicely designed and built machine) you can sort (although very very slowly) your bags of candy. Rejoice earthlings, life is once again worth living.

  4. Wow, very good one.
    Man, it was a pleasure reading your report, nicely done. Thanks for sharing 🙂

  5. That was so well done.I love it. I’ve done lots of projects with Arduinos, stepper motors and those same driver boards. Now that I have my own 3D printer at home, I’d love to be able to buy a copy of the plans and files so that i could build my own.

    1. Alexis, the Arduino code will be available shortly, as well as for my other projects. It will be published on Github.

  6. Nice!!! I Would be doing a similar project with restricted school budget soon. Your design has been a great inspiration.

    1. Please contact me through the contact form for now and I’ll arrange it. Haven’t had time to post it publicly yet, unfortunately.

  7. I would love to build one of these for my wife, would you be willing to share the code and STL files?


        1. It took me some time to get back to you, but yes, the files are now publicly available. Check my blog page for more information.

  8. Wow this is way cool! I’d buy one if you put them on the market, depending on price of course. I’m 69 years old and not a techy, so buying for me would be better than assembling. Congrats on a well thought out and designed machine!

  9. Any chance you would be willing to share the code and STL files. I am involved with a group that works with youth on STEM projects, and I think this would be very popular!

    Thank you!

  10. We are having trouble creating the pipe connected to the steppermotor. Could you upload the CAD files so we can 3D print this part?
    Thank you in advance!

  11. I build a exact copy of the machine, and wired it up like i can see in the code. But i dont work. The steppers dont turn like they are suppose to. I think i could be a problem with the wiring, because not all pins and connection are in the code

    1. The code controls the DIR (direction), EN (enable) and STEP pins on the driver boards to control the stepper motors. Did you check if those are properly wired?

  12. The rapid development of technology certainly makes us and everyone else have to continue to adapt in order to be able to follow an increasingly sophisticated and modern lifestyle.

    many things change in our daily lives because of technology and various tools created by various technology manufacturers. including the tools that you create will make a lot of changes and we hope to help many people improve the effectiveness and efficiency of work.

    From the tool that you made, I hope that you would like to tell how you made it to what it is today in order to inspire and motivate other people in making a sophisticated tool and helping many people

  13. bisakah alat ini dibuat menjadi aplikasi android yang mana bisa menyebutkan warna di saat kamera HP di arahkan ke benda atau objek yang sedang di selediki.

Leave a Reply

Your email address will not be published. Required fields are marked *