Zbotic Logo Zbotic Logo
  • Home
  • Shop
  • Sale
  • 3D Print Service
  • PCB Service
  • B2B
  • Blogs
  • Contact Us
0 0

View Wishlist Add all to cart

0 0
0 Shopping Cart
Shopping cart (0)
Subtotal: ₹0.00

View cartCheckout

  • Shop
  • About Us
  • Contact Us
  • Reseller
  • Blogs
020 69134444
1800 209 0998
[email protected]
Help Desk
Facebook Twitter Instagram Linkedin YouTube
Zbotic Logo Zbotic Logo
0 0

View Wishlist Add all to cart

0 0
0 Shopping Cart
Shopping cart (0)
Subtotal: ₹0.00

View cartCheckout

All departments
  • 3D Print Service
  • 3D Printer
  • Batteries & Chargers
  • Development Boards
  • Drone Parts
  • EBike parts
  • Sensor Modules
  • Electronic Components
  • Electronic Modules
  • IoT and Wireless
  • Mechanical Parts and Workbench Tools
  • Motors & Drivers & Pumps & Actuators
  • DIY and Robot Kits
  • Show more
  • Home
  • Shop
  • Sale
  • 3D Print Service
  • PCB Service
  • B2B
  • Blogs
  • Contact Us
Return to previous page
Home Sensors & Modules

Colour Sensor TCS3200: Sorting Machine Project with Arduino

Colour Sensor TCS3200: Sorting Machine Project with Arduino

April 1, 2026 /Posted by / 0

The TCS3200 colour sensor detects the colour of objects by shining white LEDs onto a surface and measuring the reflected light through red, green, blue, and clear filters. Combined with an Arduino and a servo motor, you can build a colour sorting machine that separates objects by colour — a popular engineering project for college submissions and a genuinely useful concept in industrial quality inspection. This guide covers sensor wiring, colour detection code, and a complete candy sorting machine build.

Table of Contents

  • How the TCS3200 Colour Sensor Works
  • Wiring to Arduino
  • Reading RGB Values
  • Calibrating for Accurate Detection
  • Building the Colour Sorting Machine
  • Other Applications
  • Frequently Asked Questions

How the TCS3200 Colour Sensor Works

The TCS3200 has an 8×8 array of 64 photodiodes: 16 with red filters, 16 with green filters, 16 with blue filters, and 16 with clear (no filter). Four white LEDs illuminate the target surface. You select which filter to read using two control pins (S2, S3). The sensor outputs a square wave whose frequency is proportional to light intensity for the selected colour channel.

By reading the frequency for red, green, and blue channels, you get an RGB colour breakdown of whatever object is in front of the sensor. A red object will have a much higher red frequency compared to green and blue.

Pin Configuration

Pin Function Arduino Connection
S0, S1 Output frequency scaling D4, D5 (set to HIGH, HIGH for 100%)
S2, S3 Filter selection D6, D7
OUT Frequency output D8
OE Output enable (active LOW) GND (always enabled)
VCC Power 5V
GND Ground GND
🛒 Recommended: Browse TCS3200 colour sensors at Zbotic — Complete modules with built-in white LEDs for illumination.

Wiring to Arduino

// Pin definitions
const int S0 = 4;
const int S1 = 5;
const int S2 = 6;
const int S3 = 7;
const int sensorOut = 8;

void setup() {
  pinMode(S0, OUTPUT);
  pinMode(S1, OUTPUT);
  pinMode(S2, OUTPUT);
  pinMode(S3, OUTPUT);
  pinMode(sensorOut, INPUT);

  // Set frequency scaling to 100%
  digitalWrite(S0, HIGH);
  digitalWrite(S1, HIGH);

  Serial.begin(9600);
}

Reading RGB Values

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

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

  // Identify colour
  if (red < green && red  RED detected");
  } else if (green < red && green  GREEN detected");
  } else if (blue < red && blue  BLUE detected");
  } else {
    Serial.println("=> Unknown colour");
  }

  delay(500);
}

int readColour(int s2State, int s3State) {
  digitalWrite(S2, s2State);
  digitalWrite(S3, s3State);
  delay(20); // Allow settling
  int frequency = pulseIn(sensorOut, LOW);
  return frequency;
}

Note: Lower frequency values mean stronger colour presence. A red object reflects more red light, giving a lower red frequency compared to green and blue. This is counterintuitive — lower number = more of that colour.

Calibrating for Accurate Detection

For reliable colour detection, calibrate against your specific objects:

  1. Place a white surface 1-2 cm from the sensor. Record R, G, B values — these are your maximum (most light reflected) values.
  2. Place a black surface. Record R, G, B — these are your minimum values.
  3. Map raw frequencies to 0-255 range using these calibration points.
  4. Test with your actual objects (candy colours, component colours, etc.) and note the RGB ranges for each colour you want to detect.
// Calibration constants (from white and black reference)
const int RED_MIN = 25, RED_MAX = 220;
const int GREEN_MIN = 30, GREEN_MAX = 250;
const int BLUE_MIN = 25, BLUE_MAX = 200;

int mapColour(int raw, int minVal, int maxVal) {
  int mapped = map(raw, minVal, maxVal, 255, 0); // Inverted!
  return constrain(mapped, 0, 255);
}

Building the Colour Sorting Machine

Here’s a complete colour sorting machine that detects objects (candies, marbles, beads) sliding down a chute and directs them into the correct bin using a servo motor.

Components Needed

  • TCS3200 colour sensor module — ₹150-250
  • Arduino Uno — ₹400
  • SG90 servo motor — ₹60
  • IR obstacle sensor (for object detection) — ₹40
  • Cardboard or 3D-printed chute and bins — ₹0-200
  • Total: ₹650-950
#include <Servo.h>

const int S0 = 4, S1 = 5, S2 = 6, S3 = 7;
const int sensorOut = 8;
const int irSensor = 2; // Object detection
Servo sortServo;

// Servo positions for 3 bins
const int BIN_RED = 30;
const int BIN_GREEN = 90;
const int BIN_BLUE = 150;

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

  digitalWrite(S0, HIGH); digitalWrite(S1, HIGH);
  sortServo.attach(9);
  sortServo.write(90); // Centre position
}

void loop() {
  // Wait for object to arrive
  if (digitalRead(irSensor) == LOW) { // Object detected
    delay(200); // Let object settle over sensor

    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.println(blue);

    // Sort based on dominant colour
    if (red < green && red < blue) {
      Serial.println("Sorting: RED");
      sortServo.write(BIN_RED);
    } else if (green < red && green < blue) {
      Serial.println("Sorting: GREEN");
      sortServo.write(BIN_GREEN);
    } else {
      Serial.println("Sorting: BLUE");
      sortServo.write(BIN_BLUE);
    }

    delay(500);  // Wait for object to fall into bin
    sortServo.write(90); // Return to centre
    delay(300);
  }
}

int readColour(int s2, int s3) {
  digitalWrite(S2, s2); digitalWrite(S3, s3);
  delay(20);
  return pulseIn(sensorOut, LOW);
}
🛒 Recommended: HC-SR04 Ultrasonic Sensor — Use as an alternative object detection method in the sorting chute, especially for larger objects.

Other Applications

1. Paint Colour Matching

Point the sensor at a wall sample and get the RGB values. Map these to the nearest paint brand colour code. Useful for finding matching paint when repainting a section.

2. Fruit Ripeness Detection

Bananas change from green to yellow to brown. Tomatoes go from green to red. The TCS3200 can detect these colour changes, making it useful for agricultural sorting and automated ripeness grading.

3. Quality Inspection

In manufacturing, colour consistency matters — PCB solder joint colour indicates quality, food products must match colour standards, and packaging must be consistent. The TCS3200 provides an affordable inspection sensor for small-scale production.

🛒 Recommended: LM35 Temperature Sensor — Add temperature monitoring to your quality inspection system, since colour sensor readings can shift with temperature changes in the LEDs.

Frequently Asked Questions

How close should the sensor be to the object?

Optimal distance is 1-2 cm. Too close and the white LEDs may not uniformly illuminate the surface. Too far and ambient light interferes. For consistent results, use a tube or enclosure around the sensor that blocks ambient light and maintains a fixed distance to the object.

Can the TCS3200 detect any colour?

It detects RGB components, so it can distinguish any colour that has distinct RGB ratios. Saturated colours (pure red, green, blue, yellow) are easy. Pastels and dark shades are harder because the RGB differences are smaller. Black objects reflect very little light on all channels, making them hard to distinguish from dark brown or navy blue.

Why do my readings change with ambient light?

External light adds to the reflected light from the sensor’s LEDs. Always shield the sensor from ambient light using a tube or box. The sensor should rely only on its own white LEDs for illumination.

Can I detect more than three colours?

Yes. With proper calibration, you can distinguish 5-8 colours reliably. Define RGB ranges for each target colour based on testing, and use distance-based matching (compare the measured RGB vector to each known colour’s RGB vector) instead of simple “which channel is lowest” logic.

Conclusion

The TCS3200 colour sensor module is an engaging project component that teaches digital signal processing, calibration, and closed-loop control. A colour sorting machine built with a TCS3200, servo, and Arduino makes an excellent engineering project that demonstrates practical automation concepts. The sensor costs about ₹150-250 and works reliably with proper calibration and ambient light shielding.

Find TCS3200 colour sensors and project components at Zbotic’s sensor collection.

Tags: Arduino, color sensor, Sensors, Sorting, TCS3200
Share Post
  • Facebook
  • Linkedin
  • Whatsapp
Raspberry Pi Kiosk Mode: Touch...
blog raspberry pi kiosk mode touchscreen information display 612789
blog caterpillar track robot tank drive build for all terrain 612793
Caterpillar Track Robot: Tank-...

Related posts

Svg%3E
Read more

Encoder Module: Position and Speed Measurement with Arduino

April 1, 2026 0
A rotary encoder converts the angular position and rotation speed of a shaft into electrical signals that Arduino can count... Continue reading
Svg%3E
Read more

Infrared Obstacle Sensor: Line Follower and Object Detection

April 1, 2026 0
Infrared obstacle sensors are the building blocks of line-following robots, edge detection systems, and proximity triggers. These tiny modules emit... Continue reading
Svg%3E
Read more

Rain Sensor and Raindrop Detection Module: Arduino Guide

April 1, 2026 0
A rain sensor module detects the presence of water droplets on its surface, giving Arduino a simple signal to trigger... Continue reading
Svg%3E
Read more

LiDAR Sensor TFmini: Distance Measurement Beyond Ultrasonic

April 1, 2026 0
When ultrasonic sensors hit their limits — range too short, accuracy too coarse, outdoor sunlight causing interference — LiDAR sensors... Continue reading
Svg%3E
Read more

Pressure Sensor BMP280: Weather Station and Altitude Meter

April 1, 2026 0
The BMP280 barometric pressure sensor by Bosch measures atmospheric pressure with ±1 hPa accuracy and temperature with ±1°C precision. These... Continue reading

Add comment Cancel reply

Your email address will not be published. Required fields are marked

Facebook Twitter Instagram Pinterest Linkedin Youtube

Get the latest deals and more.

Download on Google Play Download on the App Store

Call us: 020 69134444 / 1800 209 0998

Monday - Saturday 09:30 AM - 06:00 PM
For Technical Supports Email: [email protected]
For Sales / Enquiries Email: [email protected]

  • My Account

    • Cart

    • Wishlist

    • Checkout

    • My Orders

    • Track Order

    • My Account

  • Information

    • FAQs

    • Blogs

    • Career

    • About Us

    • Contact Us

    • Payment Options

  • Policies

    • Privacy Policy

    • Terms & Conditions

    • GST Input Tax Credit

    • Shipping Return Policy

    • E-Waste Collection Points

    • Our Sitemap

© Zbotic.in is registered trademark of Moxie Supply Pvt Ltd – All Rights Reserved
Login
Use Phone Number
Use Email Address
Not a member yet? Register Now
Reset Password
Use Phone Number
Use Email Address
Register
Already a member? Login Now
Chat with us