top of page
Writer's pictureRamesh G

NodeMCU Based Color Finder using TCS3200 Sensor

Updated: Nov 27, 2021



In this tutorial we will make a color Finder using a color sensor TCS3200, LCD display and NodeMCU8266 12E dev board. TCS3200 consisting of 64 diode in the combination which are embedded in a single small chip. the working depends on the main fact which is, every 16 diodes are coated with a different color. RED, BLUE, Green, and transparent. when the light refracts from these color patterns every four different colors coated photodiodes will receive the different light frequency. which helps the sensor to differentiate between the color.



Circuit Diagram





Components Required

  • NodeMCU ESP8266

  • TCS3200 color Sensor

  • Jumper Wires

  • LCD 16x2, I2C Module


TCS3200 color Sensor Module

This Arduino compatible TCS3200 color sensor module consist of a TAOS TCS3200 RGB sensor chip and 4 white LEDs. The main part of the module is the TCS3200 chip which is a Color Light-to-Frequency Converter. The white LEDs are used for providing proper lighting for the sensor to detect the object colour correctly. This chip can sense a wide variety of colours and it gives the output in the form of corresponding frequency. This module can be used for making colour sorting robots, test strip reading, colour matching tests etc.

The TCS3200 chip consist of an 8 x 8 array of photodiodes. Each photodiode have either a red, green, or blue filter, or no filter. The filters of each color are distributed evenly throughout the array to eliminate location bias among the colors. Internal circuits includes an oscillator which produces a square-wave output whose frequency is proportional to the intensity of the chosen color.


Features and Specifications

  • Input voltage: (2.7V to 5.5V)

  • Interface: Digital TTL

  • High-resolution conversion of light intensity to frequency

  • Programmable colour and full-scale output frequency

  • No need of ADC(Can be directly connected to the digital pins of the microcontroller)

  • Power down feature

  • Working temperature: -40oC to 85oC

  • Size: 28.4×28.4mm(1.12×1.12″)

Pin Configuration


PIN PIN

NAME NUMBER DESCRIPTION

GND 4 Power supply ground. All voltages are reference to the ground.

VCC 5 Supply voltage

OE 3 Enable for FO (Active low)

OUT 6 Output frequency (fo)

S0, S1 1, 2 Select lines for output frequency scaling

S2, S3 7,8 Select lines for photodiode type.


Logic level

S0 S1 OUTPUT FREQUENCY SCALING(f0)

L L Power down

L H 2%

H L 20%

H H 100%


Photodiode Logic

S2 S3 PHOTODIODE TYPE

L L RED

L H BLUE

H L CLEAR (NO FILTER)

H H GREEN



The sensor has four different types of filter covered diodes. In the 8 x 8 array of photodiodes, 16 photodiodes have Red filters, 16 have Blue filters, 16 have Green filters and the rest 16 photodiodes are clear with no filters. Each type can be activated using the S2, S3 selection inputs. Since each photodiodes are coated with different filters each of them can detect the corresponding colours. For example, when choosing the red filter, only red incident light can get through, blue and green will be prevented. By measuring the frequency, we get the red light intensity. Similarly, when choose other filters we can get blue or green light.

We can also set the frequency scaling option by using the S0, S1 select lines. Normally, in Arduino 20% frequency scaling is used.


How to use the module Pin Configuration

TCS3200 color sensor module can be used to detect the colous with the help of a microcontroller. Actually, the microcontroller is measuring the output frequency from the 6th pin.

To determine the color of an object, we’ve to measure the frequency from 6th pin when each filter is activated.


Set both S2 and S3 to LOW, measure the frequency. Now we get the intensity of RED component in the object.

Set S2 to LOW and S3 to HIGH in order to get the intensity of BLUE component in the object.

Set both S2 and S3 to HIGH and get the intensity of GREEN component in the object.

Compare the frequencies of the three components to get the actual colour of the object.

TIP: In Arduino, we can use the ‘pulseIn’ command to get the frequency variations.

e.g.: 
digitalWrite(S2, LOW);
digitalWrite(S3, LOW);   //Activating photodiode with red filter
red = pulseIn(outpin, LOW); 

Here we get the value corresponding to the red color component of the object color.


Similarly, we’ve to activate each photodiodes by changing the S2 and S3 states and read the corresponding values of green and blue colour components of the object colour.

For a Red object we get an approximate value of red=16, green=53 and blue=45. This may vary from ambient light and experiment setup. For good results, it’s better to cover the object and sensor from ambient light.


Programming Logic

  • First set the input pins as input and output pins as output. No need to use analog pins.

  • Set S0 and S1 to high or low to set desired frequency scaling.

  • In loop, activate each filters by setting S2 and S3 to HIGH or LOW and measure frequency ‘fo’ from 6th pin to get corresponding colour intensity. Compare frequencies of each colour to determine the colour of the object.

Component Datasheet PDF: TCS3200 Color Sensor Datasheeet



Installing the arduino Library

DownloadLiquid crystalLibrary.

After downloading the .zip files, add the libraries in Arduino IDE by clicking on


To install the library navigate to the Sketch > Include Library > Manage Libraries… Wait for Library Manager to download libraries index and update list of installed libraries.


Subscribe and download code.


Arduino Code:

#include <LiquidCrystal_I2C.h>

// set the LCD number of columns and rows

int lcdColumns = 16;

int lcdRows = 2;

LiquidCrystal_I2C lcd(0x27, lcdColumns, lcdRows); // change your I2C ADDRESS HERE EXAMPLE 0x3F

const int s0 = D3;

const int s1 = D4;

const int s2 = D5;

const int s3 = D6;

const int out = D7;

int red = 0;

int green = 0;

int blue = 0;


int redcolor= 0;

int greencolor= 0;

int bluecolor= 0;

int yellowcolor= 0;


int color= 0;



void setup()

{

Serial.begin(9600);

lcd.init();

lcd.backlight();

lcd.setCursor(0, 0);

lcd.print("ESP Color Finder");

pinMode(s0, OUTPUT);

pinMode(s1, OUTPUT);

pinMode(s2, OUTPUT);

pinMode(s3, OUTPUT);

pinMode(out, INPUT);

digitalWrite(s0, HIGH);

digitalWrite(s1, HIGH);


}

void loop()

{


digitalWrite(s2, LOW);

digitalWrite(s3, LOW);

//count OUT, pRed, RED

red = pulseIn(out, digitalRead(out) == HIGH ? LOW : HIGH);

digitalWrite(s3, HIGH);

//count OUT, pBLUE, BLUE

blue = pulseIn(out, digitalRead(out) == HIGH ? LOW : HIGH);

digitalWrite(s2, HIGH);

//count OUT, pGreen, GREEN

green = pulseIn(out, digitalRead(out) == HIGH ? LOW : HIGH);

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<18 & red>6 & green<32 & green>26 & blue<29 & blue>20){

delay(250);

redcolor++;

Serial.print("Red");

lcd.setCursor(0, 1);

lcd.print(" Red ");

delay(2000);

lcd.clear();


}

if(red<30 & red>26 & green<40 & green>36 & blue<30 &blue>26){

delay(250);

bluecolor++;

Serial.print("Blue");

lcd.setCursor(0, 1);

lcd.print(" Blue ");

delay(2000);

lcd.clear();


}

if(red<24 & red>20 & green<24 & green>20 & blue<22 & blue>18){

delay(250);

greencolor++;

Serial.print("Green");

lcd.setCursor(0, 1);

lcd.print(" Green ");

delay(2000);

lcd.clear();


}

if(red<16 & red>12 & green<24 & green>20 & blue<26 & blue>22){

delay(250);

yellowcolor++;

Serial.print("Yellow");

lcd.setCursor(0, 1);

lcd.print(" Yellow ");

delay(2000);

lcd.clear();


}

Serial.println();

// delay(1000);

}


4,269 views0 comments

Comments


bottom of page