Sie sind auf Seite 1von 35

https://www.youtube.com/watch?

v=g3i51hdfLaw

Arduino Color Sorter Project


Dejan
Projects
87

In this article I will show you how you can make an Arduino Color Sorter. You can watch the
following video or read the written article below.

Design

All we need for this Arduino project is one color sensor (TCS3200) and two hobbyist servo
motors, which makes this project quite simple but yet very fun to build it. In the first place, using
the Solidworks 3D modeling software I made the design of the color sorter and here’s its
working principle:

 Initially, the colored skittles which are held in the charger drop into the platform attached on
the top servo motor.
 Then the servo motor rotates and brings the skittle to the color sensor which detects its color.
 After that the bottom servo motor rotates to the particular position and then the top servo
motor rotates again till the skittle drop into the guide rail.
Here you can download the 3D model, as well as, the drawings with all dimensions needed for
building this Arduino project.

Arduino Project - Color Sorting Machine 3D Model Assembly Solidworks Files 2.01 MB
DOWNLOAD

Arduino Project - Color Sorting Machine 3D Model Assembly STEP File 1.81 MB
DOWNLOAD

Arduino Project - Color Sorting Machine Drawings 171.59 KB


DOWNLOAD
The following drawings can be used for laser cutting all the parts for the case:

Arduino Color Sorter Drawings for Laser Cut 1.52 MB


DOWNLOAD
Building the Arduino Color Sorter

The material that I used for this project is a 3 mm tick fiberboard. I redraw the parts on the
fiberboard according to the drawings and using a small hand saw cut all the parts to size.
Once I got all the parts ready, I started assembling them. First I assembled the outer parts using a
glue gun.

Then using all-purpose glue I glued the two servo motors on their platforms and attached them to
the assembly.

After that again using a glue I attached the guide rail on the bottom servo motor as well as the
support and the platform needed for the top servo motor.
Next, I inserted a switch and a power jack for powering the Arduino with a 5V adapter and on
the third platform I inserted the color sensor.

I connected the components together according to the following circuit schematics.


You can get the components needed for this Arduino Project from links below:

 TCS230 TCS3200 Color Sensor……. Amazon / Banggood


 Arduino Nano ……………………………. Amazon / Banggood
 Breadboard and Jump Wires ……… Amazon / Banggood
 Servo Motor ………………………………. Amazon / Banggood
 Switch………………………………….…….. Amazon / Banggood
 Power Jack…………………………….…… Amazon / Banggood
*Please note: These are affiliate links. I may make a commission if you buy the components
through these links. I would appreciate your support in this way!

Arduino Color Sorter Source Code

At this point, first we need to program the Arduino and then finish the assembly. Here’s the
Arduino Code:
1. /* Arduino Project - Color Sorting Machine
2. *
3. * by Dejan Nedelkovski, www.HowToMechatronics.com
4. *
5. */
6. #include <Servo.h>
7.
8. #define S0 2
9. #define S1 3
10. #define S2 4
11. #define S3 5
12. #define sensorOut 6
13.
14. Servo topServo;
15. Servo bottomServo;
16.
17. int frequency = 0;
18. int color=0;
19.
20. void setup() {
21. pinMode(S0, OUTPUT);
22. pinMode(S1, OUTPUT);
23. pinMode(S2, OUTPUT);
24. pinMode(S3, OUTPUT);
25. pinMode(sensorOut, INPUT);
26.
27. // Setting frequency-scaling to 20%
28. digitalWrite(S0, HIGH);
29. digitalWrite(S1, LOW);
30.
31. topServo.attach(7);
32. bottomServo.attach(8);
33.
34. Serial.begin(9600);
35. }
36.
37. void loop() {
38.
39. topServo.write(115);
40. delay(500);
41.
42. for(int i = 115; i > 65; i--) {
43. topServo.write(i);
44. delay(2);
45. }
46. delay(500);
47.
48. color = readColor();
49. delay(10);
50.
51. switch (color) {
52. case 1:
53. bottomServo.write(50);
54. break;
55.
56. case 2:
57. bottomServo.write(75);
58. break;
59.
60. case 3:
61. bottomServo.write(100);
62. break;
63.
64. case 4:
65. bottomServo.write(125);
66. break;
67.
68. case 5:
69. bottomServo.write(150);
70. break;
71.
72. case 6:
73. bottomServo.write(175);
74. break;
75.
76. case 0:
77. break;
78. }
79. delay(300);
80.
81. for(int i = 65; i > 29; i--) {
82. topServo.write(i);
83. delay(2);
84. }
85. delay(200);
86.
87. for(int i = 29; i < 115; i++) {
88. topServo.write(i);
89. delay(2);
90. }
91. color=0;
92. }
93.
94. // Custom Function - readColor()
95. int readColor() {
96. // Setting red filtered photodiodes to be read
97. digitalWrite(S2, LOW);
98. digitalWrite(S3, LOW);
99. // Reading the output frequency
100. frequency = pulseIn(sensorOut, LOW);
101. int R = frequency;
102. // Printing the value on the serial monitor
103. Serial.print("R= ");//printing name
104. Serial.print(frequency);//printing RED color frequency
105. Serial.print(" ");
106. delay(50);
107.
108. // Setting Green filtered photodiodes to be read
109. digitalWrite(S2, HIGH);
110. digitalWrite(S3, HIGH);
111. // Reading the output frequency
112. frequency = pulseIn(sensorOut, LOW);
113. int G = frequency;
114. // Printing the value on the serial monitor
115. Serial.print("G= ");//printing name
116. Serial.print(frequency);//printing RED color frequency
117. Serial.print(" ");
118. delay(50);
119.
120. // Setting Blue filtered photodiodes to be read
121. digitalWrite(S2, LOW);
122. digitalWrite(S3, HIGH);
123. // Reading the output frequency
124. frequency = pulseIn(sensorOut, LOW);
125. int B = frequency;
126. // Printing the value on the serial monitor
127. Serial.print("B= ");//printing name
128. Serial.print(frequency);//printing RED color frequency
129. Serial.println(" ");
130. delay(50);
131.
132. if(R<45 & R>32 & G<65 & G>55){
133. color = 1; // Red
134. }
135. if(G<55 & G>43 & B<47 &B>35){
136. color = 2; // Orange
137. }
138. if(R<53 & R>40 & G<53 & G>40){
139. color = 3; // Green
140. }
141. if(R<38 & R>24 & G<44 & G>30){
142. color = 4; // Yellow
143. }
144. if(R<56 & R>46 & G<65 & G>55){
145. color = 5; // Brown
146. }
147. if (G<58 & G>45 & B<40 &B>26){
148. color = 6; // Blue
149. }
150. return color;
151. }

Description of the code:

So, we need to include the “Servo.h” library, define the pins to which the color sensor will be
connected, create the servo objects and declare some variables needed for the program. In the
setup section we need to define the pins as Outputs and Inputs, set the frequency-scaling for the
color sensor, define the servo pins and start the serial communication for printing the results of
the color read on the serial monitor.
In the loop section, our program starts with moving the top servo motor to the position of the
skittle charger. Note that this value of 115 suits to my parts and my servo motor, so you should
adjust this value as well as the following values for the servo motors according to your build.

Next using the “for” loop we will rotate and bring the skittle to the position of the color sensor.
We are using a “for” loop so that we can control the speed of the rotation by changing the delay
time in loop.

Next, after half a second delay, using the custom made function, readColor() we will read the
color of the skittle. Here’s the code of the custom function. Using the four control pins and the
frequency output pin of the color sensor we read color of the skittle. The sensor reads 3 different
values for each skittle, Red, Green and Blue and according to these values we tell what the actual
color is. For more details how the TCS3200 color sensor works you can check my previous
detailed tutorial about it.

Here are the RGB values that I got from the sensor for each skittle. Note that these values can
vary because the sensors isn’t always accurate. Therefore, using these “if” statements we allow
the sensor an error of around +-5 of the tested value for the particular color. So for example if we
have a Red skittle, the first “if” statement will be true and the variable “color” will get the value
1. So that’s what the readColor() custom function does and after that using a “switch-case”
statement we rotate the bottom servo to the particular position. At the end we further rotate the
top servo motor until the skittle drops into the guide rail and again send it back to the initial
position so that the process can repeated.

Color Detector using Arduino Uno


ARDUINO

ByDilip Raja Oct 18, 201549


Color Detector using Arduino

In this project we are going to interface TCS3200 color sensor with Arduino UNO. TCS3200 is a
color sensor which can detect any number of colors with right programming. TCS3200 contains RGB
(Red Green Blue) arrays. As shown in figure on microscopic level one can see the square boxes inside
the eye on sensor. These square boxes are arrays of RGB matrix. Each of these boxes contain Three
sensors, One is for sensing RED light intensity, One is for sensing GREEN light intensity and the last
in for sensing BLUE light intensity.

Each of sensor arrays in these three arrays are selected separately depending on requirement. Hence
it is known as programmable sensor. The module can be featured to sense the particular color and
to leave the others. It contains filters for that selection purpose. There is forth mode that is no filter
mode. With no filter mode the sensor detects white light.

Components Required
Hardware: ARDUINO UNO, power supply (5v), LED, JHD_162ALCD (16*2LCD),TCS3200 color
sensor.
Software: ARDUINO IDE (ARDUINO nightly).

Circuit Diagram and Working Explanation


In 16x2 LCD there are 16 pins over all if there is a back light, if there is no back light there will be 14
pins. One can power or leave the back light pins. Now in the 14 pins there are 8 data pins (7-14 or D0-
D7), 2 power supply pins (1&2 or VSS&VDD or GND&+5v), 3rd pin for contrast control (VEE-controls
how thick the characters should be shown), and 3 control pins (RS&RW&E)

In the circuit, you can observe I have only took two control pins. The contrast bit and READ/WRITE
are not often used so they can be shorted to ground. This puts LCD in highest contrast and read mode.
We just need to control ENABLE and RS pins to send characters and data accordingly. [Also
check: LCD interfacing with Arduino Uno]

The connections which are done for LCD are given below:
PIN1 or VSS to ground
PIN2 or VDD or VCC to +5v power
PIN3 or VEE to ground (gives maximum contrast best for a beginner)
PIN4 or RS (Register Selection) to PIN8 of ARDUINO UNO
PIN5 or RW (Read/Write) to ground (puts LCD in read mode eases the communication for user)
PIN6 or E (Enable) toPIN9 of ARDUINO UNO
PIN11 or D4 to PIN7 of ARDUINO UNO
PIN12 or D5 to PIN11 of ARDUINO UNO
PIN13 or D6 to PIN12 of ARDUINO UNO
PIN14 or D7 to PIN13 of ARDUINO UNO

The connections which are done for color sensor are given below:
VDD to +5V
GND to GROUND
OE (output Enable) to GND
S0 to UNO pin 2
S1 to UNO pin 3
S2 to UNO pin 4
S3 to UNO pin 5
OUT to UNO pin 10
The color which needs to be sensed by the color sensor is selected by two pins S2 and S3. With these
two pins logic control we can tell sensor which color light intensity is to be measured.
Say we need to sense the RED color intensity we need to set both pins to LOW. Once that is done the
sensor detects the intensity and sends the value to the control system inside the module.
S2 S3 Photodiode Type
L L Red
L H Blue
H L Clear (no filter)
H H Green
The control system inside the module is shown in figure. The light intensity measured by array is sent
to current to frequency converter. What it does is, it puts out a square wave whose frequency is in
relation to current sent by ARRAY.

So we have a system which sends out a square wave whose frequency depends on light intensity of
color which is selected by S2 and S3.

The signal frequency sent by module can be modulated depending on use. We can change the output
signal frequency bandwidth.
S0 S1 Output Frequency Scaling (f0)
L L Power Down
L H 2%
H L 20%
H H 100%
The frequency scaling is done by two bits S0 and S1. For convenience we are going to limit the
frequency scaling to 20%. This is done by setting S0 to high and S1 to LOW. This feature comes in
handy when we are using the module on system with low clock.

The Array sensitivity to color is shown in below figure.


Although different colors have different sensitivity, for a normal use it won’t make much difference.
The UNO here send signal to module to detect colors and the data received by the module is shown
in the 16*2 LCD connected to it.
The UNO detects three color intensities separately and shows them on LCD.
The Uno can detect the signal pulse duration by which we can get the frequency of square wave sent
by module. With the frequency at hand we can match it with color on sensor.
1. Int frequency = pulseIn(10, LOW);

As by above condition the UNO reads pulse duration on 10th pin of UNO and stores it value in
“frequency” integer.
We are going to do this for all three colors for color recognition. All three color intensities are shown
by frequencies on 16x2 LCD.
RECOMMENDED TI WHITEPAPERS


Taking charge of electric vehicles – both in the vehicle and on the
grid
This paper will attempt to explain onboard chargers, how they work and why they’re used. It will
also explain charging stations and how they...


Which new semiconductor technologies will speed electric vehicle
charging adoption?
Read this whitepaper to learn more about EV charging systems and their design.

Code
int OutPut= 10;//naming pin10 of uno as output
unsigned int frequency = 0;

#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(8, 9, 7, 11, 12, 13);//RS,EN,D4,D5,D6,D7

void setup()
{
// set up the LCD's number of columns and rows
lcd.begin(16, 2);

pinMode(2, OUTPUT);
pinMode(3, OUTPUT);//PINS 2, 3,4,5 as OUTPUT
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(10, INPUT);//PIN 10 as input

digitalWrite(2,HIGH);
digitalWrite(3,LOW);//setting frequency selection to 20%
}
void loop()
{
lcd.print("R=");//printing name
digitalWrite(4,LOW);
digitalWrite(5,LOW);//setting for RED color sensor
frequency = pulseIn(OutPut, LOW);//reading frequency
lcd.print(frequency);//printing RED color frequency
lcd.print(" ");
lcd.setCursor(7, 0);//moving courser to position 7
delay(500);

lcd.print("B=");// printing name


digitalWrite(4,LOW);
digitalWrite(5,HIGH);// setting for BLUE color sensor
frequency = pulseIn(OutPut, LOW);// reading frequency
lcd.print(frequency);// printing BLUE color frequency
lcd.print(" ");
lcd.setCursor(0, 1);
delay(500);

lcd.print("G=");// printing name


digitalWrite(4,HIGH);
digitalWrite(5,HIGH);// setting for GREEN color sensor
frequency = pulseIn(OutPut, LOW);// reading frequency
lcd.print(frequency);// printing GREEN color frequency
lcd.print(" ");
lcd.setCursor(0, 0);
delay(500);
}

Arduino Based Color Detector


APRIL 22, 2017 BY ANUSHA 11 COMMENTS

A Color Sensor, as the name suggests, is a device that senses or detects colors. A
color sensor will use an external means of emitting light (like an array of white LEDs)
and then analyse the reflected light from the object in order to determine its color.

Color sensors will give an accurate color of the object. There are a wide range of
applications of color sensors like sorting objects by color, quality control systems, printer
color enhancement etc.

In this project, we have designed a simple Arduino Color Sensor application, which has
an ability to detect different colors. We have used TCS3200 color sensors for this
purpose. Introduction to color sensor, circuit diagram and working of the Arduino Color
Sensor project are explained below.
Arduino Color Sensor Images 5
Arduino Color Sensor Images 1
Arduino Color Sensor Images 2
Arduino Color Sensor Images 3
Arduino Color Sensor Images 4
Arduino Color Sensor Images 5
Arduino Color Sensor Images 1

Table of Contents
 Circuit Diagram
 Components Required
 A Brief Introduction to Color Sensor
 Working of the Project
 CODE
 Applications
Circuit Diagram

Components Required
 Arduino Mega [Buy Here]
 TCS3200 (RGB + Clear) Color Sensor Module [Buy Here]
 Breadboard (Prototyping board) [Buy Here]
 Power supply [Buy Here]
 Connecting wires [Buy Here]

NOTE: We have used Arduino Mega in this project as it has large number of I/O pins
and we have connected many devices like TCS 3200 Color Sensor, 16X2 LCD Display
and 4 LEDS. For simple Sensor Data using Serial Communication (Sensor information
on the Serial Terminal), simple Arduino UNO can be used.
A Brief Introduction to Color Sensor
Technically speaking, colors are figments of our imagination. When we see a red apple,
it means that it reflects that particular wavelength (~700 nm for Red) of the
electromagnetic spectrum. This energy is absorbed by the eye and based on some
chemical reaction, the brain says that particular wavelength is red color.

For computers, a sensors that differentiates between different colors will help in
determining the color of the object. We will see a simple color sensor using a photo
resistor (Light Dependent Resistor – LDR) and two different colored objects, say red
and blue.

When we shine bright red light on both the objects, the red object will reflect the light
whereas the blue object will absorb it. So, when red light is incident on both the red and
blue objects, the red objects appears brightest to the LDR as it reflects most of the red
light.

Similarly, when a bright blue light is incident on both the objects, the blue object will
appear the brightest to the sensor. This method is just to understand the working of a
color sensor and the actual results may not be accurate.
Practical Color Sensors like TCS3200 are a bit more complicated than this. The
TCS3200 color sensor is a programmable color sensor which converts color light to
frequency. The output frequency of the sensor is directly proportional to the intensity of
the light reflected from the object.

The TCS3200 Color Sensor Module has RGB + Clear Sensor along with 4 bright white
LEDs embedded on the board. TCS3200 has an 8 x 8 array of photo diodes, 16 each
for Red filters, Blue filters, Green filters and Clear (no filter).

The functional block diagram of TCS3200 Color Sensor is shown in the following image.
It consists of color filters, photo diode array, current to frequency converter and final
square wave output which can be given directly to a microcontroller.
The TSC3200 Color Sensor IC is an 8 pin IC with SOC package. The following image
shows the pin diagram of the Color Sensor IC. In that Pins 1 and 2 (S0 and S1) are
output frequency scaling pins. Pin 3 is Output enable pin and is an active low pin. Pin 4
is GND.
Pin 5 is the VDD pin and the maximum supply voltage is 5.5 V. Pin 6 is the output pin
through which we can get the square wave output. Pins 7 and 8 (S2 and S3) are
Photodiode selection pins.

Pins 1, 2 (S0, S1) and 7, 8 (S3, S4) are of special interest in TCS3200 Color Sensor. S0
and S1 are output frequency scaling pins. With these pins, the frequency of the output
square wave can be scaled according to the application or microcontroller used.

The reason for scaling of output frequency is different microcontrollers have different
timer configurations and there might be some limitations in the counter functionality of
the microcontrollers. The following table shows the percentage of output scaling for
different combinations of S0 and S1.

S0 S1 Output Frequency Scaling (f0) Typical full-scale Frequency

L L Power Down ———-

L H 2% 10 – 12 KHz
H L 20% 100 – 120 KHz

H H 100% 500 – 600 KHz

S3 and S4 are photo diode selection pins. They are used to select different photo
diodes which are associated with different color filters (Red, Blue, Green and Clear).
The following table shows different combinations of S3 and S4 for different types of
photo diodes.

S3 and S4 are photo diode selection pins. They are used to select different photo
diodes which are associated with different color filters (Red, Blue, Green and Clear).
The following table shows different combinations of S3 and S4 for different types of
photo diodes.

S3 S4 Photodiode Type

L L Red

L H Blue

H L Clear (no filter)

H H Green

The TCS 3200 Color Sensor comes in the form of a Module with all the components like
header pins, 4 White LEDs, Resistors and Capacitors in addition to the Actual TCS
3200 Color Sensor. The following image shows the real time Color Sensor Module.
Working of the Project
A simple Color Sensor using Arduino is developed in this project. The color sensor
module senses the color in its surroundings. The working of the project is explained
here.

As mentioned in the introduction to color sensor section, the TCS3200 Color Sensor
has filters for Red, Blue, Green and Clear. The intensity of each color is represented as
a frequency. In Arduino, we have fixed the output frequency scale to 100% by applying
HIGH to S0 and S1 pins of the color sensor.

We have to use the S2 and S3 pin on the color sensor to select the type of photo diode
i.e. red, green or blue. Whenever a particular Photo diode is selected, the PULSEIN
feature of the Arduino is activated on the pin that is connected to the output of the Color
Sensor.

This will help us to calculate the frequency of the output signal. The same process is
repeated for all the three photo diodes: R, G and B. The frequency in all the cases is
measured using the PULSEIN feature and is displayed on the Serial Terminal.

Additionally, this information can be used to identify the color placed in front of the
sensor and display its color on the LCD and also light up the corresponding LED.
CODE
/*Arduino Mega*/

#include<LiquidCrystal.h>

LiquidCrystal lcd(42,43,44,46,48,50);

const int S0 = 7;

const int S1 = 6;

const int outPut= 5;

const int S2 = 4;

const int S3 = 3;

unsigned int frequency = 0;

void setup()

Serial.begin(9600);

pinMode(S0, OUTPUT);
pinMode(S1, OUTPUT);

pinMode(S2, OUTPUT);

pinMode(S3, OUTPUT);

pinMode(OutPut, INPUT);

digitalWrite(S0,HIGH);

digitalWrite(S1,HIGH);

void loop()

Serial.print("R=");

digitalWrite(S2,LOW);

digitalWrite(S3,LOW);

frequency = pulseIn(outPut, LOW);

Serial.print(frequency);

Serial.print("\t");

delay(500);

Serial.print("B=");

digitalWrite(S2,LOW);

digitalWrite(S3,HIGH);
frequency = pulseIn(outPut, LOW);

Serial.print(frequency);

Serial.print("\t");

delay(500);

Serial.print("G=");

digitalWrite(S2,HIGH);

digitalWrite(S3,HIGH);

frequency = pulseIn(outPut, LOW);

Serial.print(frequency);

Serial.print("\t");

delay(500);

Serial.print("\n");

Das könnte Ihnen auch gefallen