Color Detection 2 PDF
Color Detection 2 PDF
Color Detection 2 PDF
On
CERTIFICATE
This is to certify that the Mini Project entitled “Color Detection using Arduino”
is submitted by
JAPALA NAVYA 15011A0423
K.ARPITHA 15011A0406
2
ACKNOWLEDGEMENT
There are many people who helped us directly and indirectly to complete our project
successfully. We would like to take this opportunity to thank one and all. First we
would like to express our deep gratitude towards our guide Dr.
P.CHANDRASEKHAR REDDY, Professor, Department of Electronics and
Communication Engineering, JNTUHCEH for her support in the completion of our
dissertation. We would like to express our sincere thanks to Dr. T Satya Savitri,
HOD, Department of ECE, JNTUHCEH for providing the facilities to complete the
dissertation. We would like to thank all our faculty and friends for their help and
constructive criticism during the project period. Finally we are very much indebted
to our parents for their moral support and encouragement to achieve goals.
K.ARPITHA 15011A0406
ii
3
DECLARATION
We hereby declare that the mini project entitled “Color Detection Using Arduino”
is the work done during the period from April 2018 to 15 September 2018 and is
submitted in the partial fulfillment of the requirements for the award of degree of
Bachelor of Technology in Electronics and Communication Engineering from
JNTUH College of Engineering Hyderabad. The results embodied in this project
have not been submitted to any other university or Institution for the award of any
degree or diploma.
K.ARPITHA 15011A0406
iii
4
ABSTRACT
Hence color detector is useful in this field to determine the effects of raw
ingredients to the finished product ; its shelf life or change due to processing; and
determine if the final product meets internal quality standards established.
5
LIST OF CONTENTS
Chapter 1: Introduction
Chapter 2: System Description
2.1 Block Diagram
2.2 TCS 3200 Sensor
2.3 Arduino
2.4 Arduino IDE Software
Chapter 3: Implementation and Results
3.1 Circuit Diagram
3.2 Arduino IDE Code
3.3 Obsevations and Results
3.4 Conclusion
Chapter 4: Applications
BIBILIOGRAPHY
6
1. INTRODUCTION
This is a simple color sensor using Aurdino Uno R3 and TCS3200 colo
sensor module. It can be useful for color identification and detection for food-
processing units, color printer applications, paint-mixing applications and other
industrial applications including robotics.
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.
7
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.
8
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.
9
2. SYSTEM DESCRIPTION
Introduction
10
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.
Specifications
Here’s the sensor specifications:
Power: 2.7V to 5.5V
Size: 28.4 x 28.4mm (1.12 x 1.12″)
11
By selectively choosing the photodiode filter’s readings, you’re able to detect the
intensity of the different colors. The sensor has a current-to-frequency converter
that converts the photodiodes’ readings into a square wave with a frequency that is
proportional to the light intensity of the chosen color. This frequency is then, read
by the Arduino – this is shown in the figure below.
12
Pin Out
13
Filter selection
To select the color read by the photodiode, you use the control pins S2 and S3. As
the photodiodes are connected in parallel, setting the S2 and S3 LOW and HIGH in
different combinations allows you to select different photodidodes. Take a look at
the table below:
Photodiode type S2 S3
Frequency scaling
Pins S0 and S1 are used for scaling the output frequency. It can be scaled to the
following preset values: 100%, 20% or 2%. Scaling the output frequency is useful
to optimize the sensor readings for various frequency counters or microcontrollers.
Take a look at the table below:
Power down L L
2% L H
20% H L
100% H H
14
For the Arduino, it is common to use a frequency scaling of 20%. So, you set the S0
pin to HIGH and the S1 pin to LOW.
2.3 ARDUINO
15
2.3.3 Pin Configuration
16
MISO(Master In Slave Out) – The Slave line for sending data to the master.
MOSI(Master Out Slave In) – The master line for sending data to the
peripherals.
SCK(Serial Clock) – The clock pulses which synchronize data transmission
generated by master.
SS(Slave Select) – The pin on each device that the master can use to enable
and disable specific devices
SCA – Data Line
SCL – Clock Line
(Above both pins are used for communicating with I2C/TWI devices)
17
2.4 ARDIUNO IDE SOFTWARE
Programs written using Arduino Software (IDE) are called sketches. These
sketches are written in the text editor and are saved with the file extension .ino.
The editor has features for cutting/pasting and for searching/replacing text. The
message area gives feedback while saving and exporting and also displays errors.
The console displays text output by the Arduino Software (IDE), including
complete error messages and other information. The bottom right hand corner of
the window displays the configured board and serial port. The toolbar buttons
allow you to verify and upload programs, create, open, and save sketches, and open
the serial monitor.
2.4.2 Uploading
Before uploading your sketch, you need to select the correct items from the Tools
> Board and Tools > Port menus.. Once you've selected the correct serial port and
board, press the upload button in the toolbar or select the Upload item from
the Sketch menu. Current Arduino boards will reset automatically and begin the
upload. With older boards (pre-Diecimila) that lack auto-reset, you'll need to press
the reset button on the board just before starting the upload. On most boards, you'll
see the RX and TX LEDs blink as the sketch is uploaded. The Arduino Software
(IDE) will display a message when the upload is complete, or show an error.
18
When you upload a sketch, you're using the Arduino bootloader, a small program
that has been loaded on to the microcontroller on your board. It allows you to
upload code without using any additional hardware. The bootloader is active for a
few seconds when the board resets; then it starts whichever sketch was most
recently uploaded to the microcontroller. The bootloader will blink the on-board
(pin 13) LED when it starts (i.e. when the board resets).
This displays serial sent from the Arduino or Genuino board over USB or serial
connector. To send data to the board, enter text and click on the "send" button or
press enter. Choose the baud rate from the drop-down menu that matches the rate
passed to Serial.begin in your sketch. Note that on Windows, Mac or Linux the
board will reset (it will rerun your sketch) when you connect with the serial
monitor. Please note that the Serial Monitor does not process control characters; if
your sketch needs a complete management of the serial communication with
control characters, you can use an external terminal program and connect it to the
COM port assigned to your Arduino board.
19
3. IMPLEMENTATION AND RESULTS
Wiring the TCS3200 sensor to Arduino is pretty straightforward. Simply follow the
next schematic diagram.
1. Reading and displaying the output frequency on the serial monitor. In this part
you need to write down the frequency values when you place different colors in front
of the sensor.
2. Distinguish between different colors. In this section you’ll insert the frequency
values picked previously on your code, so that your sensor can distinguish between
different colors. We’ll detect red, green and blue colors.
21
void setup() {
// Setting the outputs
pinMode(S0, OUTPUT);
pinMode(S1, OUTPUT);
pinMode(S2, OUTPUT);
pinMode(S3, OUTPUT);
void loop() {
// Setting RED (R) filtered photodiodes to be read
digitalWrite(S2,LOW);
digitalWrite(S3,LOW);
22
digitalWrite(S2,HIGH);
digitalWrite(S3,HIGH);
Place a blue object in front of the sensor at different distances. You should save
two measurements: when the object is placed far from the sensor and when the
object is close to it.
23
Check the values displayed on the serial monitor. The blue frequency (B) should be
the lowest compared to the red (R) and green (G) frequency readings – see figure
below.
When we place the blue object in front of the sensor, the blue frequency (B) values
oscillate between 59 and 223 (see highlighted values).
24
Now depending upon the frequencies of colors ,we can detect colors with the help
of following code
Code:
// TCS230 or TCS3200 pins wiring to Arduino
#define S0 4
#define S1 5
#define S2 6
#define S3 7
#define sensorOut 8
int redFrequency = 0;
int greenFrequency = 0;
int blueFrequency = 0;
int redColor = 0;
int greenColor = 0;
int blueColor = 0;
void setup() {
pinMode(S0, OUTPUT);
pinMode(S1, OUTPUT);
pinMode(S2, OUTPUT);
pinMode(S3, OUTPUT);
25
// Setting the sensorOut as an input
pinMode(sensorOut, INPUT);
digitalWrite(S0,HIGH);
digitalWrite(S1,LOW);
Serial.begin(9600);
void loop() {
digitalWrite(S2,LOW);
digitalWrite(S3,LOW);
Serial.print("R = ");
Serial.print(redFrequency);
delay(100);
digitalWrite(S2,HIGH);
digitalWrite(S3,HIGH);
26
greenFrequency = pulseIn(sensorOut, LOW);
Serial.print(" G = ");
Serial.print(greenFrequency);
delay(100);
digitalWrite(S2,LOW);
digitalWrite(S3,HIGH);
Serial.print(" B = ");
Serial.println(blueFrequency);
delay(100);
// Checks the current detected color and prints a message in the serial monitor
if(redFrequency>25&&redFrequency<40&&blueFrequency>10&&blueFrequency<25&&green
Frequency>100)
return;
27
if(redFrequency<25&&blueFrequency<=10&&greenFrequency>=60)
return;
if(redFrequency>20&&redFrequency<35&&blueFrequency>5&&greenFrequency>=20)
return;
if(redFrequency>65&&redFrequency<80&&blueFrequency>25&&blueFrequency<35&&green
Frequency>80)
return;
if(redFrequency>170&&blueFrequency>50&&greenFrequency>140&&greenFrequency<180)
return;
if(redFrequency>190&&redFrequency<230&&blueFrequency>38&&greenFrequency>160)
return;
28
To distinguish between different colors we have three conditions:
When the R is the maximum value (in RGB parameters) we know we have a red
object
Now, place something in front of the sensor. It should print in your serial monitor
the color detected: red, green or blue.
The following circuit is assembled and the code was dumped in to the board from
the Arduino IDE and the following observaions are made in the serial monitor of
IDE.
1.when color is RED
29
2.when color is WHITE
3.4 Conclusion
The circuit required for the detection of the colors is designed and colors are
detected.Similarly we can detect various colors by doing some changes in code
depending upon the frequencies of colors to be detected.
30
4.APPLICATIONS
It is used for pixel based skin color detection because skin color has proven
to be a useful and robust cue for face detection ,localization .
31
BIBILIOGRAPHY
https://electronicsforu.com/electronics-projects/rgb-color-detector-tcs3200-
sensormodule
https://www.arduino.cc/en/Guide/Environment
https://www.arduino.cc/en/Guide/Introduction
https://randomnerdtutorials.com/arduino-color-sensor-tcs230-tcs3200/
https://www.electronicshub.org/arduino-based-color-detector/
32