Hi its my first time posting. Im a first year electronic engineering student and doing our second lab project which is an RGB colour sensor. I have an Arduino mega R3 2560 and the colour sensor I am using is a TCS3200.
I have it set up correctly will the pin out diagram and was able to upload the code to the board.
#define S0 4
#define S1 5
#define S2 6
#define S3 7
#define sensorOut 8
int redfrequency = 0;
int greenfrequency = 0;
int bluefrequency = 0;
int blackfrequency = 0;
void setup() {
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() {
// Setting red filtered photodiodes to be read
digitalWrite(S2,LOW);
digitalWrite(S3,LOW);
// Reading the output frequency
redfrequency = pulseIn(sensorOut, LOW);
delay(100);
// Setting Green filtered photodiodes to be read
digitalWrite(S2,HIGH);
digitalWrite(S3,HIGH);
// Reading the output frequency
greenfrequency = pulseIn(sensorOut, LOW);
// Printing the value on the serial monitor
delay(100);
// Setting Blue filtered photodiodes to be read
digitalWrite(S2,LOW);
digitalWrite(S3,HIGH);
// Reading the output frequency
bluefrequency = pulseIn(sensorOut, LOW);
// Printing the value on the serial monitor
if (redfrequency>25 && redfrequency< 77) {Serial.println("RED COLOUR");} else if (bluefrequency>25 && bluefrequency< 77) {Serial.println("BLUE COLOUR");} else if (greenfrequency>25 && greenfrequency< 77)
{Serial.println("GREEN COLOUR");}
else
{Serial.println("NO COLOUR DETECTION");}
}
When I hold up blue and red colours the serial monitor can identify the colours correctly. When I try the colour green it shows up as blue. Im sure I have something wrong in the code but I only know some basic C+
Our goal for the lab is to identify the colours white,black,green,blue and red.
Any help would be appriciated.