How did we make an M&M sorting machine using TCS-230?

Ram Kartikeya
11 min readFeb 11, 2022

The sorting of products is one of the most tedious tasks in industries. Implementing colour sorting machines in the Industries will save lots of time and will help with sorting things faster with some tradeoff of human involvement. In thi aricle we have described a working prototype designed for the automatic colour sorting of GEMS based on their colour. This project was designed to sort the GEMS chocolate, but the same application can be used in the Medical Industries, Food Industries, Cloth Industries.

The Identification of the colour was based on the frequency analysis by using the colour detection sensor. We have also used two belts each controlled by the actuators. The first belt is for placing the product that is to be analysed. The second belt is for moving the container which has separate compartments in order to separate the products. The prototype was made to fulfil the needs of the large sector productions and quality in the automation field.

Ideology

The sensor will detect the colour of gem and generate output. The output sensor data is then transferred to Arduino and the Arduino will then process the data according to the code that has been uploaded and command the actuator to act accordingly and sort the candy based on their colour.

Components Used

We have used the following components in the Colour sensing prototype

  1. Arduino UNO (Gateway).
  2. Colour sensor- TCS230.
  3. Actuators- Servo motor.
  4. Wood(Prototype set-up.
  5. Colour candy- Gems or a Pack of M&Ms.
  6. Bread Board.
  7. Barrel Jack.
  8. PC/Laptop (obvio).
  9. Jumper Wires

The below is the description of how each component works.

TCS230 COLOR SENSOR: It has an 8 x 8 array of photo diodes. This senses the color light then using current to frequency converter the readings from the diode will be converted to square waves whose frequency will be directly proportional to the intensity of light. Lastly, using the Arduino UNO board the output of the square wave is read and the resulting color is given.

Picture 2.1 Colour sorting sensor- TCS230

Picture 2.2 the conversion of sensor reading in form of square form

These photodiodes consist of three different colour filters in them with the help of these filters it detects the colour of the objects/items. Sixteen of these have red filters, 16 have green filters, 16 have blue filters and the remaining 16 are with no filter. Each set of 16 photodiodes are connected in parallel, so they can be selected using the control pins S2 and S3. The modes of the pins can be adjusted according to the requirement from the given table.

Table 2.1 control working of pins S2 and S3

The sensor has two more control pins which are used for the frequency scaling of the output frequency. The range of the frequency values are 100%, 20%, 2% and power down. The modes for the following are mentioned in the table below.

Table 2.2 control working of pins S1 and S2

Arduino UNO Board: This is a microcontroller board which is open sourced, it is equipped with input/output pins which are both digital and analog used to interface various expansion boards and other circuits.

Picture 2.3 Arduino Uno Board

Pins on the Board:

The Arduino has several different kinds of pins, each used for different functions.

  1. GND : Short for ‘Ground’.
  2. 5V & 3.3V: As you might guess, the 5V pin allows 5 volts of power supply, and the 3.3V pin allows 3.3 volts of power.
  3. Analog: The area of pins under the Analog In label (A0 through A5 on the UNO) are Analog In pins. These pins can read the signal connected to analog sensor and help to convert them into digital values.
  4. Digital: Across from the analog pins are the digital pins (0 through 13 on the UNO). These pins can be used for both digital input output.
  5. PWM (8): there are some digital pins (3, 5, 6, 9, 10, and 11 on the UNO) with the tilde (~) next to them. These pins act as normal digital pins and can also be used for Pulse-Width Modulation (PWM).
  6. AREF (9): Stands for Analog Reference. It is used to set an external reference voltage as the upper limit for the analog input pins.

Power LED Indicator is on right of the word UNO on circuit board, there is a LED next to the word ON. This LED should light up whenever Arduino is plugged into a power source. There are two places on the Arduino UNO where TX and RX appear — once by digital pins 0 and 1, and a second time next to TX and RX are indicated by these LEDs. These LEDs will give us visual indications whenever our Arduino is receiving or transmitting data

The Arduino has a reset button. Pushing it will temporarily connect these reset pins and to ground and restart code that is to be loaded on the Arduino Board. Main IC acts the brains of Arduino.

Power (USB/ Barrel Jack): The Arduino UNO can be powered from a USB cable coming from a computer or a wall power supply that is terminated in a barrel jack.

Servo Motors: A servo motor is a closed loop that uses position feedback to control its motion and final position. This works as a closed loop. In our project we have used a hobby servo. There are four main components in this, namely a DC motor, a gearbox, a potentiometer and a control circuit. The DC motor used is of high speed and low torque. The gearbox reduces the speed to an appropriate amount and increases the torque according to the requirement. The potentiometer is attached on the last gear or the output shaft, so as the motor rotates, thus producing a voltage that is related to the absolute angle of the output shaft.

Picture 2.4 Servomotor

Here, the dark colour cable is used for ground connection. The red/middle cable is used to connect the voltage/power supply. The orange/light colour cable is used for the control pin. This servo motor can rotate up to a maximum of 180 degrees.

Jumper wires: These cables are used to connect the Arduino with the sensor and the servomotors. In our project we use different types of cables like male-male, female-female and male-female as per the requirement.

Picture 2.5 Jumper wires

DESIGN

The design of the prototype was first drawn in the 3D software and then the model was made. The design has 3 horizontal shelves each for holding TCS230 and servo motors. The top od the model is covered to achieve precision in the frequency reading taken by the sensor. The below attached is the blue print of each wood piece used in the prototype. The measurement in the picture have been multiped twice and manufactured the prototype.

Picture 3.1 Blueprint of the prototype.

TECHONOGIES USED

For the communication between the Sensors and Servo motors we have used the SPI- Serial Peripheral Interface protocol. Here the sensors and the actuators are connected in series manually using the bread board. We used Jumper wired to connect the sensor, and actuators with the Gateway. The below is the circuit picture of the connection.

Picture 4.1 Circuit diagram connected using Arduino board, servo motors and actuators.

We didn’t use Wi-Fi or and other wireless communication because we don’t need to send data to a large distance, the data only needs to be sent to the actuators so that they will act according by sorting the GEMS.

The point to multi-point technology is used over here

LITERATURE ANALYSIS

For this project we have reviewed 3 research papers before planning the algorithm for this project. The first paper was about the basic colour sorting machine by (Banik, 2014) the paper was written 2014. It describes the automatic sorting machine describes was a basic model with few precision errors. In this paper the identical shapes and sizes were sorted out. Although there is nothing much related to our project, it gave us an idea about how to implement the working model. In the model described in the paper there were no sensors used. A LED and photo resistors arrangement are used in horizontal direction. There was a vertical conveyor which brinks piece to the horizontal detector. We have taken the idea of loading the candy onto the disk vertically and horizontally moving it for the sensing its colour.

The second paper was about the Automatic colour sorting by Sahna S, Gokul M. S in which is the new generation sorting machine which sorts the objects based on their colours without continuous manual sorting by humans. The Identification of the colour was based on the frequency analysis by using the colour detection sensor. We have also used two belts each controlled by the actuators. The first belt is for placing the product that is to be analysed. The second belt is for moving the container which has separate compartments in order to separate the products. The prototype was made to fulfil the needs of the large sector productions and quality in the automation field.

The third paper which we used for the reference was written by Design and Development of a colour sorting machine using PLC and SCADA by Shashidhar. Sorting can be done in many ways based on the Dimension, Colours, weights using machine vision. This model is proposed to be used in the Thermal power plants using electromagnetic sorting technique. In this model also the main conveyor has two branches one for loading and other for sorting the items on the conveyor belt. This project was more of environment friendlyto establish a communication between man and machines.

CODE

#include <Servo.h> //Arduino board to control servo motors

#define S0 2 //Declaring all the pins of the Sensors and porting it with Arduino Board

#define S1 3 //Declaring all the pins of the Sensors and porting it with Arduino Board

#define S2 4 //Declaring all the pins of the Sensors and porting it with Arduino Board

#define S3 5 //Declaring all the pins of the Sensors and porting it with Arduino Board

#define sensorOut 6 //Declaring the output pin which is connect to the output pin of the sensor

Servo topServo; // declaring two servo motors as topServo and bottomServo

Servo bottomServo;

int frequency = 0;

int color=0;

void setup() {

pinMode(S0, OUTPUT);

pinMode(S1, OUTPUT);

pinMode(S2, OUTPUT);

pinMode(S3, OUTPUT);

pinMode(sensorOut, INPUT); //taking input after the colour is detected by the color sensor.

digitalWrite(S0, HIGH);

digitalWrite(S1, LOW);

topServo.attach(7); //Connecting the servomotor with Arduino pins.

bottomServo.attach(8);

Serial.begin(9600);

}

void loop() {

topServo.write(124);

delay(4000);

for(int i = 124; i > 74; i — ) {

topServo.write(i);

delay(2);

}

delay(1500);

color = readColor();

delay(10);

switch (color) {

case 1:

bottomServo.write(50);//pink

break;

case 2:

bottomServo.write(75);//yellow

break;

case 3:

bottomServo.write(100);

break;

case 4:

bottomServo.write(100);//green

break;

case 5:

bottomServo.write(150);

break;

case 6:

bottomServo.write(125);//blue

break;

case 0:

Serial.print(“ NO COLOUR”);

break;

}

delay(300);

for(int i = 74; i > 31; i — ) {

topServo.write(i);

delay(2);

}

delay(3000);

for(int i = 31; i < 124; i++) {

topServo.write(i);

delay(2);

}

color=0;

}

int readColor() {

// Setting red filtered photodiodes to be read

digitalWrite(S2, LOW);

digitalWrite(S3, LOW);

frequency = pulseIn(sensorOut, LOW);

int R = frequency;

Serial.print(“R= “);//printing name

Serial.print(frequency);//printing RED color frequency

Serial.print(“ “);

delay(50);

// Setting Green filtered photodiodes to be read

digitalWrite(S2, HIGH);

digitalWrite(S3, HIGH);

// Reading the output frequency

frequency = pulseIn(sensorOut, LOW);

int G = frequency;

// Printing the value on the serial monitor

Serial.print(“G= “);//printing name

Serial.print(frequency);//printing RED color frequency

Serial.print(“ “);

delay(50);

// Setting Blue filtered photodiodes to be read

digitalWrite(S2, LOW);

digitalWrite(S3, HIGH);

// Reading the output frequency

frequency = pulseIn(sensorOut, LOW);

int B = frequency;

// Printing the value on the serial monitor

Serial.print(“B= “);//printing name

Serial.print(frequency);//printing RED color frequency

Serial.println(“ “);

delay(50);

/* if(R<45 & R>32 & G<65 & G>55){

color = 1; // Red

}

if(G<590 & G>43 & B<47 &B>35){

color = 2; // Orange

}

else if(R<900 & R>870 & G<560 & G>430){

color = 3; // Green

}

if(R<730 & R>530 & G<540 & G>400){

Serial.print(“YELLOW”);

bottomServo.write(110);

return 4; // Yellow

Serial.print(“YELLOW”);

}

else if(R<56 & R>46 & G<65 & G>55){

color = 5; // Brown

}

else if (G<58 & G>45 & B<40 &B>26){

color = 6;

}// Blue bottomServo.write(75);*/

if(R<45 & R>32 & G<65 & G>55){

color = 1; Serial.print(“RED”); // Red

}

/* if(G<55 & G>43 & B<47 &B>35){

color = 2; Serial.print(“ORANGE”); // Orange

}*/

else if(R<43 & R>40 & G<46 & G>43){

color = 0; Serial.print(“ NO COLOUR”); // Green

}

else if(R❤8 & R>24 & G<44 & G>30){

color = 4; // Yellow

if(R❤3)

{

color =1;

if(G>35){

if(B>29)

{

color=5;

Serial.print(“ORANGE “);

return 5;

}

Serial.print(“PINK “);

return 1; //pink

}

else

{

color=2;

Serial.print(“YELLOW “);

return 2;

}

}

Serial.print(“GREEN”);

// YELLOW 1ST

}

else if(R<56 & R>46 & G<65 & G>55){

color = 5;

Serial.print(“BROWN”);// Brown

}

else if (G<45 & G>35 & B❤3 &B>23){

color = 6;

Serial.print(“BLUE “);// Blue

}

return color;

}

Picture 5.1 Neat Labelled diagram of the model

ALGORITHM

A simple Brute Force Algorithm was used to design this project. The project algorithm was self-designed, modulated and modified according to the calibration changes from the present existing code. The time complexity of the algorithm is O(n*m)

Start

cfirst(P)

while c ≠ Λ

do if valid(P,c)

then output(P, c)

cnext(P,c)

end

FUTURE SCOPE

In the existing model we can add the Load measuring sensor to sense the weight along with the colour of the sensor. So, the pills(tablets) can be sorted with the weight and colour. The load sensor was not added into it because the load sensor which measures weight less than 5 grams had a different working model to be made.

Adding the load sensor will enable us to sort the pills which has a great add-on to the medical industry.

CONCLUSION

The colour sorting sensor will enhance the workload and reduced the strain on the humans. This is a great application, if which introduced this in many industries, we can achieve a less human more automated work. Despite of the employment issue, the sorting machine reduces the workload on the people.

REFERENCES

--

--

Ram Kartikeya
0 Followers

Namaste! I’m a computer science engineer and a graphic designer hobbyist. Welcome to my medium. Know me more @www.ramkartikeya.com