top of page

Interfacing Colour Sensor with Arduino (TCS3200)

What is a Color Sensor?


A colour sensor can determine different colours. They will utilize a means of emitting light and then look at the reflected light to determine an object’s colour. This will give the machine the actual colour of that object. These sensors are in use in quite a few different applications today. You can find them in quality control systems, packaging systems, and more.


Specifications:


· Power: 2.7V to 5.5V

· Size: 28.4 x 28.4mm (1.12 x 1.12″)

· Interface: digital TTL

· High-resolution conversion of light intensity to frequency

· Programmable colour and full-scale output frequency

· Communicates directly to the microcontroller


Material Required:


Material Quantity

Arduino Uno 1

Colour Sensor 1

Jumper cables 10


Pinout Diagram:



Working:


The TCS230 senses colour light with the help of an 8 x 8 array of photodiodes. Then using a Current-to-Frequency Converter the readings from the photodiodes are converted into a square wave with a frequency directly proportional to the light intensity. Finally, using the Arduino Board we can read the square wave output and get the results for the colour.



If we take a closer look at the sensor we can see how it detects various colours. The photodiodes have three different colour filters. Sixteen of them have red filters, another 16 have green filters, another 16 have blue filters and the other 16 photodiodes are clear with no filters.



Every 16 photodiodes are connected in parallel, so using the two control pins S2 and S3 we can select which of them will be read. So for example, if we want to detect red colour, we can just use the 16 red filtered photodiodes by setting the two pins to a low logic level according to the table.





The sensor has two more control pins, S0 and S1 which are used for scaling the output frequency. The frequency can be scaled to three different preset values of 100 %, 20 % or 2%. This frequency-scaling function allows the output of the sensor to be optimized for various frequency counters or microcontrollers.


Circuit Diagram:



Tested Programming Code:


First, we need to define the pins to which the sensor is connected and define a variable for reading the frequency. In the setup section, we need to define the four control pins as outputs and the sensor output as an Arduino input. Here we also need to set the frequency scaling, for this example, I will set it to 20%, and start the serial communication for displaying the results in the Serial Monitor.


In the loop section, we will start with reading the red filtered photodiodes. For that purpose, we will set the two control pins S2 and S3 to low logic level. Then using the “pulseIn()” function we will read the output frequency and put it into the variable “frequency”. Using the Serial.print() function we will print the result on the serial monitor. The same procedure goes for the two other colours, we just need to adjust the control pins for the appropriate colour.


Code:


#define S0 4

#define S1 5

#define S2 6

#define S3 7

#define sensorOut 8

int frequency = 0;

void setup() {

pinMode(S0, OUTPUT);

pinMode(S1, OUTPUT);

pinMode(S2, OUTPUT);

pinMode(S3, OUTPUT);

pinMode(sensorOut, INPUT);

digitalWrite(S0,HIGH); digitalWrite(S1,LOW);

Serial.begin(9600);}

void loop() {

digitalWrite(S2,LOW);

digitalWrite(S3,LOW);





frequency = pulseIn(sensorOut, LOW);

Serial.print("R= ");//printing name Serial.print(frequency);//printing

RED color frequency Serial.print(" ");

delay(100);

digitalWrite(S2,HIGH); digitalWrite(S3,HIGH);


frequency = pulseIn(sensorOut, LOW);

Serial.print("G= ");

Serial.print(frequency);Serial.print(" ");

delay(100);

digitalWrite(S2,LOW); digitalWrite(S3,HIGH);frequency

pulseIn(sensorOut, LOW);

Serial.print("B= ");//printing name Serial.print(frequency);//printing RED color frequency Serial.println(" ");

delay(100);




















}


Precautions:

1. Double-check the connections before powering on the circuit.

2. Don’t use loose jumper cables.

3. Check whether the proper board is selected from Arduino IDE.

4. Ensure proper placement of sensor for correct working.

5. Try it with different colours and see the change in values.


Conclusion:


You can successfully identify different colours using this sensor and can be deployed for many other purposes like item sorting, Rubiks cube solving etc.


Output:


Situation Screenshot: Serial Monitor (Ctrl+Shift+M)


BLUE : GREEN : RED





GET IN TOUCH

We'd love to hear from you

bottom of page