GY-31 TCS3200 Color Sensor Features
The TCS3200 color sensor uses 64 photodiodes to detect color. The output of this sensor is a square wave. Color intensity is obtained directly from the frequency of the square wave. These 64 photodiodes consist of 16 diodes with red filter, 16 diodes with green filter, 16 diodes with blue filter and 16 transparent photodiodes without filter. All 16 diodes of each type are connected in parallel. To detect any color, the photodiodes corresponding to that color are activated.
You can download the datasheet of this module here.
GY-31 TCS3200 Color Sensor Pinout
This Module has the following pins:
- VCC: Module power supply – 2.7V to 5.5V
- GND: Ground
- OUT: Output signal
- S0: Output Frequency Scaling Selection Input
- S1: Output Frequency Scaling Selection Input
- S2: Photodiode Type Selection Input
- S3: Photodiode Type Selection Input
- LED: LED control
Pins S2 and S3 are used to select one of the 4 photodiode types. Take a look at the table below.
Pins S0 and S1 are used for scaling the output frequency. Take a look at the table below.
You can see the pinout of this module in the image below.
Interfacing GY-31 TCS3200 Color Sensor with Arduino
Step 1: Circuit
The following circuit show how you should connect Arduino to TCS3200 sensor. Connect wires accordingly.
Step 2: Code
Upload the following code to your Arduino.
/* GY-31-TCS3200-Color-Recognition-Sensor-Module Modified on 29 Dec 2020 by Amir Mohammad Shojaee @ Electropeak
First, we declare four outputs for the 4 control pins of the sensor and then one input for the sensor output pin. Next, we determine the output frequency scaling using pins S0 and S1. Then we select color using pins S2 and S3. Next, with the pulseIn command, we get the intensity of three colors: red, blue and green, and display them on the Serial Monitor.
We can calibrate the sensor output pulse using the map command and make the color intensity range from 0 and 100.
To do this, we must first place sensor in a completely stable position and then open the Serial Monitor and place the red, green and blue papers in front of the sensor, respectively. We write the range of each color and convert this range to values from 0 to 100 using map command.
You can see the output of Serial Monitor when we place the three colors red, green and blue papers in front of the sensor, respectively.
Output of Red color:
Output of Green color:
Output of Blue color: