1

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);

}
4
  • I'm not sure I really get your question, but it kind of sounds like what you want is to convert RGB to HSV and compare the hue against your target's hue, mostly irrespective of value and maybe to some degree saturation as well.
    – timemage
    Jun 1 at 20:35
  • How do you perform the calibration? The spectrum of the light source is essential for the calibration! Is it a green LED?
    – Sim Son
    Jun 1 at 21:04
  • 1
    Btw, did you take a look at the spectral sensitivity of the sensor on page 5? Your reading sound reasonable for a green LED...
    – Sim Son
    Jun 1 at 21:06
  • How exactly are you calibrating a color sensor with only white and black?
    – chrisl
    Jun 1 at 21:47

1 Answer 1

0

As I said, you MUST either

  • know the spectrum of the light source that exposes your sample or
  • calibrate the sensor under the exact same light you use for detection later on.

However, the actual calibration values don't matter at all. It should be as simple as saving the value you get for copper as a reference and compare your test color with that value, including some margin, of course. Any sensor will always have specific/individual properties, like the spectral sensitivity in case of the TCS3200. But the reason of calibration is that you don't have to bother.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.