Sticky; The Great Color Sensor Thread

Hi Folks,

Theres been lots of buzz about color sensors and thers been equaly as much confusion about the function of these, contrary to beleives when you buy these things, they are in fact quite a pain to work with.

So, i been doing a lot of research and will be linking any usefull examples and pages for your reference.

=STEP 1=

  • Identify your Color Sensor! (Yes! What you buy is not what you get sometimes!)

#TCS Serries

  • For the TCS models; 4x4, 8x8, 4x8
    4x4 = TCS230((LM)=Lens Module), 8x8 = TCS3200, 4x8 = TCS3210
    Wheter they are any of these, they interface the same way, and appear to be even the same thing. Why there is different datasheets and model numbers is yet unclear to me. Also it seems they are often confused? Or perhaps im confused now.
    I figured i have the TCS230, which appears to be the precessor to the TCS3200?! (Which has a larger array?)

A claim that supports TCS3200 is the upgrade to TCS230;
Quote “This module USES TCS3200, is TCS230 upgrade product. TCS3200 is static recognize object color, and according to the color information output different frequency, through the MCU to convert frequency sampling to RGB color data”

  • Another distinction is that the TCS230 (breakout board) has a EO pin (Typicaly 8 pin PCB), while the TCS3200 (break out board) has an extra LED pin, besides the EO pin. (Typical 10 pin PCB) THis does not mean that you have either one or the other TCS, but they are often putting the TCS 3200 on the 10 pin PCB where as the TCS230 is often put on the 8 pin board. From my research, where i soley go by all different advertisments from webshops.

  • TCS34725 has integrated IR filter. Sold by Adafruit. This makes it perfect if you work arround Infrared. Now, if i only knew the human body emits infrared i wouldve bought this one.

Datasheets & Wiring:





TCS3200 poor breakout;

TCS3200 rich breakout;!

TCS3200 code example:

TCS230 regular breakout:

TCS230 code example:

Lens module picture: (I beleive LensModules are much better than regulars. Because these can focus where they read, unlike the common non-lens version, Which take a ton of Ambient interference, but are ofcourse a ton cheaper as well. Altough, i wish i spend a bit more and got a Lens Version.)

=STEP 2=

-Download the needed libraries unless you want to use your own!

=STEP 3=

-Interface your TCS 230 and/or TCS3200 Color sensor! (Couldnt figure which code is for which sensor, as they seem to work most of the times, or fail in both cases.) I only post working code. I tested this.

-Begin to understand the most basics of the pin layout:

-Understand that it is possible to both connect VCC and GND or to NOT connect them. It seems to just want to boost the brightness of the LEDs on some models. They are not critical for operation as far as i have discovered. I perfer to put them on anyway. And take them off if i feel it doesn give good readings. And see what happens.

So unless its explicitly mentioned NOT to use them; use them! Especialy the GND. Possibly VCC, but not always needed! (Cause it draws from the IO pins.)


Full tutorial:

Claims of extrodinary performance with the TCS230 model as read in;
- (Note: Custom housing for limitting ambient light)

Next up, i will give it a shot myself, And see what i can write up from scratch.
Also i suggest everyone posts question on this thread so those that are expert in this area can reply once and be of good advise once, instead of having to dig up and repost the same awnsers over and over.

Heres a start working off a library-less scrap from net;

//Uses no library :-)

// Programa : Detector de cores usando modulo TCS230  
// Alteracoes e comentarios : Arduino e Cia  
// Baseado no programa original de Martin Mason  
//Pinos de conexao do modulo TCS230  
const int s0 = 3;  
const int s1 = 4;  
const int s2 = 5;  
const int s3 = 6;  
const int out = 2;   
//Pinos dos leds  
int pinoledverm = 2;   //You may ignore this. Unused unless you want to light LEDs
int pinoledverd = 3;   //You may ignore this. Unused unless you want to light LEDs 
int pinoledazul = 4;   //You may ignore this. Unused unless you want to light LEDs 
//Variaveis que armazenam o valor das cores  
int red = 0;  
int green = 0;  
int blue = 0;  
void setup()   
  pinMode(s0, OUTPUT);  
  pinMode(s1, OUTPUT);  
  pinMode(s2, OUTPUT);  
  pinMode(s3, OUTPUT);  
  pinMode(out, INPUT);  
  pinMode(pinoledverm, OUTPUT);  
  pinMode(pinoledverd, OUTPUT);  
  pinMode(pinoledazul, OUTPUT);  
  digitalWrite(s0, HIGH);  
  digitalWrite(s1, HIGH);  
void loop() 
  color(); //Chama a rotina que le as cores  
  //Mostra no serial monitor os valores detectados  
  Serial.print("Red :");  
  Serial.print(red, DEC);  
  Serial.print(" Green : ");  
  Serial.print(green, DEC);  
  Serial.print(" Blue : ");  
  Serial.print(blue, DEC);  

  //Verifica se a cor vermelha foi detectada  
  if (red < blue && red < green && red > 50)  
   digitalWrite(pinoledverm, HIGH); //Acende o led vermelho  
   digitalWrite(pinoledverd, LOW);  
   digitalWrite(pinoledazul, LOW);  

  //Verifica se a cor azul foi detectada  
  else if (blue < red && blue < green)   
   digitalWrite(pinoledverm, LOW);  
   digitalWrite(pinoledverd, LOW);  
   digitalWrite(pinoledazul, HIGH); //Acende o led azul  

  //Verifica se a cor verde foi detectada  
  else if (green < red && green < blue)  
   digitalWrite(pinoledverm, LOW);  
   digitalWrite(pinoledverd, HIGH); //Acende o led verde  
   digitalWrite(pinoledazul, LOW);  

  //Aguarda 2 segundos, apaga os leds e reinicia o processo  
  digitalWrite(pinoledverm, LOW);  
  digitalWrite(pinoledverd, LOW);  
  digitalWrite(pinoledazul, LOW);  
void color()  
  //Rotina que le o valor das cores  
  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);  

Lastley, if all fails! Try the DIY Color sensor from Instructables:

Thanks! Hope you find this usefull so far. Please feel free to add comments, advise, share your experiance and expertise. Correct. Etc…

-Update- Just checked

This guy is amazing. One of the best tutorials i found! I also figured out i have the same sensor he uses. Its the $2 bare color sensor. So what is missing is the lens. They say improves accuracy by 99%

I already suspected from previous readings that distnace and ambient light makes a HUGE! difference in readings, so much, you can hardly do without a lens, unless Red, Green and Blue are the only 3 colors your want.

So heres a cut down of the lens/board he uses.

I got exactly that. So if you have it to? i suggest doing this tutorial and print/buy/craft your own lens.

Hi, I just came across your post because I'm trying out color sensors and trying to minimize the cost of a project that requires 10 sensors to each detect color precisely.

Great info! I've used Adafruit's sensor (TCS34725) and had great results, but it's a bit too expensive for my project, so I bought the TCS230 and got poor precision.

Now I'm going to try making a pinhole lens for it. How would you recommend I craft it? 3D printing a model similar to the Virtuabotix one? Or any other DIY ideas or tips? Thanks!

Hi I also used a color sensor based on TCS230 (ZX-Color, but is very different. So, while typical sensor has 7 pins, ZX-Color has only 3 pins (one for 5v, one for ground and one for output signal). The output must be conected to analog input pin in Arduino UNO. I couldn't find any information about how to obtain the separates R, G, B signals. All information, codes and libraries on internet is based on 7 pins sensor. Please, any help will be aprecciated