For more information, also visit the Reddit thread for this project (Q&A in the comments)!
A sorting machine that is able to sort candy by colour has been on my to-do list for multiple years. I finally managed to complete it after working on it for several months in my free time. It uses an Arduino controller, stepper motors, an RGB colour sensor and 3D-printed parts to sort several types of candy by their respective colours.
Special thanks to the creator of this YouTube video. Their video was my inspiration to start this project!
The video below shows the machine in action:
The machine is able to sort M&M’s and Skittles by colour by performing optical measurements using the RGB sensor. It can be modified to sort any type of coloured object, as long as the individual pieces have a regular shape with even dimensions. It takes approximately 2-3 minutes to sort a 300 g bag of Skittles / M&M’s and 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 saw on YouTube, 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 I and added my own improvements.
I started working on this machine in May ’16 and only finished it in December. 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 scanner tube. The scanner consists of a small wheel with four slots which are 90 degrees apart. After a piece enters a slot, the wheel, which is powered by a stepper motor, rotates 90 degrees so a measurement can be performed. The RGB sensor takes three consecutive 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 is then repeated. 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, 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 version of the parts.
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. To provide an analogy of how I imagine the design: you should be able to sit around the machine like you would with a campfire.
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 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 evenly-spaced pillars. One pillar takes fourteen wooden pieces which are glued together.
The pillars are assembled by using threaded rod as a guide. Glue is applied between each layer. After the stack is done, the parts are pressed together using bolts. After drying, the pillars are sanded to smoothen them ahead of painting.
Besides the three small pillars, a holder for the lower stepper motor is glued to the base of the machine.
Before glueing, 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 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 whole scanning mechanism as well as all 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 determination process, while the other one does all 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 interconnected.
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 of which the signal goes high when the 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 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 the 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 switch between M&M’s and Skittles.
After connecting all wires, this is wat the wiring situation of the machine looks like. As can be seen, a buck converter was also introduced to reduce the 12V input voltage to 5V for the LED strips and the 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.