You are on page 1of 14

ĐẠI HỌC QUỐC GIA TP.

HCM
TRƯỜNG ĐẠI HỌC BÁCH KHOA

COLOR DETECTION AND MEASUREMENT

LỚP: TT01

GVHD: NGUYỄN TRỌNG TÀI

SINH VIÊN THỰC HIỆN

Nguyễn Tấn Lộc 1851034

Nguyễn Trung Hiếu 1852373

TP. HỒ CHÍ MINH, NĂM 2022


1

I. Introduction to Color Sensor


1. What is the Color Sensor?
White light is a combination of various main colors. Red, blue, and green
describe them. The wavelengths of these colors differ. Different varieties of colors
may be created by mixing these colors in various ratios.
Depending on the characteristics of the surface material, some wavelengths
of white light that reach a surface are absorbed while others are reflected back.
These reflected wavelengths enter the human eye, where they are perceived as the
material's color. Red materials are those that reflect red light wavelengths. The Color
Sensor is the element that is utilized for color detection.
The color of the substance is picked up by the color sensor. The RGB scale of
color is often detected by this sensor. Red, blue, or green wavelengths may all be
classified by this sensor. Additionally, these sensors have filters that block UV and
infrared radiation that is not desired.

Figure 1. Color Sensor


2

As a physical structure, color sensors consist of array photodiodes. These


photodiodes are separated arrays for each of the primary colors and are addressed
individually. The photodiodes used in color sensors have sensitivity that changes
with color, leading to the output for each color not linear and not RGB value.
Therefore, the sensor requires calibration in order to get an RGB value.

Figure 2. Photodiodes spectral responsivity

2. Working Principles
Three basic types of equipment are needed to determine a material's color. A
light source must illuminate the material's surface in order to identify the colored
surface and measure the wavelength reflected by it.
A white light emitter built within the color sensor illuminates the surface. To
measure the wavelengths of red, green, and blue colors, respectively, the three
filters have wavelength sensitivities of 580 nm, 540 nm, and 450 nm.
3

Figure 3. Working Principle

The classification of the material's hue is based on how these filters are
activated. The sensor also has a converter for converting light to voltage. By
producing a voltage proportional to the measured color, the sensor reacts to color.
By simultaneously illuminating the material surface with Red, Blue, and Green
LEDs, color may also be detected. Here, the sensor only uses light to convert the
voltage instead of any filters. For color detection, the largest amount of light reflected
by the material's surface when it is irradiated with red, blue, and green light is
determined.

3. Applications
Color sensors are used to measure and detect the color of surfaces. These
sensors have a wide range of applications in industrial, medical, and security
systems.
Some of the applications are light color temperature measurement, RGB LED
consistency control, medical diagnostic systems, health fitness systems, industrial
process control, and more.
4

Figure 4. Color Temperature Chart

Some color sensors can detect various hues in addition to RGB. To precisely
identify the color of the substance, the IR and UV rays will be filtered away. There is
a configurable light frequency converter included in the sensor as well. These
sensors can often be readily interfaced with a microcontroller since they are quite
tiny.

I. Types of Color Sensors


1. TCS32000
The TCS3200 color sensor module is a complete color detection sensor
module that has a TCS3200 sensor with the strength to distinguish between 3 RGB
main colors and 4 white LEDs. Nearly all colors are detectable and measurable by
the TCS3200. To prevent positional aberrations between color spots, the color filters
inside the TCS3200 are dispersed uniformly over the array. A square wave is
produced at the output of the oscillator, which is internal, in proportion to the color
intensity.
The photodiodes in an 8x8 array are read by the light-to-frequency converter.
16 photodiodes, 16 of which have blue filters, 16 of which have green filters, 16 of
which have red-green filters, and 16 of which do not.
5

Figure 5. TCS3200

a. Schematic

Figure 6. TCS3200 ports

Ports Description

S1, S0 (1,2) input, choose the ratio of output frequency

OE (3) input, activate the frequency at output port (low positive)

GND (4) power supply ground

VDD (5) supply voltage


OUT (6) output, the frequency depends on the change in intensity
and color

S2, S3 (7,8) input, choose the photodiode arrays

b. Specifications
- Convert light intensity to high resolution frequency.
- Different color filters and output frequencies are selectable by programming.
- Interfaces directly with a microcontroller.
- Voltage: 2.7 - 5V.
- Size: 28.4 x 28.4mm.
- Output frequency with 50% pulse width.
6

- Frequency is proportional to light of different intensity and color.


- The output frequency is in the range of 2 Hz- 500KHz.
c. Configuration

S2 S3 Type of Filters

L L Red filter

L H Blue filter

H L Clear (no filter)

H H Green filter

S0 S1 Output frequency ratio

L L Power down

L H 2%

H H 20%

H H 100%

2. TCS230
One of the popular color sensors, the TCS230 has a light-to-frequency
converter and a current-to-frequency converter built onto a single CMOS chip. It can
tell the difference between white, blue, green, white, and red. With a frequency
precisely proportional to light intensity, the output signal is a square wave.
The photodiodes in an 8x8 array are read by the light-to-frequency converter.
16 photodiodes, 16 of which have blue filters, 16 of which have green filters, 16 of
which have red-green filters, and 16 of which do not.
7

Figure 7. TCS230 V1

a. Schematic

Figure 8. TCS230 ports

Ports Description

S1, S0 (1,2) input, output frequency scaling selection inputs.

OE (3) input, enable output frequency (active low)

GND (4) power supply ground

VDD (5) supply voltage


OUT (6) output, the frequency depends on the change in intensity
and color

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

b. Configuration
8

S2 S3 Type of Filters

L L Red filter

L H Blue filter

H L Clear (no filter)

H H Green filter

S0 S1 Output frequency ratio

L L Power down

L H 2%

H H 20%

H H 100%

II. Interface TCS3200 with Arduino board


1. Equipment requirements.
- TCS3200
- Arduino board
- Jumper wires

2. Schematic.

Figure 9. Mapping
9

3. Arduino code.
There are two sketches for this project:
- 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.
- 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.
a. 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;

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);
10

// 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);

// 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);
}

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 to get the minimum and maximum value.
Repeat this process with green and red objects and write down the upper and
bottom frequency limits for each color.
b. Distinguish between different colors
This next sketch maps the frequency values to RGB values (that are between
0 and 255).
11

In the previous step when we have maximum blue we obtain a first frequency
and when we have blue at a higher distance we obtain a second frequency.
So, the first frequency corresponds to 255 (in RGB) and the second frequency
to 0 (in RGB). We’ll do this with the Arduino map() function. In the map() function you
need to replace XX parameters with your own values. #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);

// 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);
12

digitalWrite(S3,LOW);

// Reading the output frequency


redFrequency = pulseIn(sensorOut, LOW);
// Remaping the value of the RED (R) frequency from 0 to 255
// You must replace with your own values. Here's an example:
// redColor = map(redFrequency, 70, 120, 255,0);
redColor = map(redFrequency, XX, XX, 255,0);

// Printing the RED (R)


value Serial.print("R = ");
Serial.print(redColor);
delay(100);

// Setting GREEN (G) filtered photodiodes to be


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

// Reading the output frequency


greenFrequency = pulseIn(sensorOut, LOW);
// Remaping the value of the GREEN (G) frequency from 0 to 255
// You must replace with your own values. Here's an example:
// greenColor = map(greenFrequency, 100, 199, 255, 0);
greenColor = map(greenFrequency, XX, XX, 255, 0);

// Printing the GREEN (G) value


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

// Setting BLUE (B) filtered photodiodes to be


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

// Reading the output frequency


blueFrequency = pulseIn(sensorOut, LOW);
// Remaping the value of the BLUE (B) frequency from 0 to 255
// You must replace with your own values. Here's an example:
// blueColor = map(blueFrequency, 38, 84, 255, 0);
blueColor = map(blueFrequency, XX, XX, 255, 0);

// Printing the BLUE (B)


value Serial.print(" B = ");
Serial.print(blueColor);
13

delay(100);

// Checks the current detected color and prints


// a message in the serial monitor
if(redColor > greenColor && redColor > blueColor){
Serial.println(" - RED detected!");
}
if(greenColor > redColor && greenColor > blueColor){
Serial.println(" - GREEN detected!");
}
if(blueColor > redColor && blueColor > greenColor){
Serial.println(" - BLUE detected!");
}
}

You might also like