ESP32 TCS3200 Color Sensor Module example

The TCS3200 and TCS3210 programmable color light-to-frequency converters that combine configurable silicon photodiodes and a current-to-frequency converter on a single monolithic CMOS integrated circuit. The output is a square wave (50% duty cycle) with frequency directly proportional to light intensity (irradiance).

The full-scale output frequency can be scaled by one of three preset values via two control input pins. Digital inputs and digital output allow direct interface to a microcontroller or other logic circuitry. Output enable (OE) places the output in the high-impedance state for multiple-unit sharing of a microcontroller input line.

In the TCS3200, the light-to-frequency converter reads an 8 x 8 array of photodiodes. Sixteen photodiodes have blue filters, 16 photodiodes have green filters, 16 photodiodes have red filters, and 16 photodiodes are clear with no filters.

In the TCS3210, the light-to-frequency converter reads a 4 x 6 array of photodiodes. Six photodiodes have blue filters, 6 photodiodes have green filters, 6 photodiodes have red filters, and 6 photodiodes are clear with no filters.

The four types (colors) of photodiodes are interdigitated to minimize the effect of non-uniformity of incident irradiance. All photodiodes of the same color are connected in parallel. Pins S2 and S3 are used to select which group of photodiodes (red, green, blue, clear) are active.

Features

  • High-Resolution Conversion of Light Intensity to Frequency
  • Programmable Color and Full-Scale Output Frequency
  • Communicates Directly With a Microcontroller
  • Single-Supply Operation (2.7 V to 5.5 V)
  • Power Down Feature
  • Nonlinearity Error Typically 0.2% at 50 kHz
  • Stable 200 ppm/°C Temperature Coefficient
  • Low-Profile Surface-Mount Package

Frequency scaling

Pins S0 and S1 are used for scaling the output frequency. Scaling the output frequency is useful to optimize the sensor readings for various frequency counters or microcontrollers.

Output frequency scaling S0 S1
Power down L L
2% L H
20% H L
100% H H

 

Filter Selection

To select the color read by the photodiode, you use pins S2 and S3. As the photodiodes are connected in parallel, setting the S2 and S3 LOW and HIGH in different combinations allows you to select different photodidodes.

Photodiode type S2 S3
Red LOW LOW
Blue LOW HIGH
No filter (clear) HIGH LOW
Green HIGH HIGH

 

 

Connection

Code

#define S0 15
#define S1 2
#define S2 0
#define S3 4
#define sensorOut 8
int frequency = 0;

void setup()
{
pinMode(S0, OUTPUT);
pinMode(S1, OUTPUT);
pinMode(S2, OUTPUT);
pinMode(S3, OUTPUT);
pinMode(sensorOut, INPUT);

// Setting frequency-scaling to 20%
digitalWrite(S0,HIGH);
digitalWrite(S1,HIGH);

Serial.begin(9600);
}

void loop()
{
// Setting red filtered photodiodes to be read
digitalWrite(S2,LOW);
digitalWrite(S3,LOW);
// Reading the output frequency
frequency = pulseIn(sensorOut, LOW);
// Printing the value on the serial monitor
Serial.print("R= ");//printing name
Serial.print(frequency);//printing RED color frequency
Serial.print(" ");
delay(100);
// Setting Green filtered photodiodes to be read
digitalWrite(S2,HIGH);
digitalWrite(S3,HIGH);
// Reading the output frequency
frequency = pulseIn(sensorOut, LOW);
// Printing the value on the serial monitor
Serial.print("G= ");//printing name
Serial.print(frequency);//printing RED color frequency
Serial.print(" ");
delay(100);
// Setting Blue filtered photodiodes to be read
digitalWrite(S2,LOW);
digitalWrite(S3,HIGH);
// Reading the output frequency
frequency = pulseIn(sensorOut, LOW);
// Printing the value on the serial monitor
Serial.print("B= ");//printing name
Serial.print(frequency);//printing RED color frequency
Serial.println(" ");
delay(100);
}

Output

R= 42 G= 94 B= 64
R= 35 G= 65 B= 72
R= 60 G= 110 B= 97
R= 78 G= 122 B= 102
R= 143 G= 178 B= 131
R= 119 G= 157 B= 125
R= 113 G= 153 B= 118
R= 108 G= 152 B= 118
R= 107 G= 159 B= 122
R= 111 G= 162 B= 125
R= 114 G= 164 B= 126

Links

AliExpress.com Product – 1pcs TCS230 TCS3200 Color sensor Color recognition module for arduino

SHARE
Previous articleESP32 and IR Line tracking sensor example
Next articleESP32 and SHT21 humidity and temperature sensor example