RGB Color Detector using Arduino & TCS3200

0
167

 

Color sensors offer more dependable solutions to complex automation problems. They are used in a variety of industries, including food and beverage, automotive, and manufacturing, for tasks such as detecting materials, detecting colour marks on parts, verifying manufacturing steps, and so on. While expensive colour sensors are used in industrial applications, inexpensive sensors such as the TCS3200 colour sensor can be used in less stringent applications.

The TCS3200 is very popular because it is inexpensive and simple to use. Before we use this colour sensor in our Arduino project, we should understand how a colour sensor works.

Color Sensors in Action

White light is made up of three primary colours with different wavelengths (red, green, and blue). These colours interact with one another to create various colour shades.

When white light strikes any surface, some wavelengths of light are absorbed while others are reflected, depending on the surface material’s properties. The colour we see is caused by wavelengths being reflected back into our eyes.

Returning to the sensor, a standard colour sensor contains a high-intensity white LED that projects a modulated light onto the object. To detect the colour of reflected light, almost all colour sensors employ a grid of color-sensitive filters, also known as “Bayer Filters,” and an array of photodiodes beneath, as shown in the image below.

A pixel is composed of four filters: one red, one blue, one green, and one clear (no filter). This pattern is also known as the “Bayer Pattern.” Each filter sends only one colour of light to the photodiode beneath, while the clear filter sends all light, as shown below. In low-light situations, the extra light passing through the clear filter is a significant advantage.

After that, the processing chip addresses each photodiode in turn (one colour at a time), and it measures the amount of light that is present. Because there is a collection of photodiodes, the data is initially arithmetically averaged before being submitted to be processed. The colour of an object can be ascertained by first determining the relative levels of red, green, and blue light that it emits.

TCS3200 COLOR RECOGNITION SENSOR MODULE

The TCS3200 Color Sensor is a complete colour detector that can detect and measure almost any visible colour.

The sensor is visible in the centre of the module, surrounded by four white LEDs. When the module is activated, the LEDs light up to illuminate the object being sensed. The sensor can also determine the colour or brightness of an object in complete darkness thanks to these LEDs.

The TCS3200 operates on a 2.7 to 5.5 volt supply voltage and has TTL logic-level outputs.

TCS3200 Configuration
The TCS3200 uses an 8 x 8 array of photodiodes to detect colour; sixteen of the photodiodes have red filters, sixteen have green filters, sixteen have blue filters, and sixteen are clear without filters.
Because the 16 photodiodes are connected in parallel, you can select which of them to read by using the two control pins S2 and S3. If you want to detect only the colour red, for instance, you can select 16 red-filtered photodiodes by setting the two pins to LOW, as shown in the table.

In the same way, you can choose different types of photodiodes by putting S2 and S3 together in different ways.

S2 S3 Photodiode type
LOW LOW Red
LOW HIGH Blue
HIGH LOW Clear (No filter)
HIGH HIGH Green

The readings from the photodiodes are turned into a square wave whose frequency is proportional to the intensity of the colour chosen by a current-to-frequency converter inside the chip. Most output frequencies are between 2 Hz and 500 KHz.

S0 and S1 are two more control pins on the sensor that are used to change the frequency of the output. The frequency can be set to be 2%, 20%, or 100% of what it was previously. The sensor can be used with a wide range of microcontrollers and other devices thanks to this frequency scaling feature.

S0 S1 Output frequency scaling
LOW LOW Power down
LOW HIGH 2%
HIGH LOW 20%
HIGH HIGH 100%

 

When S0 and S1 are put together in different ways, you can get different scaling factors. Most applications for the Arduino use the 20% scaling.

Components Used

  1. Arduino Uno
  2. GENERAL PURPOSE DOT PCB
  3. TCS3200 COLOR RECOGNITION SENSOR
  4. RGB LED MODULE
  5. 12 V Power Supply
  6. Connecting wires 
  7. Female to Female Jumper Wire
  8. 40 PIN FEMALE BERG STRIP
  9. 40 PIN MALE BERG STRIP

How to Connect a TCS3200 Color Sensor to an Arduino UNO

  • VCC to 5V Output pin on Arduino
  • S1 to Arduino pin no 9
  • S0 to Arduino pin no 8
  • S2 to Arduino pin no 10
  • S3 to Arduino pin no 11
  • OUT to Arduino pin no 12

How to Connect a RGB LED Module to an Arduino UNO

  • GND to Arduino GND
  • R to Arduino Pin No 3
  • G to Arduino Pin No 5
  • B to Arduino Pin No 6

Arduino Program

const int s0 = 8;
const int s1 = 9;
const int s2 = 10;
const int s3 = 11;
const int out = 12;
int redled = 3;
int greenled = 5;
int blueled =6;
int red = 0;
int green = 0;
int blue = 0;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(s0 , OUTPUT);
pinMode(s1 , OUTPUT);
pinMode(s2 , OUTPUT);
pinMode(s3 , OUTPUT);
pinMode(out , INPUT);
pinMode(redled , OUTPUT);
pinMode(greenled , OUTPUT);
pinMode(blueled , OUTPUT);
digitalWrite(s0 , HIGH);
digitalWrite(s1 , HIGH);
}
void loop() {
// put your main code here, to run repeatedly:
color();
Serial.print("R Intensity");
Serial.print(red, DEC);
Serial.print("G Intensity");
Serial.print(green, DEC);
Serial.print("B Intensity");
Serial.print(blue, DEC);
if(red < blue && red < green && red <20)
{
Serial.print("red color");
digitalWrite(redled , HIGH);
digitalWrite(greenled , LOW);
digitalWrite(blueled , LOW);
}
else if(blue < red && blue < green && blue < 20)
{
Serial.print("blue color");
digitalWrite(redled , LOW);
digitalWrite(greenled , LOW);
digitalWrite(blueled , HIGH);
}
else if(green < red && green < blue)
{
Serial.print("green color");
digitalWrite(redled , LOW);
digitalWrite(greenled , HIGH);
digitalWrite(blueled , LOW);
}
else
{
Serial.println();
}
delay(1000);
digitalWrite(redled , LOW);
digitalWrite(greenled , LOW);
digitalWrite(blueled , LOW);
}
void color()
{
digitalWrite(s2 , LOW);
digitalWrite(s3 , LOW);
red = pulseIn(out , digitalRead(out) == HIGH ? LOW : HIGH);
digitalWrite(s3 , HIGH);
blue = pulseIn(out , digitalRead(out) == HIGH ? LOW : HIGH);
digitalWrite(s2 , HIGH);
green = pulseIn(out , digitalRead(out) == HIGH ? LOW : HIGH);
}

 

LEAVE A REPLY

Please enter your comment!
Please enter your name here