Interfacing of Color Detecting sensor TCS3200 with Arduino UNO

What is Color Sensor TCS3200  and How it works? 

A color sensor is a device that can detect colors. It usually detects the color of the surface in the RGB scale. A basic color sensor works by shining white light onto an object and then recording the reflected light to determine its color. Color sensors allow us to accurately detect the color of objects which has a vast range of applications.

This project focuses on using an Arduino color sensor application to detect colors. The color sensor used here is Industrial color Sensor (IC) called TCS3200 color sensor. We will describe the working of TCS3200 and the Arduino color sensor for this project and the various components included.

Visit our Official Online Store —>

Components Required:

  • Arduino UNO
  • TCS3200 (RGB + Clear) Color Sensor
  • Breadboard
  • Power Supply
  • Connecting Wires

Introduction to Color Sensor:

The color we see is actually wavelengths of reflected light which do not actually exist but we are manipulated to see it that way. For example, the color red we see has a particular wavelength of around 620 to 750 nm of the whole visible spectrum. Similarly, the color blue has a wavelength of around 450 to 495 nm. Also, keep in mind that the color we see is actually the color reflected off of the surface while the rest of the colors are absorbed by that specific surface. For example, we see the red color of an apple because it is the color reflected off of it.

What actually happens when we look at an object is that the light reflected off of colorful surfaces reaches the retina at the back of our eyes. Our retina has a number of photoreceptor cells which respond to light and start a chemical process in the brain which perceives that light to be a particular color.

In computers, the sensors help to differentiate light from one another. For example, if we are using a simple light dependent resistor(LDR) to detect colors on two different colored surfaces; such as let’s say, red and blue. We will shine first red light on both the surfaces, the red surface will reflect the light while the blue surface will absorb it. Therefore the red surface will appear bright to the LDR. Similarly, when we shine the blue light, the red surface will absorb it while the blue surface reflects it, and the blue surface seems bright.


Working of the TCS3200 Color Sensor:

The TCS3200 is an 8×8 array of photodiodes. The TCS3200 color sensor detects color and converts color light to frequency. The output of the sensor is proportional to the intensity of the light reflected off the surface of the object. The TCS3200 module has RGB and clear Sensor along with 4 LEDs embedded onto the board.

The photodiodes have three different color filters, 16 for red, blue, green and clear each. It basically consists of the photodiodes which sense color light and then a Current-to-Frequency Converter converts them into a square wave with a frequency proportional to the intensity of light.

The TCS3200 is an 8 pin IC with SOC package. Each of the pins has a specific purpose. The pins 1 and 2 (SO and S1) are used for scaling the output frequency. The pin 3 is Output Enable pin and pin 4 is GND. Pin 5 is VDD with the max supply voltage of 5.5 V. Pin 6 is the output pin used for the square wave output. Pin 7 and 8 (S2 and S3) are used for photodiode selection. The main pins are S0, S1 and S3, S4. These will be used to scale the frequency of the output square wave according to the microcontroller used. Different microcontrollers have different timer configurations. The frequency scaling function basically allows the output of the sensor to be optimized for various microcontrollers.

The S3 and S4 pins are used for photodiode selection according to different color filters (red, blue, green and clear). The TCS3200 has all the components attached including the different resistors and capacitors.

Schematic Diagram:

Working Function of the Project:

This project will use a simple Arduino color sensor. The TCS3200 used has different color filters as mentioned before. The intensity of each color has a different frequency. The Arduino used here has the fixed output frequency to 100% by applying HIGH to S0 and S1 pins of the color sensor. The S2 and S3 pins of the color sensor will select the type of color diode. When a particular photodiode is selected, the PULSEIN feature on the Arduino is activated.

This is connected to the output of the color sensor which helps to calculate the output signal. This is the same for the other photodiodes, Red, Green, and Blue. In each case, the frequency is measured using the PULSEIN feature and is displayed on the Serial Terminal. The color therefore detected is used and displayed onto the LCD which lights up the LED (Light Emitting Diode).

Arduino Based Color Detector using TCS3200 Source Code

The program also prints those colors on the serial, just in case you don’t have an LCD. The only library that you need is for the LCD with the I2C converter.

Here is the code:

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);
int red = 0;
int green = 0;
int blue = 0;
void setup()
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(12, OUTPUT);
pinMode(11, OUTPUT);
pinMode(10, INPUT);
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
void loop()
digitalWrite(12, LOW);
digitalWrite(11, LOW);
red = pulseIn(10, digitalRead(10) == HIGH ? LOW : HIGH);
digitalWrite(11, HIGH);
blue = pulseIn(10, digitalRead(10) == HIGH ? LOW : HIGH);
digitalWrite(12, HIGH);
green = pulseIn(10, digitalRead(10) == HIGH ? LOW : HIGH);
if (red < blue && red < green && red < 20)
Serial.println(" Red Color");
lcd.print("Red Color");
else if (blue < red && blue < green)
Serial.println(" Blue Color");
lcd.print("Blue Color");
else if (green < red && green < blue)
Serial.println(" Green Color");
lcd.print("Green Color");

The one thing that can be unclear in this code is this: digitalRead(10) == HIGH ? LOW: HIGH
It’s just a short form of if and else. (if the read from pin 10 is HIGH, it will return LOW otherwise it will return HIGH). If and else in one line without brackets.

Video Tutorial:


Color sensors have a wide range of applications as mentioned before. These include

  • Image Processing
  • Digital signal processing
  • Color identification
  • Printer color enhancements
  • Choosing and sorting of products

Related posts

Arduino Opta PLC Pros & Cons

Breakthrough of Ardino-Pro Opta: Micro-PLC with industrial IoT proficiency

Top Arduino sensors – the ultimate list 2021


Norafiqah October 1, 2018 - 8:14 pm

Can I have the color sensor in Proteus simulation?

MULUMBA Fostier NZUZI November 23, 2018 - 12:32 pm

Hi, will the same code work if I dont use de I2C interface????

orion February 26, 2019 - 9:16 pm

if (red < blue && red < green && red < 20) why red<20

Adib March 16, 2020 - 10:23 am

why i get the error

Arduino: 1.8.12 (Windows 10), Board: “Arduino Uno”

C:\Users\Adib\Documents\Arduino\libraries\LiquidCrystal_I2C\I2CIO.cpp:35:10: fatal error: ../Wire/Wire.h: No such file or directory

Multiple libraries were found for “LiquidCrystal_I2C.h”

Used: C:\Users\Adib\Documents\Arduino\libraries\LiquidCrystal_I2C

Not used: C:\Program Files (x86)\Arduino\libraries\LiquidCrystal_I2C
compilation terminated.

exit status 1
Error compiling for board Arduino Uno.

This report would have more information with
“Show verbose output during compilation”
option enabled in File -> Preferences.

Ramashesha T N May 19, 2020 - 6:39 am

If the exposed surface has multiple colors what happens.

Supposing I want to expose a Green Coffee Bean that has a Black Spot, can I identify Black Spot on the bean ??

ANDRE January 18, 2021 - 1:16 pm

Friend, your Sketch is incomplete, some variables are missing:
int s0 = 8;
int s1 = 9;
int s2 = 12;
int s3 = 11;
int out = 10;
Hope this helps
big hug !

Add Comment