Working Principle
The TCS3200 (and earlier TCS230) is a programmable color light-to-frequency converter. It contains an 8×8 array of photodiodes with four types of filters: 16 red, 16 green, 16 blue, and 16 clear (no filter). Two select pins (S2, S3) choose which filter group is active. The current from selected photodiodes drives a current-to-frequency converter, outputting a square wave whose frequency is proportional to light intensity of the selected colour channel.
Analogy: Imagine looking through coloured glasses — red glasses block everything except red light. The TCS3200 has three pairs of glasses and counts how many photons get through each.
Electrical Characteristics
| Parameter | Value |
|---|---|
| Supply Voltage | 2.7 V – 5.5 V |
| Output | Square wave (frequency proportional to intensity) |
| Colour Channels | Red, Green, Blue, Clear |
| Photodiode Array | 8 × 8 (64 photodiodes) |
| Frequency Scaling | 2%, 20%, 100% (selectable via S0, S1) |
| Non-linearity | 0.2% at 50 kHz |
| Dark Frequency | 12 Hz typical |
| Package | SOIC-8 (chip) or GY-31 module (with LEDs) |
Interfacing with an MCU
The TCS3200 module (GY-31) has pins: VCC, GND, S0, S1 (frequency scaling), S2, S3 (filter selection), OUT (frequency), and OE (output enable, usually tied LOW). Four white LEDs illuminate the target object.
Calibration
Colour accuracy depends on white-balance calibration:
- White reference: Place a white card at the sensor distance; read R, G, B frequencies. These represent maximum reflectance per channel.
- Black reference: Block all light; read R, G, B to determine the noise floor.
- Mapping:
R_mapped = map(R_raw, R_black, R_white, 0, 255)— repeat for G and B. - Consistent lighting: The on-board LEDs provide fixed illumination; ambient light introduces error — shade the sensor.
Code Example
/*
* TCS3200 Color Sensor — Arduino
* Wiring: S0→4, S1→5, S2→6, S3→7, OUT→8
*/
#define S0 4
#define S1 5
#define S2 6
#define S3 7
#define OUT_PIN 8
void setup() {
Serial.begin(9600);
pinMode(S0, OUTPUT); pinMode(S1, OUTPUT);
pinMode(S2, OUTPUT); pinMode(S3, OUTPUT);
pinMode(OUT_PIN, INPUT);
/* Frequency scaling to 20% */
digitalWrite(S0, HIGH); digitalWrite(S1, LOW);
Serial.println("TCS3200 Color Sensor Ready");
}
int readColor(bool s2, bool s3) {
digitalWrite(S2, s2); digitalWrite(S3, s3);
delay(20);
return pulseIn(OUT_PIN, LOW); /* Period ∝ 1/frequency */
}
void loop() {
int red = readColor(LOW, LOW);
int green = readColor(HIGH, HIGH);
int blue = readColor(LOW, HIGH);
Serial.print("R: "); Serial.print(red);
Serial.print(" G: "); Serial.print(green);
Serial.print(" B: "); Serial.println(blue);
/* Simple colour classifier */
if (red < green && red < blue) Serial.println(" → RED");
else if (green < red && green < blue) Serial.println(" → GREEN");
else if (blue < red && blue < green) Serial.println(" → BLUE");
else Serial.println(" → UNCLEAR");
delay(500);
}
Real-World Applications
Industrial Colour Sorting
Conveyor-belt sorting systems use TCS3200 sensors to classify objects by colour at rates of 10+ items per second. Red, green, and blue readings are fed to a classifier that triggers pneumatic actuators to divert items into correct bins — used in food grading (fruit ripeness), recycling (plastic colour), and pharmaceutical packaging.
Limitations
- Ambient light sensitivity: External light sources shift readings — enclose the sensor and object in a light-proof chamber.
- No true spectroscopy: Reports broad R/G/B bands, not narrow wavelengths — cannot distinguish metameric colours.
- Distance dependent: Reading changes with target distance; maintain a fixed sensor-to-object gap.
- Glossy surfaces: Specular reflections from shiny objects skew colour readings — matte targets are ideal.