Using the TCS3200 with Arduino or Parallax Propeller.

Image of the TCS3200 chip - from emartee

Working on a project which requires color detection, but you don’t want to bother with making your own color sensor? The TCS3200 is a great sensor offering sampling rates much higher than one made with a photoresistor. The main downfall to it is that the TCS3200-DB package from Parallax is very expensive ~ 80$ and more complicated to calculate spectral response compensation. If you’re up for some fun, make your own color sensor!

How it works:

As you can see there is an array of photodiodes with color filters on top. There are four types of filters – red, blue, green, and a clear filter. You may have noticed that there are multiple photodiodes of each color, and this helps reduce bad readings due to non-uniformity of incoming light.

TCS3200-DB package from parallax

Excluding power, TCS3200 only has 1 output and the rest of the wires are all inputs. The output is a 50% duty cycle square wave with a frequency proportional to the light intensity (irradiance) on the selected filter. There are two pins to divide the frequency of the square wave S0 and S1, and two pins to select the color filter S2 and S3. The chip works from 2.7V to 5.5V, so it’ll work fine with 3.3V or 5V micro controllers.

Wiring:

When using the TCS3200-DB with Arduino: Connect Vdd, V, and +5v to the Arduino’s 5V line, Gnd connects to the Arduino’s Ground. All other wires are on the example program.

TCS3200 Wiring

Program functionality for Arduino:

The program will need to determine if there an object in front of the sensor. If there is an object present, then figure out what color it is. I will be looking at the TCS3200 output’s rising edge to the falling edge, so the less time elapsed means that there is more light. There will be some redundant readings, but this is to help ensure correct detection if anything is moving.

Take a measurement with the LED off, then compare that to a measurement with the LED on (line 53), both using the clear filter. If there was a significant difference then that means that there is an object in front of the sensor. If there wasn’t a significant difference then just return a zero (line 61-64).

Image from TCS3200 datasheet

Take a clear filter reading and compare it with readings of each color filter, both with the LED on (line 67-72). Then do somewhat of a reverse ratio, since smaller means more light, and pick the largest reading (lines 70 – 96).

Now there will be a serial output of all the ratios and this program simply selects the largest. If you need more accurate readings instead of just the primaries, then I suggest divide the ratio with the spectral response found in the datasheet.

Spectral and pinout from datasheet. Note: if you're using the product from Parallax, use the spectral response from their TCS3200_doc.pdf.

There are plenty of comments in the programs below to help the user get started. there is a detectColor(TCS3200’s output square wave pin) that will return a 0 if nothing is in front of the sensor, 1 for red, 2 for blue, and 3 for green. After each reading it will power off the TCS3200 chip and LED.

I don’t fully support the Parallax Propeller, but I did write a simple program to do basic readings.

TCS3200 for Arduino with line numbers

TCS32000 for Arduino without line numbers

TCS3200 with Parallax Propeller (main.spin)

TCS3200 with Parallax Propeller (taosCountLib.spin)

Or download everything from RapidShare