Introduction: M&M's : Color Based Sorter Robot
Introduction:
The main purpose of the Mechatronics course is to develop the ability to make a synergy between different disciplines through the building of robots which could be used in a real and innovative field.
The goal of our project is to build a robot that sorts Peanut M&Ms based on their color and then sorts them into individual cups. The robot is fully automated and it is not affected by the irregular shape of the candy. In this project, we used and combined the fields of mechanics, electronics and programming, in order to obtain a new and innovative robot.
Since the most important aspect of the robot is to distinguish the different colors of M&Ms, the sorter machine is equiped with a color sensor and a mechanism to bring the candy to the sensor and then move it to the adequate container.
The different stages of the construction of this robot are described below.
Step 1: How Does It Work
The principle of the M&Ms sorting machine is as follows : we discharge m&ms into the funnel, so they fall one by one into a wheel-shaped system that is in continuous rotation. The wheel receives the M&Ms one by one and brings each M&M in front of a color sensor which detects its color. Then the wheel brings the M&M to its lowest point, where it is released into a tube, which is activated by a motor linked to the arduino and rotates according to the color of the M&M. The M&M will then be dropped into the appropriate cup.
Note that the M&Ms are blended in the funnel by a small metal bar that is attached to the moving wheel on one end and bent into an elbow shape and left free to move inside the funnel on the other end.
Step 2: Material Used
MECHANICAL PARTS:
3D printed parts:
o Funnel
o Wheel system composed of 2 complementary parts
o Attachements for the protoboard
o Support for the sensor composed of 2 complemetary parts·
o Tube support
o Bearing supports (one connected to the basefloor and one other connected to the tube support)
o Attachements for the servo motor
o Attachement of the stepper motor
Bought parts:
o Lego shaft (Axle piece from Lego Technic)
o Bendable bar of 2mm diameter
o 2 Bearings
o 6 Plastic cups
o Screws and nuts M2.5, 16mm length
o PVC tube of 32mm diameter
o Cable ties
o 5 elastic bands·
Laser cut parts:
o 3mm wooden plancks : 3 walls, 3 floors and 2 gears
ELECTRONIC PARTS:
o Stepper motor 28BYJ-48
o Servo motor MG995
o Battery 9V DC
o Pmod Color sensor
o DC-DC Step Down Voltage Converter
o ULN2003 Driver
o USB cable
o Protoboard
o Wires
o Power supply DC
Step 3: Mechanical Design
In order to accomplish the sorting process, the first step for the robot is to isolate the M&M's one by one so that the color sensor can detect the color of each candy. This is the "dispenser" part. After that, the robot needs a distribution mechanism to allocate each candy to the right Area. This is the "distribution" part.
As the robot uses gravity to drive the M&M's through the chain, it needs differents floors :
- The second floor, where all the M&M's are accumulated
- The first floor, where the dispenser part is built
- The basefloor, where de distribution mechanism takes place.
and the walls which hold everything together.
Except for the cable ties, all the pieces can be fully disassembled and reassembled. This is important if we have to change any pieces because an unexpected redesign would have to be done.
1. The second floor and its component
All the M&M's are placed in a funnel. It is 3D printed and its shape is such that candy can only fall from it one by one. The holding mechanism of the funel is simply 3 elastic bands and cable ties attached to the second floor as well as on the funnel.
2. The first floor and its component
The dispenser mechanism is alined with the botom's hole of the funnel and against it. This dispenser mechanism is composed of a rotative wheel and its chamber. The shape and the width of the wheel are calculated to take only one candy from the funnel while pushing the next one up thanks to the edge of the top of the chamber (it is done automatically during the movement of the wheel). The wheel rotates thanks to a stepper motor trough a molded shaft (lego). Notice that the shaft is not 3D printed because the fragile layer structure of a long 3D printed piece is not resistant to shear stress. In order to take the load of the wheel and its content, a bearing is embedded in the chamber and a printed part that fit the shape of the lego shaft is tight by the inner ring of the bearing. The transmission of the torque from the stepper to the shaft is done by a short 3D printed piece. The chamber has 2 holes with a maximum width of an M&M (~2.2 cm), one on the top and one on the bottom, and an additional hole for the the color detection by the color sensor (see pictures).
The stepper motor is maintained in the right position using a 3D printed piece attached to the first floor. The chamber is also screwed to the first floor.
Also a bar fixed on the wheel and passing through the hole of the funnel mixes the M&M's in the funnel in order to avoid to get them stuck in it. After many trials, we spotted that the torque of the stepper motor is not sufficient to free the candies when the bar is pushing on M&M's that are stuck in random ways. Also sometimes the bar is not sufficient to move M&M's (because not touching them). It may therefore be useful to reshape the edge of the bar or add an additional device to counter this problem.
The color sensor is placed next to the side of the wheel's chamber, in front of the side hole (see pictures) and held by 2 assembeled 3D printed pieces fixed to the floor (see pictures). We decided to maintain it in place using elastic bands rather than pasting it to the plastic piece, to be able to replace it easily in case of a sensor disfunction.
3. Base floor and its components
When the M&M is dropped from the first floor, a PVC tube guides it to the right color cup. The tube is carried by a cylinder cut and shaped in PVC to give it the right angle. The tube is attached to the cylinder with short screws in such a way that the attachments do not interfere with the fall of M&M's (see picture). The cylinder is screwed to a 3D printed piece, attached to a gear and to the component that clamps the external ring of a bearing (the inner part of the bearing tight a 3D printed piece embed in it and screwed to the base floor). The bearing takes the load of the tube and its rotation is made by means of a servo motor trough an other gear attached to the motor (see pictures).
The motor is attached to 3D printed pieces and those are screwed to the basefloor.
The 6 cups (for the 6 colors) are disposed on a 180° rotation angle around the center of rotation of the bearing. The square size of the floors are determined by the "cups" parameter: the cups must be large enough to receive an amount of more or less 20 m&m's. The larger the cups, the further from the center of rotation they should be placed.
4. Walls
The walls and floors are connected using special attachements composed of screws and notches. See pictures.
Step 4: Electronics
Arduino UNO board
Open-source hardware and software, informations are easy to access. The Arduino UNO is easily accessible. Due to its open-source trait, it is also easy and cheap to program or solve problems linked to the code. This Arduino UNO board is compatible with all the components we used and has an enough number of I/O pins needed by the M&Ms sorting machine.
Servo Motor MG995
Servomotor MG995 was chosen to :
- Transmit motion to the gears.
- Retrieve 6 precise positions in function of the 6 available colors of the M&Ms candies.
The limitation between 0 and 180 degrees was not a drawback for us because we do not need the servomotor to turn 360°. We managed our system to fit within the 180° limitation.
Stepper Motor 28byj48
The stepper was chosen because we wanted an “infinite” rotation movement in the same direction of rotation, so the rotation wheel could turn indefinitely without stopping and stepping back for the collection of new M&Ms.
The speed is easily controlled with the stepper Driver (we need to have a constant low rotation speed to allow the color sensor to read the color of the M&Ms candy properly).
We do not need to know or attain precise position as we want a “continous” movement (even though it is in fact, step by step) in the same direction.
ULN2003 Driver
The Stepper driver is used to link the stepper motor to the Arduino in order to be a intermediary and allow the Arduino to control the stepper indirectly.
The chosen driver was specifically adapted to our 28byj48 stepper motor.
Digilent Pmod color sensor
The Digilent Pmod color sensor was chosen because it can sense red, green, blue and clear light. The on-board AMS's TCS3472 integrates an IR blocking filter to accurately determine the color of objects as well as sense ambient light under varying lighting conditions and through attenuating materials. It also has a white LED light to help illuminate the color of our M&Ms. This color sensor was also compatible with the Arduino UNO and the wires were easy to connect.
Protoboard
The protoboard was used to distribute the alimentation to all the single components of our system.
DSN2596 Step-down module
It was used as a resistive divider. It plays the role of transformer, cutting down the 5V of the power supply to 3,3V required by the color sensor.
9V battery
A 9V battery was chosen to power the Arduino by its 7-12V input thanks to the safety of the constant voltage delivery.
Power supply
The power supply was chosen because it was able to feed the 2 motors (servomotor and stepper motor) and the color sensor at the same time.
Step 5: Connections Scheme
All the electronic components, except the Arduino Uno board and the color sensor, are supplied with 5V by the power supply via the protoboard. The color sensor requires a 3.3V supply, it is necessary to go through a DC/DC stepdown voltage converter. Regarding the Arduino board, it is powered directly via a 9V battery.
Step 6: Programming
This section focuses on the programming part of our color based sorting machine.
Four main stages make up the program:
- · Initialization and verification
- · Rotation of the sorting wheel
- · Recording and analysis of the sensor data
- · Rotation of the tube
Initialization and verification:
During this first step, all the variables and parameters necessary for the smooth running of the program are created and adjusted. A check is then done on the correct connection of the color sensor. If it is not found, the execution of the program stops here.
Rotation of the sorting wheel:
The stepper motor is then asked to perform 50 steps in order to rotate the sorting wheel
Recording and analysis of the sensor data:
At the same time as the wheel rotates, the color sensor collects data. The data consists of a component for red, a component for blue, a component for green and a component for the "clear". To allow color identification, 3 ratios are used:
- clear component / red component ratio
- clear component / green component ratio
- clear component / blue component ratio
Then, it only remains to determine experimentally the values of the different ratios corresponding to each color.
Rotation of the tube:
The last phase consists in assigning a precise position for each colour. Once a color is detected, the servo motor will rotate the tube by a corresponding number of degrees. A final rotation of the step motor will allow the M&M's to fall into the tube.
Most of the libraries used are available on the Arduino application. Only the color sensor requires a library and specialized functions supplied by the manufacturer. A large part of the program used to control the sensor is based on these provided functions.
Attachments
Step 7: Improvements and Limitations
Improvements :
Our robot worked well but we believe it could still be improved. Here are some suggestions to improve our robot:
- Using a more powerful stepper motor for sorting wheel: during our testing we found that our stepper motor driver 28BYJ-48 didn’t provide enough power which may make sorting efficiency a little low.
- Funnel: The design of our funnel is not perfect yet, the M&M’s are often stuck in the funnel, so we think we can design a more efficient solution, for example by adding a stirring device.
- Speed: There is still room for improvement in the speed of sorting, we could make the wheel move quicker by using a more suitable motor or improving our programming.
Limitations:
- Currently, our robot can only sort Peanut M&Ms, so if we want to sort another kind of candy, we would need to create and place a new sorting wheel.
- The collecting cups are limited in size, so large quantities of M&Ms cannot be sorted.


