TCS3200 Color Sensor with Arduino — Complete Guide for Students in Pakistan

Are you working on student projects, engineering projects, or industrial automation? The TCS3200 color sensor is a powerful and versatile tool that can elevate your projects to the next level. Whether you're a student in Lahore, an engineer in Pakistan, or a hobbyist exploring components on Hall Road, this blog will guide you through everything you need to know about the TCS3200 color sensor. At QKZee Technologies, we provide top-notch services and consultation to help you succeed in your projects.

What is the TCS3200 Color Sensor?

The TCS3200 is a programmable color sensor that detects the red, green, and blue (RGB) components of light reflected from an object. It converts this information into a frequency signal that can be read by a microcontroller, such as an Arduino. This makes it an ideal choice for school projects, final year projects, and professional applications in automation and robotics.

Inside the sensor is an 8×8 array of photodiodes: 16 with a red filter, 16 with a green filter, 16 with a blue filter, and 16 with no filter (clear). Two pins (S2 and S3) choose which filter is active, and the OUT pin gives a square wave whose frequency depends on how much of that colour the sensor sees. The Arduino measures that frequency with pulseIn() — and from the three frequencies, it works out the colour.

For the full sensor comparison, see our best Arduino sensors guide.

How to Connect the TCS3200 with Arduino

Wiring Diagram

To connect the TCS3200 color sensor to an Arduino, follow these steps:

TCS3200 PinArduino Pin
VCC5V
GNDGND
S0D8
S1D9
S2D10
S3D11
OUTD12
TCS3200 color sensor wiring with Arduino UNO

Steps

  1. Connect the VCC pin of the TCS3200 to the 5V pin on the Arduino.
  2. Connect the GND pin of the TCS3200 to the GND pin on the Arduino.
  3. Connect the S0, S1, S2, and S3 pins to digital pins D8, D9, D10, and D11 respectively. These pins control the frequency scaling and filter selection.
  4. Connect the OUT pin to digital pin D12 on the Arduino. This pin will read the frequency output from the sensor.

How the Pins Work

  • S0 and S1 — frequency scaling: LOW/LOW = output off, LOW/HIGH = 2%, HIGH/LOW = 20%, HIGH/HIGH = 100%. Use 20% (S0 HIGH, S1 LOW) for most projects — 100% can give frequencies too fast for pulseIn() to measure reliably.
  • S2 and S3 — colour filter: LOW/LOW = red, LOW/HIGH = blue, HIGH/HIGH = green, HIGH/LOW = clear (no filter). The sketch below reads all three colours one after another by switching S2/S3.

Arduino Code

Here's a simple Arduino code to read and interpret colors using the TCS3200 sensor:

// TCS3200 colour sensor — read R, G, B with pulseIn()
// S0 = D8, S1 = D9 (scaling), S2 = D10, S3 = D11 (filter), OUT = D12

const int S0 = 8;
const int S1 = 9;
const int S2 = 10;
const int S3 = 11;
const int OUT = 12;

void setup() {
  Serial.begin(9600);
  pinMode(S0, OUTPUT);
  pinMode(S1, OUTPUT);
  pinMode(S2, OUTPUT);
  pinMode(S3, OUTPUT);
  pinMode(OUT, INPUT);

  // Frequency scaling: 20% (S0 HIGH, S1 LOW)
  digitalWrite(S0, HIGH);
  digitalWrite(S1, LOW);
}

int readColour(int s2, int s3) {
  digitalWrite(S2, s2);
  digitalWrite(S3, s3);
  delay(100);  // let the sensor settle on the new filter
  return pulseIn(OUT, LOW);
}

void loop() {
  int red   = readColour(LOW, LOW);    // red filter
  int blue  = readColour(LOW, HIGH);   // blue filter
  int green = readColour(HIGH, HIGH);  // green filter

  Serial.print("R: ");
  Serial.print(red);
  Serial.print("  G: ");
  Serial.print(green);
  Serial.print("  B: ");
  Serial.println(blue);

  // The LOWEST frequency means the STRONGEST colour
  // (more light of that colour = higher frequency = shorter pulse)
  if (red < green && red < blue) {
    Serial.println("Detected: RED");
  } else if (green < red && green < blue) {
    Serial.println("Detected: GREEN");
  } else if (blue < red && blue < green) {
    Serial.println("Detected: BLUE");
  } else {
    Serial.println("Detected: unclear — check the light");
  }

  delay(500);
}

How to read the numbers: pulseIn() measures the length of one LOW pulse in microseconds. More light of a colour means a higher frequency, which means a SHORTER pulse — so the smallest number is the strongest colour. A red card gives the smallest number on the red filter; a green card gives the smallest on the green filter. If all three numbers are nearly equal, the sensor is seeing white, grey, or no clear colour — check the lighting (see FAQ Q1).

Key Features

  • RGB colour detection — reads red, green and blue separately
  • Frequency output — no ADC needed, the Arduino measures timing
  • Programmable scaling — 2%, 20% or 100% output frequency
  • 5V operation — works straight from the Arduino's 5V pin
  • Small and cheap — ideal for student projects and sorting machines

Applications

  • Colour sorting machines — sort objects by colour on a conveyor
  • Line followers — follow a coloured line instead of a black one
  • Smart agriculture — check fruit ripeness by colour
  • Quality control — detect wrong-coloured parts on a production line
  • Student projects — a strong final year project on its own, or combined with a robot car (see our ultrasonic sensor project for the robot base)

Where to Buy the Parts

The full build costs Rs 3,455. To display the detected colour on an LCD, see our LCD & keypad projects guide.

Still Stuck?

If all three readings look the same, the sensor gives nonsense numbers, or the detected colour is always wrong, message us on WhatsApp and we'll help you debug it — or watch the build on our YouTube channel.

Chat on WhatsApp Watch on YouTube

Frequently Asked Questions

Q1: Why do all three readings look the same?

Almost always the light. The sensor reads reflected light, so it needs bright, even, white light on the object — a desk lamp right above it works. In a dim room, or under yellow room lighting, all three filters see nearly the same thing. Also check that the sensor is close to the object (2–5 cm) and that S2/S3 are actually changing — a loose wire on D10 or D11 leaves the filter stuck on one colour.

Q2: Why does the sensor need light? Can't it work in the dark?

No. The TCS3200 does not emit light — it only measures the light bouncing off the object. In the dark there is nothing to measure. Some TCS3200 modules have built-in white LEDs on the board; if yours does, turn them on (they are usually wired to VCC already). If yours has no LEDs, add a bright white LED or a desk lamp above the object.

Q3: What is the difference between the TCS3200 and the TCS230?

Almost nothing — the TCS230 is the older version of the same chip, and the TCS3200 replaced it. They share the same pinout, the same S0/S1/S2/S3 logic and the same code. If a tutorial says TCS230, the wiring and sketch in this guide work exactly the same. Our shop listing covers both names.

Q4: Can the TCS3200 read any colour?

It reads red, green and blue separately, so it can tell apart clearly different colours (red, green, blue, yellow, white, black). It cannot give you an exact colour name or a hex code — the numbers depend on the light, the distance and the surface. For a sorting machine, calibrate it: hold each colour in front of the sensor, note the three numbers, and use those ranges in your code instead of guessing.

Q5: Why do the values jump around?

The sensor is sensitive to flickering light (tube lights flicker at 50 Hz) and to movement. Fix it by taking 5 readings of each colour and using the average, by keeping the sensor and the object still while reading, and by shielding the sensor from room light with a small tube or box around it. Also make sure the 20% scaling is set (S0 HIGH, S1 LOW) — at 100% the frequency can be too fast for pulseIn() to measure steadily.