I used the TCS3200 sensor to read the RGB color values.First, I calibrated the sensor with white and black colors.The sensor detects red, blue, and green correctly, but does not give an accurate value.For example, green is 105 190 150 instead of 0 255 0 . I have to recognize the brown copper with the RGB value 138 73 49 .But it seems that I can not recognize this color with this method.I will be grateful if you can guide me.
#define S0 4
#define S1 5
#define S2 6
#define S3 7
#define sensorOut 8
int redPW = 0 ;
int greenPW = 0 ;
int bluePW = 0 ;
void setup() {
// Set S0 - S3 as outputs
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,LOW);
Serial.begin(9600);
}
void loop() {
// Calibration Values
int redMin=40;// Red minimum value
int redMax=470;//346 Red maximum value
int greenMin=40;// Green minimum value
int greenMax=510;//348 Green maximum value
int blueMin=30;// Blue minimum value
int blueMax=390;//262 Blue maximum value
int redValue;
int greenValue;
int blueValue;
//Read Red Pulse Width
digitalWrite(S2,LOW);
digitalWrite(S3,LOW);
// Read the output Pulse Width
redPW = pulseIn(sensorOut,LOW);
redValue=map(redPW, redMin,redMax,255,0);
delay(200);
// Read Green Pulse Width
digitalWrite(S2,HIGH);
digitalWrite(S3,HIGH);
// Read the output Pulse Width
greenPW = pulseIn(sensorOut,LOW);
greenValue=map(greenPW, greenMin,greenMax,255,0);
delay(200);
// Read Blue Pulse Width
digitalWrite(S2,LOW);
digitalWrite(S3,HIGH);
// Read the output Pulse Width
bluePW = pulseIn(sensorOut,LOW);
blueValue=map(bluePW, blueMin,blueMax,255,0);
delay(200);
// Print output to Serial Monitor
Serial.print("redValue = ");
Serial.print(redValue);
Serial.print(" - greenValue = ");
Serial.print(greenValue);
Serial.print(" - blueValue = ");
Serial.println(blueValue);
}