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 (very) 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. Over the course of a few months, I went through several revisions before even ordering anything. Sometimes I’d run into a component sourcing problem, sometimes I figured out that a particular part would not work for some reason. After finishing the models, they were sent to a 3D printing company for production.
After receiving the printed parts, I assembled them and integrated them with some of the motors and electronics to perform tests. This resulted in a list of bugs and shortcomings 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 body. This allows a user or 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 are made of MDF wood, which is lasercut according to my 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, right on top of the center. 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. I was looking to get a very smooth surface finish so some sanding between layers was needed too.
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. This is necessary, because the control unit and motor drivers are all in the upper part of the machine.
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 (an adapter).
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 piece of large tubing is the upper frame part of the machine. As described before, it’s a piece of PVC. After sanding and degreasing it, 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 (“camel-shaped” pieces of wood) 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. I had not anticipated an interaction between these LEDs and the colour sensor, which is why I had to manually cut this ring from a piece of wood as I didn’t feel like placing another lasercutting order for this part only.
The brain of this machine consists of four individual boards – 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 using a base board that provides all the necessary interconnections.
As discussed earlier, the scanner / candy processing unit 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 reaches the microswitch roller, the software knows to stop rotating the wheel and starts 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 PVC ring and the middle plate, there is an 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. This toggle is necessary because the colours of both kinds of candy are slightly different. Therefore, different calibration profiles are required.
After connecting all wires, this is wat the wiring situation looks like. As is shown, a buck converter was also introduced to reduce the 12 V input voltage to 5 V for the LED strips, Arduinos and mixer servo. I have to admit that all of this looks slightly messy, but it is what it is, and most importantly, the machine works!
Finally, the top plate is put in place and it is secured by putting cap nuts on the threaded rods. The hopper/funnel is also added. The machine is now completely ready to sort M&M’s and Skittles!
This concludes the build log of my candy sorting machine. Thank you for reading this post! 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. Please do remember to check out the links at the top of this page if you are looking for design files.