Color Sensor

In this project, you'll learn how to connect and control the TCS230/TCS3200 color sensor to detect different colors.

Parts needed:
  • Arduino
  • A color sensor
  • Wires
Color sensor     
1 Making the connections
  • Connect S0 on the color sensor to pin 4 on the Arduino.
  • Connect S1 on the color sensor to pin 5 on the Arduino.
  • Connect S2 on the color sensor to pin 6 on the Arduino.
  • Connect S3 on the color sensor to pin 7 on the Arduino.
  • Connect OUT on the color sensor to pin 8 on the Arduino.
  • Connect EO on the color sensor to GND on the Arduino.
  • Connect GND on the color sensor to GND on the Arduino.
  • Connect VCC on the color sensor to 5V on the Arduino.
2 Create a new Bare Minimum program and type in this program.
// TCS230/TCS3200 Color Sensor
// connect EO to GND 
#define S0 4
#define S1 5
#define S2 6
#define S3 7
#define OUT 8

int frequency = 0;

void setup() {
  Serial.begin(9600);

  pinMode(S0, OUTPUT);
  pinMode(S1, OUTPUT);
  pinMode(S2, OUTPUT);
  pinMode(S3, OUTPUT);
  pinMode(OUT, INPUT);

  // Output Frequency Scaling
  // S0   S1   Scaling
  // Low  Low  Power down
  // Low  High 2%
  // High Low  20%
  // High High 100%
  digitalWrite(S0,HIGH);
  digitalWrite(S1,LOW);  
}
void loop() {
  // Setting photodiode filter color
  // S2   S3   Color
  // Low  Low  Red
  // Low  High Blue
  // High Low  Clear (no filter)
  // High High Green
  
  // Setting red filtered photodiodes to be read
  digitalWrite(S2,LOW);
  digitalWrite(S3,LOW);
  // Reading the output frequency
  frequency = pulseIn(OUT, LOW);
  //Remaping the value of the frequency to the RGB Model of 0 to 255
  //frequency = map(frequency, 25,72,255,0);
  Serial.print("R=");
  Serial.print(frequency);
  delay(100);

  // Setting Green filtered photodiodes to be read
  digitalWrite(S2,HIGH);
  digitalWrite(S3,HIGH);
  // Reading the output frequency
  frequency = pulseIn(OUT, LOW);
  //Remaping the value of the frequency to the RGB Model of 0 to 255
  //frequency = map(frequency, 30,90,255,0);
  Serial.print("  G=");
  Serial.print(frequency);
  delay(100);
  
  // Setting Blue filtered photodiodes to be read
  digitalWrite(S2,LOW);
  digitalWrite(S3,HIGH);
  // Reading the output frequency
  frequency = pulseIn(OUT, LOW);
  //Remaping the value of the frequency to the RGB Model of 0 to 255
  //frequency = map(frequency, 25,70,255,0);
  Serial.print("  B=");
  Serial.print(frequency);
  delay(100);
  
  // Setting Clear filtered photodiodes to be read
  digitalWrite(S2,HIGH);
  digitalWrite(S3,LOW);
  // Reading the output frequency
  frequency = pulseIn(OUT, LOW);
  //Remaping the value of the frequency to the RGB Model of 0 to 255
  //frequency = map(frequency, 25,70,255,0);
  Serial.print("  C=");
  Serial.println(frequency);
  delay(100);
}
4 Open the serial monitor and set the baud rate to 9600. Place different color objects in front of the sensor and observe the numbers for the Red/Green/Blue/Clear readings. The number for the matching color object will be lower than the other numbers. For example, if you place a red object in front of the sensor, the red values are lower than the other numbers. All of the numbers are low for white, and all of the numbers are high for black.