In this article, we are going to read the colors using the TCS230 color sensor (RGB Sensor) and Arduino Uno. The TCS 230 color sensor senses the color light by using the photodiodes. The sensor converts the readings from the photodiode into a square wave by using the light to frequency converter. The frequency of these waves is directly proportional to the light intensity. Then the Arduino reads these square waves and gives us the values of the RGB colors. So let’s begin our tutorial on Interfacing Arduino and RGB Color Sensor TCS230.

Pin out – TCS230 (RGB Color Sensor)




If you take a closer look at the sensor, you will see that it contains an array of photodiodes which are used to sense the color light. The sensor also consists of four LED lights.

The sensor has 10 pins; S0, S1 are for setting the frequency and S2, S3 are for reading the color values. The out pin is supposed to give the output to Arduino in the form of a square wave. The other pins are for powering the sensor.

Working of RGB Color Sensor

TCS230 color sensor consists of an 8X8 array of photodiodes. These photodiodes include three different color filters. 16 of them are red, 16 of them are green, 16 of them are blue and 16 of them are clear Every 16 photodiodes are connected in parallel. So, if we want to read colors, then we can read them by using the S2 and S3 pins. The pin combination for reading is RGB colors as follows

S2 S3 Color
LOW LOW Red
LOW HIGH Blue
HIGH LOW Clear
HIGH HIGH Green
If you like First of all, we have the red color by making both the S2 and S3 pin low. Then, we read the green color by making both the pins high and finally, we read the blue color by making the S2 pin low and S3 pin high. After that, we will map these values ​​to 0-255 and show the color values ​​on the serial monitor.

The sensor also has two more pins which are S0 and S1 These pins are used to set the frequency to 0%, 2%, 20% or 100%. The pin combination for setting

S0 S1 Output Frequency
LOW  LOW 0%
LOW HIGH 2%
HIGH  LOW 20%
HIGH HIGH 100%
In our code, the frequency is set at 20%. You can set the frequency to any other value, but the output values ​​will change according to the set frequency and you have set frequency associated with color values.

Circuit Diagram and Explanation

The connections of Arduino with the color sensor TCS230 is as given below:

TCS230 Arduino Uno
VCC 5V
GND GND
S0 Pin 8
S1 Pin 9
S2 Pin 12
S3 Pin 11
OUT Pin 10

Code/Program – Arduino Color Sensor Interfacing

int s0_pin = 8;

int s1_pin = 9;

int s2_pin = 12;

int s3_pin = 11;

int out_pin = 10;


void setup () {

Serial.begin (9600);

pinMode (s0_pin, OUTPUT);

pinMode (s1_pin, OUTPUT);

pinMode (s2_pin, OUTPUT);

pinMode (s3_pin, OUTPUT);

pinMode (out_pin, INPUT);

digitalWrite (s0_pin, HIGH);

digitalWrite (s1_pin, LOW);

}


void loop () {

digitalWrite (s2_pin, LOW);

digitalWrite (s3_pin, LOW);

int red_color = pulseIn (out_pin, LOW);

red_color = map (red_color, 25,72,255,0);

delay (50);

digitalWrite (s2_pin, HIGH);

digitalWrite (s3_pin, HIGH);

int green_color = pulseIn (out_pin, LOW);

green_color = map (green_color, 30,90,255,0);

delay (50);

digitalWrite (s2_pin, LOW);

digitalWrite (s3_pin, HIGH);

int blue_color = pulseIn (out_pin, LOW);

blue_color = map (blue_color, 25,70,255,0);

delay (50);

Serial.print ("RED:");

Serial.print (red_color);

Serial.print ("");

Serial.print ("GREEN:");

Serial.print (green_color);

Serial.print ("");

Serial.print ("BLUE:");

Serial.print (blue_color);

Serial.println ("");

delay (1000);

}


No comments

Theme images by Dizzo. Powered by Blogger.