PET ENGINEERING COLLEGE
DEPARTEMENT OF ELECTRONICS AND
COMMUNICATION ENGINEERING
ET3491-EMBEDDED SYSTEM AND IOT DESIGN
PROJECT REPORT- COLOUR BASED PRODUCT
SORTING
LABORATORY
MINI PROJECT
SUBMITTED BY,
PET ENGINEERING COLLEGE
An ISO 9001:2008 Certified Institution
Approved by AICTE, Recognized by Government of Tamil Nadu and Affiliated to Anna University
BONAFIDE CERTIFICATE
Certified that this the bonafide record of work done by
Mr./Ms……
………………………………………………………………………………….of
the SIXTH Semester in Electronics and Communication Engineering of this
college in the ET3491 EMBEDDED SYSTEMS AND IOT DESIGN
LABORATORY during 2023-2024 in partial fulfillment of the requirements of the
B.E Degree Course of the ANNA UNIVERSITY.
Staff in-charge Head of the Department
University Examination held on ……………….
INTERNAL EXAMINER EXTERNAL EXAMINER
S.NO LIST OF CONTENTS PG.NO
1 ABSTRACT 1
2 INTRODUCTION
2. COLOR SORTING AND IDENTIFICATION
PIN DIAGRAM
3. METHEDOLOGY AND WORKING
TSC230 WORKING MODULE
TSC230 OPERATION
4. WORKING OF HARDWARE
PROGRAM CODE
5. RESULTS AND CONCLUSION
6. ACKNOWLEDGEMENT AND REFERENCES
Automatic Color Sorting Machine Using TCS230
Color Sensor And PIC Microcontroller
Abstract:
Sorting of products is a very difficult industrial process. Continuous manual sorting creates
consistency issues. This paper describes a working prototype designed for automatic sorting of
objects based on the color. TCS230 sensor was used to detect the color of the product and the
PIC16F628A microcontroller was used to control the overall process. The identification of the color
is based on the frequency analysis of the output of TCS230 sensor. Two conveyor belts were used,
each controlled by separate DC motors. The first belt is for placing the product to be analyzed by
the color sensor, and the second belt is for moving the container, having separated compartments, in
order to separate the products. The experimental results promise that the prototype will fulfill the
needs for higher production and precise quality in the field of automation.
Keywords: Color sorting, Conveyor belt, DC motor, PIC 16F628A, TCS230 color sensor.
1. Introduction
Machines can perform highly repetitive tasks better than humans. Worker fatigue on assembly lines
can result in reduced performance, and cause challenges in maintaining product quality. An
employee who has been performing an inspection task over and over again may eventually fail to
recognize the color of product. Automating many of the tasks in the industries may help to improve
the efficiency of manufacturing system. The purpose of this model is to design and implement a
system which automatically separates products based on their color. This machine consists of three
parts: conveyor belt, color sensor, and dc motor. The output and input of these parts was interfaced
using PIC microcontroller.
he project intends to design and implement an “Color Sorting Machine using MicroController”
using position control mechanism and color sensing technology with the help of Micro-Controller
(ESP-32). A prototype has been developed to illustrate the project. In this project the stepper motor
brings the color discs from the holder to exact top position of the color sensor TSC230. The color
sensor TSC230 identify the color of the disc and send the RGB value of the color to the
microcontroller. The microcontroller then identifies the color from the pre define value and instructs
the servo motor to rotate the sliding platform to the respective color pot. In the sext rotation of the
stepper motor the disc fall down to the particular color pot. The developed prototype consists of the
following main section. Disc holder – it holds the color disc in the vertical position just above the
rotating disc positioner. disc positioner – it brings the color discs from the holder and place it
exactly above the color sensor TSC230 Stepper motor – it moves the disc positioner Servo motor
– it controls the sliding platform so that the discs can accumulate to the correct color pot Control
board – it consists of ESP32 microcontroller, stepper motor driver, voltage regulator etc. The heart
of the project. Controls the stepper motor, servo motor and the color sensor TSC230. Color sensor
– this sensor senses the color of any object and break it the RGB value.
1.1. Color Sensing and Identification
Color sensor systems are increasingly being used in automated applications to detect automation
errors and monitor quality at the speed of production line. They are used in assembly lines to
identify and classify products by color. The objectives of their usage include to check the quality of
products [1-3], to facilitate sorting and packaging [4-6], to assess the equality of products in storage
[7,8], and to monitor waste products [9]. Consequently, there is an abundance of color sensors and
the choice is often application-driven [10, 11]. Low cost and simple color sensors are preferred over
sophisticated solutions for less demanding applications where the top priority is cost and power
consumption.
Color names can be used and conjure reasonably consistent perceptions. There have eleven basic
color names that have been identified such as white, gray, black, red, yellow, green, blue, orange,
purple, pink, and brown. Most or all colors can be described in terms of variations and combinations
of these colors [12]. Due to the fact that human color vision is accomplished in part by three
different types of cone cells in the retina, it follows that three values are necessary and sufficient to
define any color. Color theory describes that there are three values that can be thought of as
coordinates of a point in three-dimensional space, giving rise to the concept of color space. Hue,
saturation, luminance is one such color co-ordinate system, or color space.
Figure 1: Block Diagram
1.2. Color Sorting
Bickman, et al [13] described in the article about automated color-sorting using optical technology
that has evolved from early designs intended to remove ceramic contaminants. The system
configuration is similar to automated ceramic removal equipment, but color-sorting equipment used
a different light source. Automated systems can generally be instructed to remove any one or a
combination of the three glass colors. Industrial applications require some sort of automated visual
processing and classification of items placed on a moving conveyor. Bozma and Yal-cin [14] state
that items may be randomly positioned and oriented while moving on a conveyor. A camera located
above the conveyor views the items orthographically. Boukouvalas et al [15] describes an integrated
system developed for the detection of defects on color ceramic tiles and for the color grading of
defect-free tiles. The integrated system developed under the ASSIST project (automatic system for
surface inspection and sorting of tiles) is used for the detection of defects on color tiles and for the
color grading of defect-free tiles. Many have proposed advanced solutions for the sorting of
recyclable packaging towards process automation. Mattone et al [16] had explained about a
technique for detecting and classifying objects. Most of the authors prefer to use 2D Vision
techniques to separate the objects from the known belt background and to get some of their
geometrical parameters.
Figure 2: Circuit Diagram
2. Methodology
2.1. Prototype Design Parameters
The proposed system is designed for automatic sorting of Red or Green or Black colored products.
The prototype consists of two DC motors, two conveyor belt, a PIC and a color sensing circuit using
TCS230 (Fig. 3). DC motors are used to control the conveyor belts. After integrating the
programmed PIC and the TCS230 circuitry with the structure of the model, we measure the
frequency of signals corresponding to each color by observing them on a CRO. Based on this study
the timer delay value is adjusted by reprogramming the PIC. The time required for the product to
reach the corresponding container in the separator placed on second conveyor belt is also
considered. L293D Hybrid IC is used to drive the second motor both in clock wise and anti-clock
wise direction, which provides the to and fro movement of the container of dimensions 9cm x 30cm
x 7cm (Width x Length x Height). Separators were used to create compartments of equal sizes
meant for collecting objects of same color. The end section consist of a DC motor (12V, 30rpm),
which is used to control the movement of the second conveyor belt in order to position the separator
according to the sensor output.
The whole framework, excluding the DC power supply, weighed 1.5kg approximately and was 27cm tall,
35cm wide and 77cm long.
Figure 3: Side view of our prototype.
2.2. TCS230 Color Sensor
The TCS230 is a programmable color sensing module equipped with GY-31 light-to frequency
converter that combines configurable 8x8 silicon photodiode array as single monolithic CMOS
integrated circuit [17]. The output is a square wave (50 percentage duty cycle) with frequency
directly proportional to light intensity (irradiance). The full scale output frequency can be scaled by
one of three preset values via two control input pins. Digital inputs and digital output allow direct
interface to a microcontroller or other logic circuitry. Output enable (OE) places the output in the
highimpedance state for multiple unit sharing of a microcontroller input line. The light-to-frequency
converter reads an 8 x 8 array of photodiodes. Sixteen photodiodes have blue filters, 16 photodiodes
have green filters, 16 photodiodes have red filters, and 16 photodiodes are clear with no filters. The
four types (colors) of photodiodes are inter-digitated to minimize the effect of non-uniformity of
incident irradiance. All 16 photodiodes of the same color are connected in parallel and which type
of photodiode the device uses during operation is pin-selectable. Photodiodes are 120 mm x 120
mm in size and are on 144-mm center.
TSC230 Color Sensor Module :
At the heart of the module is an inexpensive RGB sensor chip from Texas Advanced Optoelectronic
Solutions – TCS230. The TCS230 Color Sensor is a complete color detector that can detect and
measure an almost infinite range of visible colors.
TCS230 Operation:
The TCS230 detects color with the help of an 8 x 8 array of photodiodes, of which sixteen
photodiodes
have red filters, 16 photodiodes have green filters, 16 photodiodes have blue filters, and remaining
16
photodiodes are clear with no filters.
If you look closely at the sensor, you can actually see these filters
Each 16 photodiodes are connected in parallel, so using two control pins S2 and S3 you can choose
which of them to read. So for example, if you want to detect only red color, you can select 16
redfiltered photodiodes by setting the two pins to LOW according to the table. 31 Similarly, you can
choose different types of photodiodes by different combinations of S2 and S3. Table 3: Photodiode
filter selection S2 S3 Photodiode type LOW LOW Red LOW HIGH Blue HIGH LOW Clear (No
filter) HIGH HIGH Green An internal current-to-frequency converter converts readings from
photodiodes into a square wave whose frequency is proportional to the intensity of the chosen color.
The range of the typical output frequency is 2HZ~500KHZ. The sensor has two more control pins,
S0 and S1, which are used for scaling the output frequency. The frequency can be scaled to three
different preset values of 2%, 20% or 100%. This frequencyscaling function allows the sensor to be
used with a variety of microcontrollers and other devices. Table 4: output frequency scaling S0 S1
Output frequency scaling LOW LOW Power down LOW HIGH 2% HIGH LOW 20% HIGH HIGH
100% One can get different scaling factor by different combinations of S0 and S1. For the Node
MCU / ESP32 most applications use the 20% scaling. 3.6.4 TSC230 Color Sensor Module Pinout
The following diagram shows the pinout of a common TCS230 module. Figure 20: TSC230 module
pinout GND is a ground pin. OE is the Output Enable pin. This pin is rarely used and on most
modules is permanently enabled. If not already enabled then pull it LOW. S0 & S1 pins are used to
select the frequency scaling. S2 & S3 pins are used to select the color array. 32 OUT pin is a TTL
level square wave. VCC pin supplies power to the module. Connect it to the 2.7V to 5.5V power
supply
2.3. Constraints on Object Dimensions
The test objects were soft drink bottle caps with cylindrical shape having 2.5cm diameter and 1cm
height. The distance between the top surface of the object and the color sensor, during the time of
detection process, must always be the same. The reason for such a constraint is owed to the fact that
TCS230 produces output signals of different frequencies while detecting the color of the same
object kept at different distances from the sensor. We have used four aluminum rods and a fiber
plate to suspend the color sensor above the first conveyor belt so that a 17cm wide and 6cm high
rectangular window is provided for the object to move under it. In other words, deducting the height
of our test object, the sensor and the top of the object is kept 5cm apart.
2.4. Working of the Model
When a supply of 3.4V is given to the DC motor (12V, 3.5rpm) it starts to rotate. It will control the
movement of the conveyor belt on which the product is placed.
When the light falls on the product it is reflected back to the color sensor. As mentioned before,
color sensor TCS230 has 4 color filters for green, red, blue and black (no color), which is opted by
its select pins. Filters are selected by the program saved in the microcontroller. Frequency output
from color sensor depends on the color of the object as well as the select pin configuration input
from microcontroller. Select pin can select one of the four photo diode filters which can give output
according to the color of the object. When there is no object in front of sensor it produces an output
of 330Hz range frequency and when there is an object it produces an output frequency of 7-14 KHz.
The microcontroller can find the frequency of the output from TCS230 by counting falling or rising
edge of sensor given to its TOCK1 pin using pre-scalar settings set by option register configuration.
The pre-scalar was set for 1:16 arrangement and the time for counting is 50ms. Hence PIC counts
the frequency using its timer at the rate of one increment for sixteen falling edges of input frequency
given to TOCK1.
When there is no object in front of sensor it produces an output of 330Hz range frequency. Hence
we set a break down value of 32H for deciding whether there is an object on the conveyor belt or
not. Therefore the PIC can only proceed to the next step after checking this condition. If there is an
object the sensor produces an output frequency which is proportional to the color of the object and
the selected photo diode configuration in such a way that it provides maximum frequency for the
respective color to the respective photo diode. Hence sensor gives maximum frequency for red
colored object when red filter is selected, and in the same way other colored object are also sensed
by corresponding filters. Frequency received during each filter selection is counted and saved to
separate registers and these values are examined for taking the greater one, in order to identify the
color of the object.
The second DC motor is in contact with another conveyor belt, on which a container is placed. The
container has three sections; first section for Green, middle for Black, and third for Red. According
to the color, the container will be moved in forward or backward direction by the conveyor belt,
which is made possible by connecting the DC motor to L293D hybrid IC. The products will finally
fall to the corresponding sections in the container.
Fig.2 shows the circuit connections between different components of the model. The PIC, has 18
pins, out of which five pins are connected to TCS230 color sensor, and two pins are connected to
L293D IC.
Figure 4: (a)The color sensor identifying the color of object 1, (b)the object 1 (Green) falls into the
first section of the container, (c) The color sensor identifying the color of object 2, and (d)the object
2 (Red) falls into the third section of the container
.
Hardware interfacing
TSC230 interfacing with microcontroller
The TCS3200 color sensor – shown in the figure below – uses a TAOS TCS3200 RGB sensor chip
to
detect color. It also contains four white LEDs that light up the object in front of it.
Here’s the sensor specifications:
Power: 2.7V to 5.5V
Size: 28.4 x 28.4mm (1.12 x 1.12″)
Interface: digital TTL
High-resolution conversion of light intensity to frequency
Programmable color and full-scale output frequency
Communicates directly to microcontroller
A4988 Interfacing with ESP32
To connect the ESP32 board with the stepper motor and driver we will use all the pins of the driver
except for the enable pin and the micro step resolution selection pins. Connect the output pins of the
driver with the respective motor pins. Connect the STEP pin and the DIR pin with any appropriate
GPIO pin of ESP32 board. We have used GPIO12 to connect with DIR and GPIO14 to connect
with
STEP. As we want to operate our stepper mode in full mode hence, we will leave the MS1, MS2
and
MS3 pins as they are. The RST pin will be connected with SLP so that the driver is enabled.
Moreover,
the VCC and GND pins will be connected with Vin and GND pin from ESP32
PROGRAM CODE:
#include<Servo.h>
Servo servo_1;
int pos;
#define S0 15
#define S1 13
#define S2 12
#define S3 14
#define sensorOut 16
// Define pin connections & motor's steps per revolution
const int dirPin = D1;
const int stepPin = D2;
int Red = 0;
int Green = 0;
int Blue = 0;
void setup()
{
servo_1.attach(D3, 500, 2400);
pinMode(S0, OUTPUT);
pinMode(S1, OUTPUT);
pinMode(S2, OUTPUT);
pinMode(S3, OUTPUT);
pinMode(sensorOut, INPUT);
pinMode(stepPin, OUTPUT);
pinMode(dirPin, OUTPUT);
// Setting frequency-scaling to 20%
digitalWrite(S0,HIGH);
digitalWrite(S1,HIGH);
Serial.begin(9600);
}
void loop()
{
// Set motor direction clockwise
digitalWrite(dirPin, HIGH);
// Spin motor slowly
for(int x = 0; x < 267; x++)
69
{
digitalWrite(stepPin, HIGH);
delayMicroseconds(2000);
digitalWrite(stepPin, LOW);
delayMicroseconds(2000);
}
delay(500); // Wait a second
// Setting red filtered photodiodes to be read
digitalWrite(S2,LOW);
digitalWrite(S3,LOW);
// Reading the output frequency
Red = pulseIn(sensorOut, LOW);
// Printing the value on the serial monitor
Serial.print("R= ");//printing name
Serial.print(Red);//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
Green = pulseIn(sensorOut, LOW);
// Printing the value on the serial monitor
Serial.print("G= ");//printing name
Serial.print(Green);//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
Blue = pulseIn(sensorOut, LOW);
// Printing the value on the serial monitor
Serial.print("B= ");//printing name
Serial.print(Blue);//printing RED color frequency
Serial.println(" ");
if(Red <= 6 && Red >=3 && Green <= 13 && Green >= 11 && Blue <= 11 && Blue >=
10){
Serial.println(" - ORANGE Detected!");
servo_1.write (0);
}
if(Red <= 9 && Red >=7 && Green <= 13 && Green >= 11 && Blue <= 11 && Blue >= 9){
Serial.println(" - BROWN Detected!");
servo_1.write (30);
}
70
if(Red <= 6 && Red >=3 && Green <= 6 && Green >= 4 && Blue <= 8 && Blue >= 4){
Serial.println(" - YELLOW Detected!");
servo_1.write (60);
}
if(Red <= 16 && Red >=14 && Green <= 18 && Green >= 15 && Blue <= 14 && Blue >=
12){
Serial.println(" - BLUE Detected!");
servo_1.write (90);
}
if(Red <= 16 && Red >=14 && Green <= 14 && Green >= 10 && Blue <= 14 && Blue >=
12){
Serial.println(" - Green Detected!");
servo_1.write (120);
}
if(Red <= 8 && Red >=6 && Green <= 17 && Green >= 15 && Blue <= 14 && Blue >=
12){
Serial.println(" - RED Detected!");
servo_1.write (150);
}
delay(500);
3. Results and Conclusion
We have developed a sorting machine using PIC for automatic color sorting, taking in to
consideration three colors namely Green, Red and Black. We consumed two months to produce the
prototype with the expense of Rs.2000. Fig.4 shows different stages involved in the process. You
may note that the green object and the red object lying in different sections of the container placed
on the second conveyor belt.
3.1. Dimensional Analysis
The prototype is designed for sorting objects of any shape but having fixed sizes of 1cm. We can of
course change this parameter by adjusting the aluminum frame of the color sensor. But one may
note that it usually results in a change in the light ambience forcing us to do further frequency
analysis of the sensor output for test colors. The prototype will get more complicated as we increase
the number of colors that have to be detected.
The placement of the object on the first conveyor belt is very crucial. It must be so placed that the
centre of the object and that of the sensor should be aligned with the same vertical plane, so that
perfect detection takes place.
3.2. Time Cost
The object once placed on the first conveyor belt takes less than half a second to reach the sensor. It
takes another 200ms for the sensor to detect the color. An additional 0.6secs is required if the color
of the object is not black so s to position the correct compartment in the sorting container, which
implies that an additional 0.6secs will be consumed to reposition the container back the normal
position on the second conveyor belt. Of course, these time values are dependent on the speed of the
DC motors used. 3.1. Trails
As mentioned before we have used objects of standard size and having any of the three colors for
testing our prototype. We conducted a continuous trail with 100 objects and we got 100% correct
detection. As long as the colors of the objects do not deviate from the preset values and as long as
the placement on the belt is perfect, the detection process seldom fails.
4. Future Work
It is very useful in wide varieties of industries along with the help of PLC and SCADA, especially
in the packaging section. Automatic sorting machine enhances efficiency, practicality, and safety of
operators. It ensures remarkable processing capacity as well as peerless performance including color
detection. Of course we need to add high speed DC motors and sensors with appreciable response to
speed up the system for industrial application.
The model can be improved by making some changes in the program and components. Some
suggestions are given below.
We can add a load cell for measurement and control of weight of the product
We can also add a counter for counting the number of products
Speed of the system can be increased accounting to the speed of production
The system can be used as a quality controller by adding more sensors
The sensor can be changed according to the type of product
The DC motor can be replaced with stepper
motor The PIC can be replaced with PLC
Acknowledgements
The authors would like to thank Mr.Mohammed Ismail Yasar Arafath K., Mr.Manoj, Ms.Anju K. and Ms.Nithya
Ramanath M. for their help in technical design and documentation.
References
[1] C. Zhang and K. S. Suslick, Colorimetric sensor array for soft drink analysis , J. Agric Food Chem, vol 55, pp 237-242, 2007.
[2] P. D. Oram and J. Strine, Color measurement of a solid active pharmaceutical ingredient as an aid to identifying key process
parameters , J. Pharm Biomed Anal, vol 40, pp 1021-1024, 2006.Author, Title of the Book, Publisher, (200X), pp:XXX-YYY.
[3] M. Frank, Nobert Kaiser, Wolfgang Buss, Ramona Eberhardt, High-speed industrial color and position sensors , Electronic
Imaging 99, pp 50-57, 1999.
[4] A. Pacquit, J. Frisby, Danny Diamond, King Tong Lau, Alan Farrell, Brid Quilty, Dermot Diamond, Development of a smart
packaging for the monitoring of fish spoilage , Food Chem, vol 102, pp 466-470, 2007.
[5] E. J. Cadieux Jr, System and method for visually inspecting a cigarette packaging process , ed: Google Patents, 2002.
[6] D.J. Lee and R. S. Anbalagan, High-speed automated colorsorting vision system , in Optical Engineering Midwest 95, pp 573-
579, 1995.
[7] J. V. Popov-Ralji, et al, Investigations of bread production with postponed staling applying instrumental measurements of
bread crumb color , Sensors, vol 9, pp 8613- 8623, 2009.
[8] J. V. Popov-Ralji and J. G. Lalii-Petronijevi, Sensory properties and color measurements of dietary chocolates with different
compositions during storage for up to 360 days , Sensors, vol 9, pp 1996-2016, 2009.
[9] R. Bogue, Optical chemical sensors for industrial applications , Sensor Review, vol 27, pp 86-90, 2007.
[10] R. Baribeau, Color reflectance modeling using a polychromatic laser range sensor , IEEE T Pattern. Anal., vol. 14, pp. 263269,
1992.
[11] H. Escid, et al., 0.35 mm CMOS optical sensor for an integrated transimpedance circuit , the International Journal on Smart
Sensing and Intelligent Systems, vol. 4, no. 3, pp. 467481, September 2011.
[12] Norfazlinda Binti Daud, Application of colors sensor in an automated system , Technical University Malaysia, May 2007.
[13] Bickman, Josh, Automated Color-Sorting uses optical technology , vol. 13, 1996.
[14] Bozma and Yal-cin, Visual processing and classification of items on a moving conveyor: a selective perception approach , vol.
18, issue 2, 2002.
[15] C Boukouvalas, J Kittler, R Marik, M Mirmehdi and Petrou, Ceramic tile inspection for color and structural deffects ,
University of Surrey, 1995.
[16] R Mattone, G. Campagiorni, F. Galati, Sorting of items on a moving conveyor belt. Part1: A Technique for detecting and
classifying objects , vol. 16, issues 2-3, 1999. [17] Available at http://www.pobot.org