RGB sensor returns to close each other R, G, and B values

I mounted an RGB sensor based on TCS230 module both on a NANO (clone) and on an UNO (original). same result: R, G, B values to close each other (in terms of few units, no matter the card color presented).

Datasheet attached for TCS230, but I do not know more about the module itself.

Wiring is:

Sensor-> Arduino

S0->GND
S1->5V
S2->pin 7
S3->pin 8
Out->pin 4
VCC->5V
GND->GND
Actually they are 2 GNDs on the sensor, I connected both to GND of the board.

I used the following code, based on Paul McWorther video lesson on you tube:

 //Measuring RGB
int S2=7;
int S3=8;
int outPin=4;
unsigned long int pulseWidth;
int rColorStrength;
int gColorStrength;
int bColorStrength;

void setup() {
Serial.begin(9600);
pinMode(S2,OUTPUT);
pinMode(S3,OUTPUT);
pinMode(outPin,INPUT);
}

void loop() {

// Read RED =>  S2 = LOW and S3 =LOw (from the combination of parameters to tell the sensor which color I want to measure) 
digitalWrite(S2,LOW);
digitalWrite(S3,LOW);
pulseWidth=pulseIn(outPin,LOW);
rColorStrength=pulseWidth/400.-1;
rColorStrength=255-rColorStrength;

 // Read GREEN =>  S2 = HIGH and S3 = HIGH (from the combination of parameters to tell the sensor which color I want to measure) 
digitalWrite(S2,HIGH);
digitalWrite(S3,HIGH);
pulseWidth=pulseIn(outPin,LOW);
gColorStrength=pulseWidth/400.-1;
gColorStrength=255-gColorStrength;

 // Read BLUE =>  S2 = LOW and S3 = HIGH (from the combination of parameters to tell the sensor which color I want to measure) 
digitalWrite(S2,LOW);
digitalWrite(S3,HIGH);
pulseWidth=pulseIn(outPin,LOW);
bColorStrength=pulseWidth/400.-1;
bColorStrength=255-bColorStrength;

// Print the RGB values (0 to 255)on the serial monitor
Serial.print(rColorStrength);
Serial.print(" , ");
Serial.print(gColorStrength);
Serial.print(" , ");
Serial.print(bColorStrength);
Serial.println(" ");
delay(300);

}

The RGB values I got are very very close each other: 243 - 253, no matter the color, red being usually the largest value, no matter the color of the card presented.

Question is:

a) Is this situation related to code/wiring or I just got a poor quality sensor? (thus nothing to be done)

Side question is:

b) Do you have any idea how can I measure in a simple yet accurate manner R, G, B using for instance separate R, G and B sensors (e.g. d.i.y. ones)?

Thank you for helping a poor Robocat to find his food!
+++

I need the RGB spectrum to:

  • make my Robo-cat recognize the food (he is still starving >:( :slight_smile: )
  • evaluate the tree foliage health (future project)

In need the spectrum to be available it on-site, to be processed by the Arduino code itself.

tcs230.pdf (121 KB)

It usually works best to start off with a library that's specifically made for whatever sensor you have, like this TCS230 library. Just google for " arduino library", that's what I did just now for your sensor and this link is the first result.
In many cases I've been able to get sensors which require quite complex interfaces (e.g. the DHT22) to work in minutes.