Color Detector using Arduino Uno


ByDilip Raja 50

Color Detector using Arduino

In this project we are going to interface TCS3200 color sensor with Arduino UNO. TCS3200 is a color sensor which can detect any number of colors with right programming. TCS3200 contains RGB (Red Green Blue) arrays. As shown in figure on microscopic level one can see the square boxes inside the eye on sensor. These square boxes are arrays of RGB matrix. Each of these boxes contain Three sensors, One is for sensing RED light intensity, One is for sensing GREEN light intensity and the last in for sensing BLUE light intensity.

TCS230 Color Sensor Pinout

Each of sensor arrays in these three arrays are selected separately depending on requirement. Hence it is known as programmable sensor. The module can be featured to sense the particular color and to leave the others. It contains filters for that selection purpose. There is forth mode that is no filter mode. With no filter mode the sensor detects white light.


Components Required

Hardware: ARDUINO UNO, power supply (5v), LED, JHD_162ALCD (16*2LCD),TCS3200 color sensor.

Software: ARDUINO IDE (ARDUINO nightly).


Circuit Diagram and Working Explanation

In 16x2 LCD there are 16 pins over all if there is a back light, if there is no back light there will be 14 pins. One can power or leave the back light pins. Now in the 14 pins there are 8 data pins (7-14 or D0-D7), 2 power supply pins (1&2 or VSS&VDD or GND&+5v), 3rd pin for contrast control (VEE-controls how thick the characters should be shown), and 3 control pins (RS&RW&E)


In the circuit, you can observe I have only took two control pins. The contrast bit and READ/WRITE are not often used so they can be shorted to ground. This puts LCD in highest contrast and read mode. We just need to control ENABLE and RS pins to send characters and data accordingly. [Also check: LCD interfacing with Arduino Uno]


The connections which are done for LCD are given below:

PIN1 or VSS to ground

PIN2 or VDD or VCC to +5v power

PIN3 or VEE to ground (gives maximum contrast best for a beginner)

PIN4 or RS (Register Selection) to PIN8 of ARDUINO UNO

PIN5 or RW (Read/Write) to ground (puts LCD in read mode eases the communication for user)

PIN6 or E (Enable) toPIN9 of ARDUINO UNO

PIN11 or D4 to PIN7 of ARDUINO UNO

PIN12 or D5 to PIN11 of ARDUINO UNO

PIN13 or D6 to PIN12 of ARDUINO UNO

PIN14 or D7 to PIN13 of ARDUINO UNO


The connections which are done for color sensor are given below:

VDD to +5V


OE (output Enable) to GND

S0 to UNO pin 2

S1 to UNO pin 3

S2 to UNO pin 4

S3 to UNO pin 5

OUT to UNO pin 10

Arduino Based Color Sensor Circuit

The color which needs to be sensed by the color sensor is selected by two pins S2 and S3. With these two pins logic control we can tell sensor which color light intensity is to be measured.

Say we need to sense the RED color intensity we need to set both pins to LOW. Once that is done the sensor detects the intensity and sends the value to the control system inside the module.



Photodiode Type









Clear (no filter)




The control system inside the module is shown in figure. The light intensity measured by array is sent to current to frequency converter. What it does is, it puts out a square wave whose frequency is in relation to current sent by ARRAY.

Photodiode Array

So we have a system which sends out a square wave whose frequency depends on light intensity of color which is selected by S2 and S3.


The signal frequency sent by module can be modulated depending on use. We can change the output signal frequency bandwidth.



Output Frequency Scaling (f0)



Power Down










The frequency scaling is done by two bits S0 and S1. For convenience we are going to limit the frequency scaling to 20%. This is done by setting S0 to high and S1 to LOW. This feature comes in handy when we are using the module on system with low clock.


The Array sensitivity to color is shown in below figure.

Array Sensitivity

Although different colors have different sensitivity, for a normal use it won’t make much difference.

The UNO here send signal to module to detect colors and the data received by the module is shown in the 16*2 LCD connected to it.

The UNO detects three color intensities separately and shows them on LCD.

The Uno can detect the signal pulse duration by which we can get the frequency of square wave sent by module. With the frequency at hand we can match it with color on sensor.

  1. Int frequency = pulseIn(10, LOW);


As by above condition the UNO reads pulse duration on 10th pin of UNO and stores it value in “frequency” integer.

We are going to do this for all three colors for color recognition. All three color intensities are shown by frequencies on 16x2 LCD.


int OutPut= 10;//naming pin10 of uno as output

unsigned int frequency = 0;


#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins

LiquidCrystal lcd(8, 9, 7, 11, 12, 13);//RS,EN,D4,D5,D6,D7


void setup()


                // set up the LCD's number of columns and rows

                lcd.begin(16, 2);


                pinMode(2, OUTPUT);

                pinMode(3, OUTPUT);//PINS 2, 3,4,5 as OUTPUT

                pinMode(4, OUTPUT);

                pinMode(5, OUTPUT);

                pinMode(10, INPUT);//PIN 10 as input



                digitalWrite(3,LOW);//setting frequency selection to 20%


void loop()


                lcd.print("R=");//printing name


                digitalWrite(5,LOW);//setting for RED color sensor

                frequency = pulseIn(OutPut, LOW);//reading frequency

                lcd.print(frequency);//printing RED color frequency

                lcd.print("  ");

                lcd.setCursor(7, 0);//moving courser to position 7



               lcd.print("B=");// printing name


                digitalWrite(5,HIGH);// setting for BLUE color sensor

                frequency = pulseIn(OutPut, LOW);// reading frequency

                lcd.print(frequency);// printing BLUE color frequency

                lcd.print("  ");

                lcd.setCursor(0, 1);



               lcd.print("G=");// printing name


                digitalWrite(5,HIGH);// setting for GREEN color sensor

                frequency = pulseIn(OutPut, LOW);// reading frequency

                lcd.print(frequency);// printing GREEN color frequency

                lcd.print("    ");

                lcd.setCursor(0, 0);




Get Our Weekly Newsletter!

Subscribe below to receive most popular news, articles and DIY projects from Circuit Digest


  • Dany's picture
    Nov 23, 2015

    How many colors it can detect? Is it possible to you in for measuring skin color? Thank you for replay.

  • Abhishek's picture
    Nov 28, 2015

    Yes, it can detect any color and gives you RGB values of that color. You can convert those RGB values into color, many online tools are available for this.

  • Dany's picture
    Dec 09, 2015

    Please Do you have more photos of this project? thanks

  • Yaakub's picture
    Dec 19, 2015


    I need to understand better how you derive the "Output Frequency Scaling"; for example how you set 2% on S0 = H, S1 = L and the rest.

    Please advise.

    Thanks and best regards,

  • Maddy's picture
    Jan 01, 2016

    This is defined in Color sensor TCS3200 datasheet.

  • Jeys's picture
    Feb 03, 2016

    What is the range of this sensor? I mean the maximum sensing distance

  • M DILIP RAJA's picture
    Feb 03, 2016

    The sensor cannot measure higher distances, the maximum distance is 3cm. With the increment in distance the accuracy gets decreased.

  • Yusuf's picture
    Feb 04, 2016

    Do that arduino have any specification ?

  • Pen's picture
    Feb 23, 2016

    Will this code work for other models of colour sensor? I use the Adafruit TCS34725 and I'm constructing a colour sensor module with an LCD screen.

  • Jan's picture
    Apr 15, 2016

    what is the function of capacitor in this project?

    Thank you very much for your replay.

  • DILIP RAJA's picture
    Apr 16, 2016

    Capacitor is connected across the power supply to filter the noise from the power supply unit.

  • Jan's picture
    Apr 17, 2016

    Thank you very much!:)

  • mac's picture
    May 14, 2016

    What version of arduino is used in this project and please send me the complete tutorial.

  • Isaiah's picture
    Jun 15, 2016

    Using this project idea can one then convert the colours to sound. If possible what can I add?.

  • Shraddha 's picture
    Jul 06, 2016

    My color sensor is giving electrical intensity as the output. How can I convert these values into RGB values of that specific color

  • Dionet's picture
    Jul 07, 2016

    hi, with which tools can i detected all the colors? not just the RGB, and i cant understand the code to modify

  • Abhishek's picture
    Aug 13, 2016

    You can detect any color with this project. Every color is made up of RGB colors, so this circuit gives you values of RGB for every color you scan.

  • Viswajith 's picture
    Jul 10, 2016

    I have just started to build
    Give a tutorial how to build this..
    Thank u..

  • Birinder's picture
    Jul 13, 2016

    Can I use RGB leds to display the detected colour

  • Abhishek's picture
    Aug 13, 2016

    Thats a good idea! yes we can do that, but I suggest you to use NeoPixel LED to display the colors.

  • irmawan's picture
    Jul 25, 2016

    sory sir, , how if i want showing the RGB values not the frequency , ,

  • Shashi's picture
    Aug 06, 2016

    I just bought a TCS 3200 and there is a S0..S4 pins on one end, and on the other end
    pins - but I dont see a OE pin on my board !
    I suspect that the LED pin is the OE ? Is this about right ?

  • Mark Jvann Inson's picture
    Mark Jvann Inson
    Sep 26, 2016

    Can this sensor be used in detecting the color of the liquid inside a test tube???

  • Maddy's picture
    Oct 07, 2016

    Yes, it should detect the color of liquid.

  • pol's picture
    Oct 04, 2016

    What do you mean by that being a programmable sensor? Do we have to set the sensor when detecting a specific color?

  • Maddy's picture
    Oct 27, 2016

    Yes you can program it to only sense the particular color and leave the others and acts like a filter.

  • pius's picture
    Oct 14, 2016

    Can you send to me full tutorial iniordel to lean it more.plz

  • Tellus's picture
    Oct 17, 2016

    Hi guys, doing a project but I need a very small color sensor. Every sensor I seen so far is quite big, any idea where I can found the smallest version?

  • Tootzskie's picture
    Oct 23, 2016

    Hi can you show how much/cost you used for this project. (kindly list down for each item)

  • larry's picture
    Nov 08, 2016

    pls can u give a full project report on this project?

  • miyo's picture
    Nov 15, 2016

    with you experience unconsistence result RGB in lcd display?

  • Dave P.'s picture
    Dave P.
    Jan 20, 2017

    The code line,

    pulseIn(OutPut, LOW);//reading frequency

    Is "pulseIn()" a function from a library that needs to be brought into the Arduino IDE, or is it an intrinsic in the C# language set supported natively?

    Thanks for your example and code, this is great.

  • Dave P.'s picture
    Dave P.
    Jan 20, 2017

    I looked on which has a lot of great arduino info, and believe I have confirmed that indeed PulseIn() is part of the C# implementation.

  • Anas Masood Quddusi's picture
    Anas Masood Quddusi
    Feb 10, 2017

    Hi, this tutorial was extremely helpful and I cannot thank you enough.
    I want to take it a step further. Can we add a RGB LED somewhere and ask it to generate the same color as the one detected by the sensor?
    So in short, Color X---> Sensor ---> Arduino ---> RGB LED ---> Color X.

  • Atheeth's picture
    Feb 17, 2017

    Can it detect only three colours, if no pls tell the modifications to do so that we can detect more than 3 colours.

  • elh's picture
    Mar 04, 2017

    it can detect more than 3 colors. if u have specific color to detect, just set the value into program

  • Deepak's picture
    Mar 18, 2017

    Hello Dilip,

    I have made this project. However, I find that all three values (R,G and B) are very close to each other, irrespective of what colour object is held up in front of the sensor. For example, without any object, I get R=188, B=183 & G= 190. Then when I bring a red object close to the sensor, it shows R=610, B=605 and G=620. With a blue object, I get R =676, B=670 and G = 690. Same is the case with a green object.

    Can you tell me what I am doing wrong?



  • Saurabh Sharma's picture
    Saurabh Sharma
    Mar 29, 2017

    It shows a greater value for green even when you put red color in front of the sensor. Why does this happen?

  • ivan's picture
    Mar 31, 2017

    I'm experiencing the same as Saurabhh and Deepak

  • Sushil's picture
    Apr 25, 2017

    How can i Make this circuit to detect the fluorescence color

  • gajender's picture
    Mar 16, 2018

    my lcd shows boxes only it does not display output

  • Soma's picture
    Apr 22, 2018

    Hi !, Thanks for this. here, when we measure visually red colour thing, lcd shows higher 'G' value than 'R' value & so on .How to avoid this problem ? It is a problem of tcs 3200 sensor , what is the suitable sensor ?
    Thanks. Soma.

  • R.Navya's picture
    Jul 30, 2018

    i need a sensor that detects only green color . What would be the best one to be used?

  • Haryanto's picture
    Jan 31, 2020

    hello sir
    can you help me to be able to get a Library (LIB) color sensor for Proteus Graphs
    I really need it now
    thank you..

Log in or register to post Comment