
Colour Detection with the TCS3200
Intermediate30 minA circuit that tells the colour of an object held in front of it. The TCS3200 board measures light through red, green and blue filtered photodiodes and puts out the chosen colour's strength as a square wave; the Arduino times the three colours' pulses with pulseIn, prints them to the Serial Monitor and names the strongest. It teaches choosing a filter with digital pins and timing pulses. No extra library needed.

What you need
Wiring steps
- 1
Power the sensor

Plug a red jumper wire into the 5V pin on the Arduino's POWER header and its other end onto the sensor board's Vcc pin; a black one from the GND pin at the start of the digital pins (next to pin 13) to the board's Gnd pin. Once the Arduino is on USB, the board's four white LEDs light up: they light the object. Leave the OE pin free for now.
- Arduino 5V → TCS3200 Vcc (red wire)
- Arduino GND → TCS3200 Gnd (black wire)
- 2
Wire the frequency scaling

Run a yellow wire from the Arduino's pin 4 to the board's S0 pin and a green one from pin 5 to S1. These two pins scale the sensor's output frequency down: the code sets S0 HIGH and S1 LOW for 20%, slow enough for the Arduino to time the pulses easily.
- Arduino pin 4 → TCS3200 S0 (yellow wire)
- Arduino pin 5 → TCS3200 S1 (green wire)
- 3
Wire the colour filter pins

Run an orange wire from pin 6 to S2 and a cyan one from pin 7 to S3. These two choose which colour the sensor looks at: both LOW opens the red filter, both HIGH the green one, S2 LOW with S3 HIGH the blue one. The code picks the three in turn and measures each.
- Arduino pin 6 → TCS3200 S2 (orange wire)
- Arduino pin 7 → TCS3200 S3 (cyan wire)
- 4
Wire the output

Run a purple wire from the board's Out pin to the Arduino's pin 8. The sensor puts out the chosen colour's strength on this pin as a square wave: the stronger the colour, the shorter the pulses. The Arduino times them with pulseIn.
- Arduino pin 8 → TCS3200 Out (purple wire)
Arduino sketch
#define S0 4
#define S1 5
#define S2 6
#define S3 7
#define SENSOR_OUT 8
// How long a pulse lasts through the
// chosen filter (microseconds). Smaller:
// more of that colour. 0: no pulse came.
int readColour(int s2, int s3) {
digitalWrite(S2, s2);
digitalWrite(S3, s3);
// Let the sensor settle on the filter
delay(20);
return pulseIn(SENSOR_OUT, LOW, 100000);
}
void setup() {
pinMode(S0, OUTPUT);
pinMode(S1, OUTPUT);
pinMode(S2, OUTPUT);
pinMode(S3, OUTPUT);
pinMode(SENSOR_OUT, INPUT);
// Output scale 20%: S0 HIGH, S1 LOW
digitalWrite(S0, HIGH);
digitalWrite(S1, LOW);
Serial.begin(9600);
}
void loop() {
int red = readColour(LOW, LOW);
int green = readColour(HIGH, HIGH);
int blue = readColour(LOW, HIGH);
Serial.print("R: ");
Serial.print(red);
Serial.print(" G: ");
Serial.print(green);
Serial.print(" B: ");
Serial.print(blue);
// The colour with the shortest pulse
// is the one the object is closest to.
if (red == 0 || green == 0 || blue == 0) {
Serial.println(" -> ?");
} else if (red < green && red < blue) {
Serial.println(" -> R");
} else if (green < red && green < blue) {
Serial.println(" -> G");
} else {
Serial.println(" -> B");
}
delay(500);
}
What the Serial Monitor shows
R: 38 G: 112 B: 95 -> R R: 37 G: 110 B: 93 -> R
If a wire is loose
R: 0 G: 0 B: 0 -> ?
What you will see
Hold a red object 1-2 cm in front of the sensor and the R value is the smallest, the line ending in “-> R”; a green object gives “-> G”, a blue one “-> B”. The numbers change with the room's light and the distance; what counts is how the three compare. If it keeps printing “R: 0 G: 0 B: 0”, check the Out wire and connect the OE pin to GND with a wire.
Similar projects
Level Measurement with a Water Level SensorBeginner15 minA starter project that reads the water level sensor's analog output and writes the level as Empty, Low, Medium or High to the Serial Monitor once a second. As the sensor's parallel tracks go under water, the resistance drops and the reading rises. The thresholds (100, 400, 450) depend on the water's conductivity and the sensor; watching the raw values first and setting your own thresholds gives better results. Only dip the lower part with the tracks in water; keep the electronics and pins at the top dry. To reduce corrosion, do not leave the sensor powered all the time. No extra library needed.Open project
Traffic LightBeginner20 minA real traffic light with three LEDs: red, red + yellow, green and yellow light up in the order used in Turkey, and each stage is also written to the Serial Monitor. It teaches driving several outputs in turn, timing with digitalWrite and delay, and gathering a repeated job into its own function. You can change how long each light stays on with the constants in the code. No extra library needed.Open project
LPG Gas Measurement with the MQ-5 (PPM)Intermediate30 minA project that reads the MQ-5 gas sensor's analog output, turns it into a voltage and the sensor's present resistance (Rs), measures Ro itself in clean air at start-up, and writes an estimated LPG concentration (PPM), worked out with the LPG curve in the MQ-5 datasheet, to the Serial Monitor every two seconds. At start-up it waits 10 seconds for the heater to settle, then calibrates for 5 seconds: the sensor must be in clean air then, with no gas near it. In clean air the Rs/Ro ratio is about 6.5 and the PPM below 1; with gas around, the ratio drops and the PPM rises clearly. The PPM value is an estimate: by its datasheet, a new sensor gives steady readings only after more than 24 hours of heating on first use. No extra library needed.Open project
In the app, tick off every wire, match the parts to your inventory and pick up where you left off.
