Hey,
I have a project for school and im using a color sensor i need to detect 3 colors but only the last color in the code can be detected properly, the other two switch between unkown and the right color. the values of the colors are right i've changed them multiple times and it still doesn't work.this is my code.
// TCS230 or TCS3200 pins wiring to Arduino
#define S0 4
#define S1 5
#define S2 6
#define S3 7
#define sensorOut 8
#define Roodout 9
#define Groenout 10
#define Blauwout 11
// Stores frequency read by the photodiodes
int redFrequency = 0;
int greenFrequency = 0;
int blueFrequency = 0;
//Detectie van de snoepkleur
int detectRood = 0;
int detectGroen = 0;
int detectBlauw = 0;
void setup() {
// Setting the outputs
pinMode(S0, OUTPUT);
pinMode(S1, OUTPUT);
pinMode(S2, OUTPUT);
pinMode(S3, OUTPUT);
// Setting the sensorOut as an input
pinMode(sensorOut, INPUT);
// Setting frequency scaling to 20%
digitalWrite(S0, HIGH);
digitalWrite(S1, LOW);
// Begins serial communication
Serial.begin(9600);
}
void loop() {
// Setting RED (R) filtered photodiodes to be read
digitalWrite(S2, LOW);
digitalWrite(S3, LOW);
// Reading the output frequency
redFrequency = pulseIn(sensorOut, LOW);
// Setting GREEN (G) filtered photodiodes to be read
digitalWrite(S2, HIGH);
digitalWrite(S3, HIGH);
// Reading the output frequency
greenFrequency = pulseIn(sensorOut, LOW);
// Setting BLUE (B) filtered photodiodes to be read
digitalWrite(S2, LOW);
digitalWrite(S3, HIGH);
// Reading the output frequency
blueFrequency = pulseIn(sensorOut, LOW);
if ((93 <= redFrequency) && (108 >= redFrequency) && (79 <= greenFrequency) && (greenFrequency <=94 ) && (73 <= blueFrequency) && (blueFrequency <= 88)) {
Serial.println("GROEN");
detectGroen = 1;
digitalWrite(Groenout, HIGH);
delay(200);
}
if ((105 <= redFrequency) && (redFrequency <= 120) && (100 <= greenFrequency) && (greenFrequency <= 115) && (72 <= blueFrequency) && (blueFrequency <= 87)) {
Serial.println("BLAUW");
detectBlauw = 1;
digitalWrite(Blauwout, HIGH);
delay(200);
}
if ((63 <= redFrequency) && (redFrequency <= 77) && (107 <= greenFrequency) && (greenFrequency <= 122) && (89 <= blueFrequency) && (blueFrequency <= 104)) {
Serial.println("ROOD");
detectRood = 1;
digitalWrite(Roodout, HIGH);
delay(200);
}
else {
Serial.println("ONBEKEND");
detectRood = 0;
detectGroen = 0;
detectBlauw = 0;
digitalWrite(Roodout, LOW);
digitalWrite(Groenout, LOW);
digitalWrite(Blauwout, LOW);
delay(200);
}
}
Can anyone please tell me what im doing wrong? thank you already