The TCS230 (and equivalent TCS3200) sensor can be easily purchased mounted on any number of inexpensive breakout boards, similar in design to that shown in the photo. These boards extend the package connections to header pins, and integrate LEDs for illumination of the target object. These sensors work well to recognize color but they need to be calibrated. An Arduino library for this sensor can be found at my Arduino Library site and elsewhere.
The output from the sensor is a square wave (50% duty cycle) with frequency (fO) directly proportional to light intensity:
where fO is the output frequency; fD is the output frequency for dark condition (when Ee = 0); Re is the device responsivity for a given wavelength of light in kHz/(mW/cm2); Ee is the incident irradiance in mW/cm2.
fD is an output frequency resulting from leakage currents. As shown in the equation above, this frequency represents a light-independent term in the total output frequency fO. At very low light levels (dark colors), this dark frequency can be a significant portion of fO. The dark frequency is also temperature dependent.
As fO is directly proportional to frequency, it is possible to map between the frequency and RGB color value (0-255 for each of R, G and B) using linear interpolation.
Two points on the RGB line are well determined – pure Black (RGB 0, 0, 0) and pure White (255, 255, 255). The values returned by the sensor can be read using easily obtainable color swatches:
- A black color card gives us the dark condition constant fD. This is the origin (zero value) for the RGB straight line conversion.
- A white color card gives us the extreme RGB point fW, also known as white balance. Knowing fD, this value can be used to scale all intermediate frequencies to a corresponding RGB value.
The proportional relationship is expressed by the standard straight line equation y = mx + b where
- y is the reading obtained (in our case fO)
- x is the normalised RGB value
- b is the value of y when x is 0 (in our case fD)
- m is the slope, or proportionality constant, of the line (in our case [fW–fD]/255).
The resulting equation is
or, rearranging to give us the desired RGB value
Yurish, Sergey Y 2005, ‘Intelligent Opto Sensors Interfacing Based on Universal Frequency-to-Digital Converter’, Sensors & Transducers Magazine (S&T e-Digest), Vol.56, Issue 6, June 2005, pp.326-334. [PDF Link]
TAOS Inc 2003, ‘TCS230 Programmable Color Light-to-Frequency Converter’, Product Datasheet TAOS046 – February 2003. [PDF Link]
Poynton, Charles 2005, ‘Sensing Color with the TAOS TCS230’, TAOS Inc., 2005-05-17. [PDF Link]