rgb color sensor tcs3200


So now I have got color sensor tcs 3200 which I have connected to arduino. I have to detect only red color. What to do?

What have you tried? What happened? How does what happened differ from what you expected?

Ok so I tried the basic code:

enum Colours {RED,GREEN,BLUE,CLEAR}; //Unumerate Colours RED,GREEN,BLUE and ClEAR

define s2Pin 2 //S2 Colour Selection inputs define and connected to arduino pin 2

define s3Pin 3 //S3 Colour Selection inputs define and connected to arduino pin 3

define outPin 4 //Output define in Arduino pin 4

void setup() { Serial.begin(9600); //Serial begin at baudrate 9600 pinMode(s2Pin, OUTPUT); //Pin Mode s2Pin as Output pinMode(s3Pin, OUTPUT); //Pin Mode s2Pin as Output pinMode(outPin, INPUT); //Pin Mode s2Pin as Input } void loop() {

Serial.print(ReadColour(RED)); //Read colors value to serial communication Serial.print(" : "); Serial.print(ReadColour(GREEN)); Serial.print(" : "); Serial.print(ReadColour(BLUE)); Serial.print(" : "); Serial.println(ReadColour(CLEAR)); }

// Function reads colours and returns the a value betwenn 0 and 255 byte ReadColour(byte Colour) { switch(Colour) { case RED: digitalWrite(s2Pin, LOW); digitalWrite(s3Pin, LOW); break;

case GREEN: digitalWrite(s2Pin, HIGH); digitalWrite(s3Pin, HIGH); break;

case BLUE: digitalWrite(s2Pin, LOW); digitalWrite(s3Pin, HIGH); break;

case CLEAR: digitalWrite(s2Pin, HIGH); digitalWrite(s3Pin, LOW); break; }

return map(pulseIn(outPin, HIGH), 30, 2500, 255, 0); //PWM map to 30,2500,255,0 }

so this code reads and gives me numbers for red,green blue.

I want to detect only red color.How to do?

You need to define the limits of what you consider to be “red”

and how do we do that?

i just want it to detect a red color object. According to the above code, it gives different value for red color every time

From the values that it gives for red, you need to decide which are acceptable to you.