Sei sulla pagina 1di 32

Mini Project Report

On

COLOR DETECTION USING ARDUINO


Submitted in partial fulfillment of the
Requirements for the award of the degree of Bachelor of Technology
In
Electronics and Communication Engineering By

JAPALA NAVYA 15011A0423


PASUPULETI SOWMYA 15011A0445
SANJAY GANDHAM 15011A0436
ARPITHA K 15011A0406
Under the Guidance of

Dr. P.CHANDRASEKHAR REDDY


Professor
Dept. of E.C.E., JNTUHCEH

Department of Electronics and Communication Engineering


Jawaharlal Nehru Technological University Hyderabad, College of
Engineering Hyderabad
Kukatpally, Hyderabad – 500085
Jawaharlal Nehru Technological University Hyderabad, College of
Engineering Hyderabad.
Department of Electronics and Communication Engineering

CERTIFICATE
This is to certify that the Mini Project entitled “Color Detection using Arduino”
is submitted by
JAPALA NAVYA 15011A0423

PASUPULETI SOWMYA 15011A0445

SANJAY GANDHAM 15011A0436

K.ARPITHA 15011A0406

In partial fulfillment of the award of degree in Bachelor of Technology in


Electronics and Communication Engineering during academic year 2018-2019.

Internal Guide Head of the Department

Prof. Dr.P.CHANDRASEKHAR REDDY Prof. Dr. T SATYA SAVITRI


Professor Head of Department
Department of E.C.E. Department of E.C.E.
JNTUHCEH JNTUHCEH

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.

JAPALA NAVYA 15011A0423

PASUPULETI SOWMYA 15011A0445

SANJAY GANDHAM 15011A0436

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.

JAPALA NAVYA 15011A0423

PASUPULETI SOWMYA 15011A0445

SANJAY GANDHAM 15011A0436

K.ARPITHA 15011A0406

iii

4
ABSTRACT

Visual color is closely related to perceptions. Consumer perception or


purchase decision is made even prior to tasting food. To detect the color, either the
human eye or the instrument used must be capable of recognizing the object and
translate the stimuli into a perception of color.

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.

Color in raw materials or in finished goods is important to a food processor.


Easier said than done is the quick approach to check colors with the naked eye. There
are disadvantages associated with visual examination as judgment is influenced by
lightning ,visual deficiencies of the eye, or in a trained panel based on repetability.
Application of the color detector include diary products such as milk,
cheese,beef,fruits and vegetables.

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

A color detection algorithm identifies pixels in an image that match a


specified color or color range. The color of detected pixels can then be changed to
distinguish them from the rest of the image.

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.

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.
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

2.1 BLOCK DIAGRAM

TCS 3200 SENSOR ARDUINO SERIAL


MONITOR

2.2 TCS3200 SENSOR

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″)

 Interface: digital TTL


 High-resolution conversion of light intensity to frequency
 Programmable color and full-scale output frequency
 Communicates directly to microcontroller

How does the TCS3200 sensor work?

The TCS3200 has an array of photodiodes with 4 different filters. A photodiode is


simply a semiconductor device that converts light into current. The sensor has:
 16 photodiodes with red filter – sensitive to red wavelength
 16 photodiodes with green filter – sensitive to green wavelength
 16 photodiodes with blue filter – sensitive to blue wavelength
 16 photodiodes without filter
If you take a closer look at the TCS3200 chip you can see the different filters.

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

Here’s the sensor pinout

Pin Name I/O Description

GND (4) -- Power supply ground

OE (3) I Enable for output frequency (active low)

OUT (6) O Output frequency

S0, S1(1,2) I Output frequency scaling selection inputs

S2, S3(7,8) I Photodiode type selection inputs

VDD(5) -- Voltage supply

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

Red LOW LOW

Blue LOW HIGH

No filter HIGH LOW

Green HIGH HIGH

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:

Output frequency scaling S0 S1

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

2.3.1 WHAT IS ARDUINO?

Arduino Uno is a microcontroller board based on the ATmega328P. Along


with Atmega328P, it consists other components such as 16MHz crystal oscillator,
serial communication, voltage regulator, etc .Arduino uno has 14 digital
input/output pins of which 6 can be used as PWM outputs, 6 analog inputs, a USB
connection, a power jack, an ICSP (In-Circuit Serial Programming) header and a
reset button.

2.3.2 Pin diagram

15
2.3.3 Pin Configuration

Pin Category Pin Name Details


Power Vin, 3.3V, 5V, GND Vin: Input voltage to
Arduino when using an
external power source.
5V: Regulated power
supply used to power
microcontroller and other
components on the board.
3.3V: 3.3V supply
generated by on-board
voltage regulator.
Maximum current draw
is 50mA.
GND: ground pins.
Reset Reset Resets the
microcontroller.
Analog Pins A0 – A5 Used to provide analog
input in the range of
0-5V
Input/Output Pins Digital Pins 0 - 13 Can be used as input or
output pins.
Serial 0(Rx), 1(Tx) Used to receive and
transmit TTL serial data.
External Interrupts 2, 3 To trigger an interrupt
.
PWM 3, 5, 6, 9, 11 Provides 8-bit PWM
output.
SPI 10 (SS), 11 (MOSI), 12 Used for SPI (Serial
(MISO) and 13 (SCK) Peripheral Interface)
communication.
Inbuilt LED 13 To turn on the inbuilt
LED.
TWI A4 (SDA), A5 (SCL) Used for TWI (two wire
interface)
communication.
AREF AREF To provide reference
voltage for input voltage
.

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)

2.3.4 Arduino Uno Technical Specifications

Microcontroller ATmega328P – 8 bit AVR family


microcontroller
Operating Voltage 5V
Recommended Input Voltage 7-12V
Input Voltage Limits 6-20V
Analog Input Pins 6 (A0 – A5)
Digital I/O Pins 14 (Out of which 6 provide PWM
output)
DC Current on I/O Pins 40 mA
DC Current on 3.3V Pin 50 mA
Flash Memory 32 KB (0.5 KB is used for
Bootloader)
SRAM 2 KB
EEPROM 1 KB
Frequency (Clock Speed) 16 MHz

17
2.4 ARDIUNO IDE SOFTWARE

The Arduino Integrated Development Environment - or Arduino Software (IDE) -


contains a text editor for writing code, a message area, a text console, a toolbar
with buttons for common functions and a series of menus. It connects to the
Arduino and Genuino hardware to upload programs and communicate with them.

2.4.1 Writing Sketches

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).

2.4.3 Serial Monitor

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

3.1 CIRCUIT DIAGRAM

Wiring the TCS3200 sensor to Arduino is pretty straightforward. Simply follow the
next schematic diagram.

Here’s the connections between the TCSP3200 and the Arduino:

 S0: digital pin 4


 S1: digital pin 5
20
 VCC: 5V
 S3: digital pin 6
 S4: digital pin 7
 OUT: digital pin 8

3.2 ARDUINO IDE CODE


You need two sketches for this project:

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.

3.2.1 Reading the output frequency

// TCS230 or TCS3200 pins wiring to Arduino


#define S0 4
#define S1 5
#define S2 6
#define S3 7
#define sensorOut 8

// Stores frequency read by the photodiodes


int redFrequency = 0;
int greenFrequency = 0;
int blueFrequency = 0;

21
void setup() {
// Setting the outputs
pinMode(S0, OUTPUT);
pinMode(S1, OUTPUT);
pinMode(S2, OUTPUT);
pinMode(S3, OUTPUT);

// Setting the sensorOut as an input


pinMode(sensorOut, INPUT);

// Setting frequency scaling to 20%


digitalWrite(S0,HIGH);
digitalWrite(S1,LOW);

// Begins serial communication


Serial.begin(9600);
}

void loop() {
// Setting RED (R) filtered photodiodes to be read
digitalWrite(S2,LOW);
digitalWrite(S3,LOW);

// Reading the output frequency


redFrequency = pulseIn(sensorOut, LOW);

// Printing the RED (R) value


Serial.print("R = ");
Serial.print(redFrequency);
delay(100);

// Setting GREEN (G) filtered photodiodes to be read

22
digitalWrite(S2,HIGH);
digitalWrite(S3,HIGH);

// Reading the output frequency


greenFrequency = pulseIn(sensorOut, LOW);

// Printing the GREEN (G) value


Serial.print(" G = ");
Serial.print(greenFrequency);
delay(100);

// Setting BLUE (B) filtered photodiodes to be read


digitalWrite(S2,LOW);
digitalWrite(S3,HIGH);

// Reading the output frequency


blueFrequency = pulseIn(sensorOut, LOW);

// Printing the BLUE (B) value


Serial.print(" B = ");
Serial.println(blueFrequency);
delay(100);
}

Procedure to view frequencies

Open the serial monitor at a baud rate of 9600.

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).

3.2.2 Distinguish between different colors


This next sketch maps the frequency values to RGB values (that are between 0 and
255).

In the previous step when we have maximum blue we obtained a frequency of 59


and when we have blue at a higher distance we obtained 223.

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

// Stores frequency read by the photodiodes

int redFrequency = 0;

int greenFrequency = 0;

int blueFrequency = 0;

// Stores the red. green and blue colors

int redColor = 0;

int greenColor = 0;

int blueColor = 0;

void setup() {

// Setting the outputs

pinMode(S0, OUTPUT);

pinMode(S1, OUTPUT);

pinMode(S2, OUTPUT);

pinMode(S3, OUTPUT);

25
// Setting the sensorOut as an input

pinMode(sensorOut, INPUT);

// Setting frequency scaling to 20%

digitalWrite(S0,HIGH);

digitalWrite(S1,LOW);

// Begins serial communication

Serial.begin(9600);

void loop() {

// Setting RED (R) filtered photodiodes to be read

digitalWrite(S2,LOW);

digitalWrite(S3,LOW);

// Reading the output frequency

redFrequency = pulseIn(sensorOut, LOW);

// Printing the RED (R) value

Serial.print("R = ");

Serial.print(redFrequency);

delay(100);

// Setting GREEN (G) filtered photodiodes to be read

digitalWrite(S2,HIGH);

digitalWrite(S3,HIGH);

26
greenFrequency = pulseIn(sensorOut, LOW);

// Printing the GREEN (G) value

Serial.print(" G = ");

Serial.print(greenFrequency);

delay(100);

// Setting BLUE (B) filtered photodiodes to be read

digitalWrite(S2,LOW);

digitalWrite(S3,HIGH);

// Reading the output frequency

blueFrequency = pulseIn(sensorOut, LOW);

// Printing the BLUE (B) value

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)

Serial.println(" - RED detected!");

return;

27
if(redFrequency<25&&blueFrequency<=10&&greenFrequency>=60)

Serial.println(" - PINK detected!");

return;

if(redFrequency>20&&redFrequency<35&&blueFrequency>5&&greenFrequency>=20)

Serial.println(" - white detected!");

return;

if(redFrequency>65&&redFrequency<80&&blueFrequency>25&&blueFrequency<35&&green
Frequency>80)

Serial.println(" - yellow detected!");

return;

if(redFrequency>170&&blueFrequency>50&&greenFrequency>140&&greenFrequency<180)

Serial.println(" -Green detected!");

return;

if(redFrequency>190&&redFrequency<230&&blueFrequency>38&&greenFrequency>160)

Serial.println(" - Blue detected!");

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

 When G is the maximum value, we know we have a green object

 When B is the maximum value, we know we have a blue object

Now, place something in front of the sensor. It should print in your serial monitor
the color detected: red, green or blue.

3.3 OBSERVATIONS AND RESULTS

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.when color is PINK

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

 Color detectors have a wide range of applications in the fields of image


processing, Digital Signal Processing,Object Detection, Color
Identification, etc

 In Industries, Color detectors are often used in sorting objects based on


color.

 It can be useful for color detection of food processing units,color printer


applications , paint mixing applications and other industrial applications
including robotics.

 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 .

 Color measurement of tablets in pharamaceuticals production .In tablet


production different ingredients are used. change in the concentration of
these ingredients affects the color of tablet. The color gradient varies from
white and beige yellow.

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

Potrebbero piacerti anche