Go Down

Topic: Sticky; The Great Color Sensor Thread (Read 8846 times) previous topic - next topic

arduino5

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:

TCS230 http://ap.urpi.fei.stuba.sk/sensorwiki/index.php/Acrob041
http://www.parallax.com/dl/docs/prod/datast/TCS230.pdf

TCS3200 http://www.elecfreaks.com/wiki/index.php?title=Color_Sensor_Module
http://www.datasheetspdf.com/PDF/TCS3210/840153/1

TCS34725 http://www.adafruit.com/datasheets/TCS34725.pdf


Pictures:

TCS3200 poor breakout;
http://i01.i.aliimg.com/img/pb/884/859/554/554859884_704.jpg

TCS3200 rich breakout;
http://www.sainsmart.com/zen/zp-core/i.php?a=SKU/20/20-011/20-011-924/nichegeek&i=02.JPG&s=595&cw=&ch=&q=85&wmk=!

TCS3200 code example:
http://www.geeetech.com/wiki/index.php/Arduino_TCS230_Color_Recognition_Sensor_module

TCS230 regular breakout:
http://cdn.sejalivre.org/uploads/2014/10/color-sensor-TCS230-Color-Recognition-Sensor-Detector-Module-DC-3-5V-Input-Color-090541.jpg

TCS230 code example:
http://www.arduinoecia.com.br/2014/02/sensor-de-reconhecimento-de-cor-tcs230.html

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.)
http://ap.urpi.fei.stuba.sk/sensorwiki/images/f/f7/TCS230_Module.jpg

=STEP 2=

-Download the needed libraries unless you want to use your own!
- Arduino Library;
- http://arduinocode.codeplex.com/releases/view/115253  (Does only work for Arduino UNO and simular models. Uses Interupts... whatever that is. E.g. Does not work on Leonardo without Adjustments)
(Relevant thread: http://forum.dev.arduino.cc/index.php?topic=150283.0)
3rd Party Library;
- https://github.com/dalmirdasilva/ArduinoColorRecognitionDriver
- https://github.com/Swap-File/tron-suit/tree/master/Disc/Software/Libraries

=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:
http://circuits.datasheetdir.com/351/TCS230-circuits.jpg

-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.)

Downloads:
- DFRobot example code; http://www.robotshop.com/content/ZIP/documentations-sen0101.zip
- http://profmason.com/?p=2234
- http://tecnomelque.blogspot.com.br/2012/12/arduino-tcs3200d-sensor-de-cor-rgb.html
- http://arms22.blog91.fc2.com/blog-entry-215.html

Full tutorial:
- http://www.tinkbox.ph/tutorials/color-recognition-using-tcs230
- http://www.toptechboy.com/arduino/lesson-15-super-cool-arduino-color-sensor-project/

Claims of extrodinary performance with the TCS230 model as read in;
-https://banu.com/blog/41/interview-of-colorhug-maker-richard-hughes/
-http://www.hughski.com/ (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;
Code: [Select]

//-----------------------------
//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); 
  Serial.begin(9600); 
  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); 
  Serial.println(); 

  //Verifica se a cor vermelha foi detectada 
  if (red < blue && red < green && red > 50) 
  { 
   Serial.println("Red"); 
   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)   
  { 
   Serial.println("Blue"); 
   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) 
  { 
   Serial.println("Green"); 
   digitalWrite(pinoledverm, LOW); 
   digitalWrite(pinoledverd, HIGH); //Acende o led verde 
   digitalWrite(pinoledazul, LOW); 
  } 
  Serial.println(); 

  //Aguarda 2 segundos, apaga os leds e reinicia o processo 
  delay(500);   
  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:
- http://www.instructables.com/id/Introduction-29/

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

arduino5

-Update-
Just checked http://www.toptechboy.com/arduino/lesson-15-super-cool-arduino-color-sensor-project/

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.
https://www.virtuabotix.com/product/virtuabotix-color-sensor-exclusive-lens/

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

nadiacw

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!

carlosaguirre

Hi
I also used a color sensor based on TCS230 (ZX-Color http://olimex.cl/website_MCI/static/documents/Datasheet_ZX-Color.pdf), 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

Go Up