Calibration sensor tcs3200

I have a color sensor experiment. how do I calibrate the tcs3200 sensor to match the rgb standard and the program code?
I have tried using red, green, blue, black and white color paper. but it can't match the standard example on red (255,145,169) should be (255,0,0).

#include <Wire.h>

// TCS3200 color sensor wiring
#define S0 2
#define S1 3
#define S2 4
#define S3 5
#define sensorOut 6
#define LED 7

void setup() {
  pinMode(S0, OUTPUT);
  pinMode(S1, OUTPUT);
  pinMode(S2, OUTPUT);
  pinMode(S3, OUTPUT);
  pinMode(sensorOut, INPUT);
  pinMode(LED, OUTPUT);

  digitalWrite(LED, HIGH);

  // Setting frequency-scaling to 20%
  digitalWrite(S0, HIGH);
  digitalWrite(S1, LOW);

  Serial.begin(9600); // use the serial port to print out the resultant data
}

void loop() {
  readTCS3200();
}

// Function to read data from TCS3200 sensor
void readTCS3200() {
  // Calibration values
  int redMin = 50, redMax = 346;
  int greenMin = 85, greenMax = 348;
  int blueMin = 40, blueMax = 262;
  int clearMin = 0, clearMax = 500;

  int redPW, greenPW, bluePW, clearPW;
  int redValue, greenValue, blueValue, clearValue;
  const unsigned long timeout = 1000000; // 1 second timeout for pulseIn

  // Read Red Pulse Width
  digitalWrite(S2, LOW);
  digitalWrite(S3, LOW);
  redPW = pulseIn(sensorOut, LOW, timeout);
  redValue = map(redPW, redMin, redMax, 255, 0);
  Serial.print("Raw Red: "); Serial.print(redPW);
  Serial.print(" Mapped Red: "); Serial.println(redValue);

  // Read Green Pulse Width
  digitalWrite(S2, HIGH);
  digitalWrite(S3, HIGH);
  greenPW = pulseIn(sensorOut, LOW, timeout);
  greenValue = map(greenPW, greenMin, greenMax, 255, 0);
  Serial.print("Raw Green: "); Serial.print(greenPW);
  Serial.print(" Mapped Green: "); Serial.println(greenValue);

  // Read Blue Pulse Width
  digitalWrite(S2, LOW);
  digitalWrite(S3, HIGH);
  bluePW = pulseIn(sensorOut, LOW, timeout);
  blueValue = map(bluePW, blueMin, blueMax, 255, 0);
  Serial.print("Raw Blue: "); Serial.print(bluePW);
  Serial.print(" Mapped Blue: "); Serial.println(blueValue);

  // Read Clear Pulse Width
  digitalWrite(S2, HIGH);
  digitalWrite(S3, LOW);
  clearPW = pulseIn(sensorOut, LOW, timeout);
  clearValue = map(clearPW, clearMin, clearMax, 255, 0);
  Serial.print("Raw Clear: "); Serial.print(clearPW);
  Serial.print(" Mapped Clear: "); Serial.println(clearValue);
}

What standard?

Reflective color depends extremely strongly on characteristics of the illumination. "Red paper" looks red only under certain types of lighting, e.g. "white" light.

Furthermore, the meaning of (255,0,0) depends very strongly on the characteristics of the sensor you are using. Study the data sheet of the TCS3200 to learn about what wavelength ranges of light are detected.

In particular, notice that the R, G and B photodiodes are all about equally sensitive to Near Infrared (NIR) light, in the wavelength range of 800-1000 nm.

Capture

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.