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 Robotics & DIY

Color-Sorting Robot: TCS3200 Sensor & Servo Mechanism Build

Color-Sorting Robot: TCS3200 Sensor & Servo Mechanism Build

March 11, 2026 /Posted byJayesh Jain / 0

A color sorting robot using the TCS3200 sensor and servo mechanism with Arduino is a classic mechatronics project that demonstrates colour sensing, decision logic, and precise mechanical actuation in one compact system. Used as a demonstration of automated quality control in manufacturing, this project is popular at engineering college exhibitions across India and provides an excellent foundation for understanding industrial sorting systems. This guide covers everything from TCS3200 wiring to servo-controlled sorting gate construction.

Table of Contents

  • TCS3200 Color Sensor Overview
  • Wiring TCS3200 to Arduino
  • Colour Calibration Procedure
  • Servo-Controlled Sorting Gate
  • Complete Arduino Code
  • Adding a Conveyor Belt
  • Frequently Asked Questions

TCS3200 Color Sensor Overview

The TCS3200 (and its successor TCS34725) is a colour-to-frequency converter that converts the intensity of filtered light into a square wave output whose frequency is proportional to the detected light intensity. The IC contains an array of 8×8 photodiodes with four types of filters: red, green, blue, and no filter (clear).

How It Works:

  • White LEDs on the module illuminate the target object
  • Reflected light passes through the selected colour filter
  • The photodiode array converts light intensity to a digital frequency output
  • Arduino measures this frequency using the pulseIn() function
  • Higher frequency = more of that colour in the object

Specifications:

  • Power supply: 2.7V to 5.5V (3.3V or 5V compatible)
  • Output: Square wave (50% duty cycle) with frequency proportional to colour intensity
  • Frequency scaling: S0/S1 pins set output frequency to 100%, 20%, 2% or off
  • Filter selection: S2/S3 pins select Red, Green, Blue, or Clear filter
  • Optimal sensing distance: 1-2cm from target surface
  • Price in India: ₹80-₹150 for a module with white LED illuminators
Recommended: Waveshare General Driver Board for Robots (ESP32) — Upgrade your colour sorter from Arduino to ESP32 for faster colour detection, more servo channels, and WiFi-based monitoring of sort statistics.

Wiring TCS3200 to Arduino

The TCS3200 uses 6 digital pins:

  • TCS3200 VCC → Arduino 5V
  • TCS3200 GND → Arduino GND
  • TCS3200 S0 → Arduino Pin 4
  • TCS3200 S1 → Arduino Pin 5
  • TCS3200 S2 → Arduino Pin 6
  • TCS3200 S3 → Arduino Pin 7
  • TCS3200 OUT → Arduino Pin 8
  • TCS3200 OE → Arduino GND (tie low to enable)

Servo wiring:

  • Servo 1 (main sorting gate) → Arduino Pin 9 (PWM)
  • Servo 2 (secondary gate, optional) → Arduino Pin 10 (PWM)
  • Servo red wire (5V) → External 5V supply (do NOT power multiple servos from Arduino 5V pin)
  • Servo black/brown wire → GND (common with Arduino GND)

Colour Calibration Procedure

Calibration is essential — TCS3200 readings vary significantly based on ambient light, distance, and object surface texture. A proper calibration routine stores baseline readings for each colour and uses them for comparison.

#include <Servo.h>

// TCS3200 pins
#define S0 4
#define S1 5
#define S2 6
#define S3 7
#define OUT 8

// Calibration storage
int redMin, redMax;
int greenMin, greenMax;
int blueMin, blueMax;

void setupColorSensor() {
    pinMode(S0, OUTPUT); pinMode(S1, OUTPUT);
    pinMode(S2, OUTPUT); pinMode(S3, OUTPUT);
    pinMode(OUT, INPUT);
    
    // Set frequency scaling to 20% (good balance)
    digitalWrite(S0, HIGH);
    digitalWrite(S1, LOW);
}

int readColor(int s2val, int s3val) {
    digitalWrite(S2, s2val);
    digitalWrite(S3, s3val);
    delay(10);  // Settle time
    return pulseIn(OUT, LOW);  // Measure pulse width (inverse of frequency)
}

int readRed()   { return readColor(LOW,  LOW);  }
int readGreen() { return readColor(HIGH, HIGH); }
int readBlue()  { return readColor(LOW,  HIGH); }

void calibrate() {
    Serial.println("Calibrating... Place WHITE reference under sensor");
    Serial.println("Press enter when ready");
    while (!Serial.available()) {}  Serial.read();
    
    redMin   = readRed();
    greenMin = readGreen();
    blueMin  = readBlue();
    
    Serial.println("Now place BLACK reference under sensor");
    while (!Serial.available()) {}  Serial.read();
    
    redMax   = readRed();
    greenMax = readGreen();
    blueMax  = readBlue();
    
    Serial.println("Calibration complete!");
    Serial.print("Red range: "); Serial.print(redMin); 
    Serial.print(" - "); Serial.println(redMax);
}

String detectColor() {
    int r = map(readRed(),   redMin,   redMax,   255, 0);
    int g = map(readGreen(), greenMin, greenMax, 255, 0);
    int b = map(readBlue(),  blueMin,  blueMax,  255, 0);
    
    // Clamp values
    r = constrain(r, 0, 255);
    g = constrain(g, 0, 255);
    b = constrain(b, 0, 255);
    
    Serial.print("R:"); Serial.print(r);
    Serial.print(" G:"); Serial.print(g);
    Serial.print(" B:"); Serial.println(b);
    
    // Colour classification
    if (r > 150 && g < 100 && b < 100) return "RED";
    if (g > 150 && r < 100 && b < 100) return "GREEN";
    if (b > 150 && r < 100 && g < 100) return "BLUE";
    if (r > 150 && g > 150 && b < 80)  return "YELLOW";
    if (r > 200 && g > 200 && b > 200)  return "WHITE";
    return "UNKNOWN";
}

Servo-Controlled Sorting Gate

The sorting gate is a rotary flap controlled by a servo. After the colour sensor identifies the object, the servo rotates to direct the object into the appropriate bin.

Physical Design:

  • Use a V-shaped or angled chute with a central pivot point
  • The servo arm connects to the chute pivot via a 3D-printed linkage
  • Servo at 45° → Left bin; Servo at 135° → Right bin; Servo at 90° → Centre/default
  • For 3+ colour sorting, use a rotating carousel with one servo and multiple positions, or use 2 servos in series (two binary gates = 4 possible outputs)
Servo sortingGate;

void sortObject(String color) {
    sortingGate.attach(9);
    
    if (color == "RED") {
        sortingGate.write(45);   // Bin 1 (left)
    } else if (color == "GREEN") {
        sortingGate.write(90);   // Bin 2 (centre)
    } else if (color == "BLUE") {
        sortingGate.write(135);  // Bin 3 (right)
    } else {
        sortingGate.write(90);   // Unknown → centre
    }
    
    delay(500);  // Wait for servo to reach position
    delay(1000); // Wait for object to pass through gate
    
    // Reset gate to centre/detection position
    sortingGate.write(90);
    delay(300);
}
Recommended: Waveshare 20kg.cm Bus Servo with Magnetic Encoder — For heavy-duty sorting gates handling dense objects, this high-torque servo with position feedback prevents gate stalling and provides accurate angle control.

Complete Arduino Code

#include <Servo.h>

// ... (include all declarations from above)

Servo conveyorMotor;  // Controls conveyor belt motor speed via ESC
Servo sortingGate;

void setup() {
    Serial.begin(9600);
    setupColorSensor();
    sortingGate.attach(9);
    sortingGate.write(90);  // Centre position
    
    // Calibrate on startup
    calibrate();
    
    Serial.println("Colour Sorter Ready!");
}

void loop() {
    // Wait for object to be placed under sensor
    // (In a conveyor system, a proximity sensor triggers this)
    
    Serial.println("Place object under sensor...");
    delay(2000);  // 2 second window to place object
    
    // Detect colour
    String color = detectColor();
    Serial.print("Detected: "); Serial.println(color);
    
    // Sort object
    sortObject(color);
    
    Serial.println("Ready for next object.");
    delay(500);
}

Adding a Conveyor Belt

A conveyor belt automates object feeding, making the sorter fully autonomous. You can build a simple belt conveyor from:

  • Two wooden/PVC rollers
  • Rubber band or thin belt looped around rollers
  • One TT motor (or N20 motor) to drive the primary roller
  • L298N or TB6612FNG module to control motor speed

Add an HC-SR04 ultrasonic sensor above the conveyor near the colour sensor position. When the sensor detects an object (distance drops below a threshold), stop the conveyor, detect colour, sort, then restart the conveyor:

void loop() {
    startConveyor();
    
    // Wait for object to arrive at sensor
    while (getDistance() > 3.0) {
        delay(50);  // Object not here yet
    }
    
    stopConveyor();
    delay(100);  // Let object settle
    
    String color = detectColor();
    sortObject(color);
    
    delay(500);  // Clear time
}
Recommended: Waveshare ESP32 Servo Driver Expansion Board — Control up to 16 servos and multiple motors simultaneously for complex multi-stage sorting systems with WiFi-based count reporting.

Frequently Asked Questions

The TCS3200 keeps detecting the wrong colours — how do I improve accuracy?

Ambient light is the most common cause of incorrect readings. Add a cardboard/3D-printed shroud around the sensor and object area to block external light. Increase the number of readings and average them (read each colour 5-10 times and take the mean). Ensure consistent sensing distance by mounting the sensor at a fixed height above the conveyor. Use a dark background (black) for testing to minimise reflections.

Can TCS3200 distinguish similar shades (light red vs dark red)?

Distinguishing similar shades is challenging. The TCS3200 has limited dynamic range and is better at detecting broadly different colours (red, green, blue) than subtle variations. For precise shade detection, upgrade to the TCS34725 (I2C, better dynamic range) or use a camera-based solution with OpenCV colour space analysis.

How do I sort more than 3 colours?

Add a second servo gate in series with the first (2 binary gates = 4 paths). Or use a rotating disc with holes leading to different bins (servo positions at 90°, 180°, 270°, 360°). Or replace the servo gate with a stepper motor for continuous rotation to precisely position the gate at any angle. For 5+ colours, a turntable carousel mechanism is most practical.

What is the maximum conveyor speed for reliable colour detection?

With standard TCS3200 at 20% frequency scaling, a single colour reading takes approximately 50-100ms. Including averaging (5 readings × 100ms = 500ms minimum), the system needs at least 500ms-1s per object. At a conveyor speed of 5cm/s, objects need to be spaced at least 5cm apart. Slow the conveyor when the object is at the sensor position for best reliability.

Shop Sensors & Robot Components at Zbotic →

Tags: color sorting robot, colour sensor, robotics project, servo Arduino, TCS3200
Share Post
  • Facebook
  • Linkedin
  • Whatsapp
Wire-to-Board vs Wire-to-Wire ...
blog wire to board vs wire to wire connector selection guide 598394
blog diy solar tracker with arduino renewable energy project 598404
DIY Solar Tracker with Arduino...

Related posts

Svg%3E
Read more

Caterpillar Track Robot: Tank-Drive Build for All Terrain

April 1, 2026 0
When wheels lose grip on sand, gravel, grass, or loose surfaces, caterpillar tracks keep moving. A tank-track robot distributes its... Continue reading
Svg%3E
Read more

RC Car to Robot: Convert a Toy Car into an Autonomous Robot

April 1, 2026 0
That old RC toy car gathering dust can be transformed into an Arduino-controlled autonomous robot with just a few electronic... Continue reading
Svg%3E
Read more

Robotic Arm Kit India: Best Options for Students and Hobbyists

April 1, 2026 0
If you are a student or hobbyist looking to get into robotics, a robotic arm kit is one of the... Continue reading
Svg%3E
Read more

Sumo Robot: Competition Build Guide India

April 1, 2026 0
Sumo robot competitions are among the most exciting events in Indian robotics, pitting small autonomous robots against each other in... Continue reading
Svg%3E
Read more

Robot Arm Build: 6-DOF Servo Arm with Arduino Control

April 1, 2026 0
Building a 6-DOF robot arm with servo motors and Arduino is one of the most rewarding robotics projects you can... 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