Arduino Colorsensor TCS230

I want to detect colors with the Arduino

My Code:

// here it begins

#define SENSOR_S0 5
#define SENSOR_S1 4
#define SENSOR_S2 7
#define SENSOR_S3 6
#define SENSOR_OUT 8

int frequencyR=0;
int frequencyG=0;
int frequencyB=0;

void setup() {
// put your setup code here, to run once:
pinMode(SENSOR_S0, OUTPUT);
pinMode(SENSOR_S1, OUTPUT);
pinMode(SENSOR_S2, OUTPUT);
pinMode(SENSOR_S3, OUTPUT);
pinMode(SENSOR_OUT, INPUT);

// Setting frequency- to 20%
digitalWrite(SENSOR_S0, HIGH);
digitalWrite(SENSOR_S1, LOW);

Serial.begin(4800);
}

void loop() {
// put your main code here, to run repeatedly:
// Setting RED filtered photodiodes to be read
digitalWrite(SENSOR_S2, LOW);
digitalWrite(SENSOR_S3, LOW);
frequencyR = pulseIn(SENSOR_OUT, LOW);// Reading the output frequency

// Setting GREEN filtered photodiodes to be read
digitalWrite(SENSOR_S2, HIGH);
digitalWrite(SENSOR_S3, HIGH);
frequencyG = pulseIn(SENSOR_OUT, LOW);

// Setting BLUE filtered photodiodes to be read
digitalWrite(SENSOR_S2, LOW);
digitalWrite(SENSOR_S3, HIGH);
frequencyB = pulseIn(SENSOR_OUT, LOW);

delay(500);

Serial.print("RGB: ");
Serial.print(frequencyR);
Serial.print( " " );
Serial.print(frequencyG);
Serial.print( " " );
Serial.println(frequencyB);
}

My question

I wonder how I could detect yellow light or other types of colors than RGB...

Colors (frequencies) are detected and sized by a color sensor. All colors will be different from other projects. Adjust your sketch colors for your project. You can see a simulation (here). Colors are detected toward the bottom of the sketch.

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