| MD_TCS230 Color Sensor Arduino Library 1.2 Library to control TCS230 Color Sensor

Loading...
Searching...
No Matches
Using the Library

## Measuring Frequency

The sensor’s output is a square wave with 50% duty cycle (on/off equal amounts) with frequency directly proportional to light intensity, so accurately measuring the frequency is a fundamental requirement of any implementation.

To measure frequency, we need to measure the number of cycles in a fixed time period. The number of cycles in 1 second is measured in Hz. As long as the system is able to sample cycle transitions at a rate at least twice the expected frequency, we can be assured of an accurate reading. This rate should be easily achievable with an Arduino based implementation, even at 100% frequency scale.

Output scaling can be used to increase the resolution for a given clock rate or to maximize resolution as the light input changes.

The MD_TCS230 library uses a timer interrupt for the gate interval. If another interrupt is running, or interrupts are disabled by the main program, response to the timer could be delayed. That will lengthen the gate interval, perhaps leading to counting more cycles. The next gate interval will be shorter (if normal interrupt response occurs), so a corresponding decrease will occur in the next measurement. This mechanism is implemented in the FreqCount library.

The longer the time period allowed for reading a value, the higher the accuracy. The library is set to use 1000ms, giving a value in Hz, as the basis of measurement. A divisor is applied to the time and the resulting count is multiplied by the divisor. Shorter sampling times are possible when the color differences between samples are more distinct. Higher resolution is obtained using a lower time divisor. There is no additional benefit counting cycles beyond 1000ms using this method.

## Sensor Calibration

To calibrate the sensors, we need to measure the raw data that is returned with black and white test cards and then use that data to scale subsequent readings to an RGB value. This is described in its own section in this documentation.

It is not necessary to calibrate the sensor every time it is used. Calibration can be done separately from the application, and the constants determined during testing applied to the sensor from the code running the final application. Care should be taken to calibrate the sensor in a position that closely approximates final conditions.

## References

TAOS Inc, 'TCS230 Programmable Color Light-to-Frequency Converter', TAOS046, February 2003.

Charles Poynton, 'Sensing Color with the TAOS TCS230', TAOS Inc, 17 May 2005.

Paul J Stoffregen, 'FreqCount Library', http://www.pjrc.com/teensy/td_libs_FreqCount.html accessed 18 February 2013.