Colour Sensor Calibration TCS230/TCS3200 - DevBhoomi Robots

Home Top Ad

Responsive Ads Here

Post Top Ad

Your Ad Spot

Sunday, September 16, 2018

Colour Sensor Calibration TCS230/TCS3200

Click To Enlarge

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:
TCS230_eq1
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 [fWfD]/255).
The resulting equation is
TCS230_eq2
or, rearranging to give us the desired RGB value
TCS230_eq3

More information on this later posting here.

References

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]

Update 


My first post about calibrating TCS230 RGB color sensor has consistently been the most read article on the site. A lot of readers have also used the MD_TCS230 library to write their own sketches. A few questions, however, have consistently been asked on forums and via email about the sensor and the library. Here is a collection of these FAQs and their answers.

A. How do I connect my sensor to the Arduino?

There are several options for connecting the sensor to the Arduino. First thing is to understand the functions of the sensor IC and which inputs and outputs it needs for operations. These are shown in the figure below.

TCS230_Functional
The IC only has one output, a frequency signal that is proportional to the R, G or B component of the color being tested – more on this later. All the other signals (S0, S1, S2, S3 and OE) are inputs to the IC. This means they are outputs from the Arduino.
The S2 and S3 signals are always required as they are used to change the R, G and B filters for the sensor. These should always be connected to the Arduino output pins.
The S0 and S1 signals are used to select the output frequency scaling. In almost all situations this will be 100%, so S0 and S1 could simply be connected to the Vdd (+5V), but if more control is needed then S0 and S1 can be connected to Arduino pins.
OE is an active low signal that is used to activate the sensor output. When this signal is high, the sensor output is not enabled (see Question E). So if the sensor is to be permanently active, the breakout pin can be permanently connected to ground. Indeed, on most breakout boards, this is already connected to ground (see Question C). To exercise more control over the sensor this can be connected to an Arduino pin.
The MD_TCS230 library allows all the different control combinations to be selected ([S2, S3], [S2, S3, OE], [S2, S3, S0, S1], [S2, S3, S0, S1, OE]) through an overloaded class constructor. In this instance the actual pins numbers are arbitrary and passed as parameters.
The output from the sensor is an oscillating signal at a frequency proportional to the selected color component. This is an input to the Arduino. To measure frequency of this signal, we need to measure the number of cycles in a fixed time period. The MD_TCS230 library uses the FreqCount library to measure this frequency. This library implements a timer interrupt for the gate interval and so MUST be used on a specific Arduino pin, which depends on the type of Arduino the sketch is running. This dependency is clearly documented in the FreqCount library documentation and the associated web site. For example, for the Arduino Uno, the input must to be pin 5, for the Mega it is pin 47.
So, the minimum number of pins that need to be connected to read this sensor are S2, S3 as outputs from the Arduino, Frequency as an input to the Arduino. S2 and S3 are arbitrary pins; Frequency is a specific pin number that depends on Arduino board, as documented on the FreqCount library site.

B. All my RGB readings are (0,0,0). What is wrong?

This could be due to a number of reasons. The most likely is that the connections to the sensor, especially the frequency counter pin, are not correct. See the answer to Question A.
It is also possible that you may have a faulty sensor. Try the same software with a different sensor.

C. Why does the Arduino reset when my sketch runs?

The sensor is usually purchased mounted in a breakout board that board extends the IC connections to header pins and integrates LEDs for illumination of the target object. Many of these boards include a design ‘feature’ connecting OE directly to ground rather than through a pull-down resistor. You can work out if yours has this feature by measuring the resistance between OE and ground with a multimeter – zero ohms reading indicates a direct connection.
If you don’t need to connect the OE pin, then this is a perfectly fine arrangement. However, this will cause problems if the OE line is driven high by external circuitry – this creates a short circuit between ground and the output of the driving circuit, which resets the Arduino.
The solution for this problem is to cut the PCB track that links OE and ground while still leaving the link between OE on the IC and the breakout header pin. You will need to trace the signal back from the header pin to find a convenient spot for this. On my sensor this was easiest between resistors R5 and R8, highlighted by the circle in the photo on the right. This may be different for other boards, so it is wise to follow the connections to make sure the correct PCB track is cut.

TCS230_OE_Pin_ModificationD. My readings don’t seem to be consistent?

The first thing to check is that all electrical connections are sound.
It may also be that stray light is getting into the sensor. One way to reduce this is to shroud the sensor. The shroud does not allow external light to enter the sensing space and also ensures all the reflected light goes back to the sensor.
The shroud can be made from black card, wrapped and taped to the breakout board. Black colored material is preferred as it will make sure the light reflected back into the sensor does not include color components originating from the shroud. My own sensor setup is shown in the photo below.

TCS230_Shrouded
If possible you should also calibrate the sensor in the same positions that it will be used, as the surrounding materials and the distance to the measured object could affect the reading.

E. Can I connect more than one sensor to the Arduino?

Yes. The TCS230 is designed to allow many sensors to be connected.
The S0, S1, S2 and S3 outputs from the Arduino can all be connected in parallel to the different sensors. There will need to be one OE output per sensor, which is used to select which sensor is active at any time.
When the OE pin is set high, the frequency output pin is effectively ‘turned off’ on the corresponding sensor by putting it into a high impedance state. This allows the OE for another sensor to be set low and that sensor to be read. This allows the frequency input pin to the Arduino to be shared between the sensors.

Post Top Ad

Your Ad Spot