ESP32 C3 Super Mini - TCS3200D/TCS230 Color Sensor

Learn how to connect the TCS3200D/TCS230 color sensor to your ESP32 C3 Super Mini for accurate RGB color detection. This beginner-friendly tutorial covers calibration and real-time color measurements.

What you'll learn:

ESP32 C3 Super Mini with TCS3200D TCS230 color sensor module tutorial

Hardware Preparation

1×ESP32 C3 Super Mini
1×USB Cable Type-A to Type-C (for USB-A PC)
1×USB Cable Type-C to Type-C (for USB-C PC)
1×TCS3200D/TCS230 Color Recognition Sensor Module
1×Breadboard
1×Jumper Wires

Or you can buy the following kits:

1×DIYables Sensor Kit (18 sensors/displays)
Disclosure: Some of the links provided in this section are Amazon affiliate links. We may receive a commission for any purchases made through these links at no additional cost to you.
Additionally, some of these links are for products from our own brand, DIYables .

Overview of TCS3200D/TCS230 Color Sensor

The TCS3200D/TCS230 is an optical sensor that detects colors by measuring light reflections through specialized photodiode filters.

Key features:

  • 64 photodiodes in 8×8 array (16 red filters, 16 green, 16 blue, 16 clear)
  • Frequency output proportional to light intensity
  • Operating voltage: 2.7V to 5.5V (5V recommended)
  • Built-in white LED illumination for consistent readings
  • Output frequency range: 2 Hz to 500 kHz
  • Ideal for beginners: simple digital output, no complex analog reading

Why it's useful:

  • Works in various lighting conditions thanks to onboard LEDs
  • Easy to interface with ESP32 C3 Super Mini digital pins
  • Perfect for color sorting, matching, and detection projects

Pinout

The TCS3200D/TCS230 color sensor has 8 connection pins:

  • VCC: Power supply input (connect to 5V)
  • GND: Ground connection (0V reference)
  • S0: Frequency scaling control pin 1
  • S1: Frequency scaling control pin 2
  • S2: Color filter selection pin 1
  • S3: Color filter selection pin 2
  • OUT: Frequency output signal pin (connect to ESP32 digital pin)
  • OE: Output enable pin (active LOW, usually connected to GND)
TCS3200 TCS230 color sensor module pinout diagram showing VCC GND S0 S1 S2 S3 OUT pins

How It Works

The TCS3200 color sensor operates using two control systems:

Frequency scaling (S0 and S1 pins):

  • S0=LOW, S1=LOW: Power down mode
  • S0=LOW, S1=HIGH: 2% frequency scaling
  • S0=HIGH, S1=LOW: 20% frequency scaling
  • S0=HIGH, S1=HIGH: 100% frequency scaling (recommended)

Color filter selection (S2 and S3 pins):

  • S2=LOW, S3=LOW: Red filter active
  • S2=LOW, S3=HIGH: Blue filter active
  • S2=HIGH, S3=LOW: Clear filter (no filtering)
  • S2=HIGH, S3=HIGH: Green filter active

How readings work:

  • The OUT pin outputs a square wave signal
  • Frequency increases with brighter light (2 Hz to 500 kHz)
  • ESP32 C3 Super Mini measures pulse width using pulseIn()
  • Shorter pulses = brighter light = higher color intensity
  • Calibration converts pulse widths to standard RGB values (0-255)

Maximizing Measurement Precision

Follow these tips for accurate TCS3200 color readings:

  • Keep sensor distance fixed at 1-3 cm from the object
  • Position sensor at consistent angle (perpendicular works best)
  • Use the built-in white LEDs for stable illumination
  • Shield sensor from external light sources when possible
  • Perform calibration in your actual working environment
  • Test on flat, matte surfaces for best results

Wiring Diagram

Connect the TCS3200D color sensor to your ESP32 C3 Super Mini following this simple wiring configuration:

Safety note:

  • Note: The TCS3200 sensor works best with 5V power, which the ESP32 C3 Super Mini can provide via the 5V pin when powered through USB.
TCS3200 Color SensorESP32 C3 Super Mini
VCC5V
GNDGND
S0D4
S1D3
S2D6
S3D5
OUTD7
The wiring diagram between ESP32 C3 Super Mini and TCS3200 color sensor

This image is created using Fritzing. Click to enlarge image

ESP32 C3 Super Mini Code - Sensor Calibration

Start with this calibration code to optimize your TCS3200 sensor for your specific environment.

What this code does:

  • Powers up the sensor with full frequency scaling (100%)
  • Cycles through red, green, and blue filters
  • Tracks minimum and maximum pulse widths for each color
  • Continuously updates calibration values as you show different colors
  • Displays real-time measurements in the Serial Monitor
/* * This ESP32 C3 Super Mini code was developed by newbiely.com * * This ESP32 C3 Super Mini code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/esp32-c3/esp32-c3-super-mini-tcs3200d-tcs230-color-sensor */ // Define color sensor pins #define PIN_S0 D4 // The ESP32 C3 SuperMini pin connected to the S0 of the color module #define PIN_S1 D3 // The ESP32 C3 SuperMini pin connected to the S1 of the color module #define PIN_S2 D6 // The ESP32 C3 SuperMini pin connected to the S2 of the color module #define PIN_S3 D5 // The ESP32 C3 SuperMini pin connected to the S3 of the color module #define PIN_sensorOut D7 // The ESP32 C3 SuperMini pin connected to the OUT of the color module // Variables for Color Pulse Width Measurements int redPW = 0; int greenPW = 0; int bluePW = 0; // Variables to track min and max pulse widths for calibration int redMin = 10000, redMax = 0; int greenMin = 10000, greenMax = 0; int blueMin = 10000, blueMax = 0; void setup() { // Set S0 - S3 as outputs pinMode(PIN_S0, OUTPUT); pinMode(PIN_S1, OUTPUT); pinMode(PIN_S2, OUTPUT); pinMode(PIN_S3, OUTPUT); // Set Pulse Width scaling to 20% digitalWrite(PIN_S0, HIGH); digitalWrite(PIN_S1, LOW); // Set Sensor output as input pinMode(PIN_sensorOut, INPUT); // Setup Serial Monitor Serial.begin(9600); Serial.println("=== TCS3200 Calibration ==="); Serial.println("Point the sensor at different objects (white, black, colors)."); Serial.println("Min and Max values are tracked automatically."); Serial.println("When values look stable, note them down for the next code."); Serial.println("------------------------------------------"); } void loop() { // Read Red Pulse Width redPW = getRedPW(); // Delay to stabilize sensor delay(200); // Read Green Pulse Width greenPW = getGreenPW(); // Delay to stabilize sensor delay(200); // Read Blue Pulse Width bluePW = getBluePW(); // Delay to stabilize sensor delay(200); // Update min and max values if (redPW < redMin) redMin = redPW; if (redPW > redMax) redMax = redPW; if (greenPW < greenMin) greenMin = greenPW; if (greenPW > greenMax) greenMax = greenPW; if (bluePW < blueMin) blueMin = bluePW; if (bluePW > blueMax) blueMax = bluePW; // Print the pulse width values with min/max Serial.print("Red PW = "); Serial.print(redPW); Serial.print(" - Green PW = "); Serial.print(greenPW); Serial.print(" - Blue PW = "); Serial.println(bluePW); Serial.print(" Min -> R:"); Serial.print(redMin); Serial.print(" G:"); Serial.print(greenMin); Serial.print(" B:"); Serial.println(blueMin); Serial.print(" Max -> R:"); Serial.print(redMax); Serial.print(" G:"); Serial.print(greenMax); Serial.print(" B:"); Serial.println(blueMax); Serial.println("------------------------------------------"); delay(1000); } // Function to read Red Pulse Widths int getRedPW() { // Set sensor to read Red only digitalWrite(PIN_S2, LOW); digitalWrite(PIN_S3, LOW); // Read the Pulse Width int PW = pulseIn(PIN_sensorOut, LOW); // Return the value return PW; } // Function to read Green Pulse Widths int getGreenPW() { // Set sensor to read Green only digitalWrite(PIN_S2, HIGH); digitalWrite(PIN_S3, HIGH); // Read the Pulse Width int PW = pulseIn(PIN_sensorOut, LOW); // Return the value return PW; } // Function to read Blue Pulse Widths int getBluePW() { // Set sensor to read Blue only digitalWrite(PIN_S2, LOW); digitalWrite(PIN_S3, HIGH); // Read the Pulse Width int PW = pulseIn(PIN_sensorOut, LOW); // Return the value return PW; }

Detailed Instructions

  • New to ESP32 C3 Mini? Complete our Getting Started with ESP32 C3 Mini tutorial first to set up your development environment.
  • Wire the components: Follow the wiring diagram above to connect all pins correctly.
  • Connect your board: Plug the ESP32 C3 Super Mini into your computer using a USB-C cable.
  • Open Arduino IDE: Launch the software on your computer.
  • Select your board: Choose ESP32 C3 Super Mini and the correct COM port from the Tools menu.
  • Copy the code: Paste the calibration code into a new Arduino IDE sketch.
  • Upload the code: Click the Upload button and wait for the process to complete.
  • Open Serial Monitor: Set baud rate to 9600 to view calibration data.
  • Point at white objects: Start with bright white paper or surfaces.
  • Point at black objects: Move to dark black surfaces.
  • Point at colored objects: Show the sensor various colored items (red, green, blue, yellow, etc.).
  • Watch values stabilize: After 10-20 seconds, the Min/Max numbers will stop changing significantly.
  • Record your values: Write down all six numbers (redMin, redMax, greenMin, greenMax, blueMin, blueMax).
  • Pro Tip: Keep the sensor distance consistent (2-3 cm) during calibration for the most accurate results.
Newbiely | Arduino IDE 2.3.8
──
File
Edit
Sketch
Tools
Help
ESP32C3 Dev Module
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'ESP32C3 Dev Module' on 'COM15')
New Line
9600 baud
=== TCS3200 Calibration === Point the sensor at different objects (white, black, colors). Min and Max values are tracked automatically. When values look stable, note them down for the next code. ------------------------------------------ Red PW = 42 - Green PW = 55 - Blue PW = 60 Min -> R:42 G:55 B:60 Max -> R:42 G:55 B:60 ------------------------------------------ Red PW = 210 - Green PW = 185 - Blue PW = 172 Min -> R:42 G:55 B:60 Max -> R:210 G:185 B:172 ------------------------------------------ Red PW = 44 - Green PW = 57 - Blue PW = 61 Min -> R:42 G:55 B:60 Max -> R:210 G:185 B:172 ------------------------------------------ Red PW = 38 - Green PW = 51 - Blue PW = 58 Min -> R:38 G:51 B:58 Max -> R:210 G:185 B:172 ------------------------------------------
Ln 11, Col 1
ESP32C3 Dev Module on COM15
2

Calibration values from this example:

  • RedMin = 38, redMax = 210
  • GreenMin = 51, greenMax = 185
  • BlueMin = 58, blueMax = 172

ESP32 C3 Super Mini Code - RGB Color Reading

Use this code to read accurate RGB color values after calibration.

What this code does:

  • Applies your calibration values to normalize sensor readings
  • Measures red, green, and blue channels sequentially
  • Converts raw pulse widths to standard RGB format (0-255)
  • Displays color values continuously in Serial Monitor
  • Updates readings in real-time as you move colored objects
/* * This ESP32 C3 Super Mini code was developed by newbiely.com * * This ESP32 C3 Super Mini code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/esp32-c3/esp32-c3-super-mini-tcs3200d-tcs230-color-sensor */ // Define color sensor pins #define PIN_S0 D4 // The ESP32 C3 SuperMini pin connected to the S0 of the color module #define PIN_S1 D3 // The ESP32 C3 SuperMini pin connected to the S1 of the color module #define PIN_S2 D6 // The ESP32 C3 SuperMini pin connected to the S2 of the color module #define PIN_S3 D5 // The ESP32 C3 SuperMini pin connected to the S3 of the color module #define PIN_sensorOut D7 // The ESP32 C3 SuperMini pin connected to the OUT of the color module // Calibration Values // Replace these values with your actual calibration data from the previous step int redMin = 0; // Red minimum pulse width int redMax = 0; // Red maximum pulse width int greenMin = 0; // Green minimum pulse width int greenMax = 0; // Green maximum pulse width int blueMin = 0; // Blue minimum pulse width int blueMax = 0; // Blue maximum pulse width // Variables for Color Pulse Width Measurements int redPW = 0; int greenPW = 0; int bluePW = 0; // Variables for final Color values int redValue; int greenValue; int blueValue; void setup() { // Set S0 - S3 as outputs pinMode(PIN_S0, OUTPUT); pinMode(PIN_S1, OUTPUT); pinMode(PIN_S2, OUTPUT); pinMode(PIN_S3, OUTPUT); // Set Pulse Width scaling to 20% digitalWrite(PIN_S0, HIGH); digitalWrite(PIN_S1, LOW); // Set Sensor output as input pinMode(PIN_sensorOut, INPUT); // Setup Serial Monitor Serial.begin(9600); } void loop() { // Read Red value redPW = getRedPW(); // Map to value from 0-255 redValue = map(redPW, redMin, redMax, 255, 0); // Delay to stabilize sensor delay(200); // Read Green value greenPW = getGreenPW(); // Map to value from 0-255 greenValue = map(greenPW, greenMin, greenMax, 255, 0); // Delay to stabilize sensor delay(200); // Read Blue value bluePW = getBluePW(); // Map to value from 0-255 blueValue = map(bluePW, blueMin, blueMax, 255, 0); // Delay to stabilize sensor delay(200); // Print output to Serial Monitor Serial.print("Red = "); Serial.print(redValue); Serial.print(" - Green = "); Serial.print(greenValue); Serial.print(" - Blue = "); Serial.println(blueValue); } // Function to read Red Pulse Widths int getRedPW() { // Set sensor to read Red only digitalWrite(PIN_S2, LOW); digitalWrite(PIN_S3, LOW); // Read the Pulse Width int PW = pulseIn(PIN_sensorOut, LOW); // Return the value return PW; } // Function to read Green Pulse Widths int getGreenPW() { // Set sensor to read Green only digitalWrite(PIN_S2, HIGH); digitalWrite(PIN_S3, HIGH); // Read the Pulse Width int PW = pulseIn(PIN_sensorOut, LOW); // Return the value return PW; } // Function to read Blue Pulse Widths int getBluePW() { // Set sensor to read Blue only digitalWrite(PIN_S2, LOW); digitalWrite(PIN_S3, HIGH); // Read the Pulse Width int PW = pulseIn(PIN_sensorOut, LOW); // Return the value return PW; }

Detailed Instructions

  • New to ESP32 C3 Mini? Complete our Getting Started with ESP32 C3 Mini tutorial first to set up your development environment.
  • Locate calibration variables: Find these lines near the top of the code (around line 10-15):
int redMin = 0; int redMax = 0; int greenMin = 0; int greenMax = 0; int blueMin = 0; int blueMax = 0;
  • Insert your calibration values: Replace all zeros with the numbers you recorded during calibration. For example:
int redMin = 38; int redMax = 210; int greenMin = 51; int greenMax = 185; int blueMin = 58; int blueMax = 172;
  • Upload the code: Click Upload to transfer the modified code to your ESP32 C3 Super Mini.
  • Open Serial Monitor: Set baud rate to 9600 to see RGB values.
  • Test with colored objects: Place red, green, blue, yellow, or other colored items in front of the sensor.
  • Read RGB values: Watch the color measurements update in real-time on the Serial Monitor.
  • Pro Tip: For consistent results, always maintain the same distance and lighting conditions you used during calibration.
Newbiely | Arduino IDE 2.3.8
──
File
Edit
Sketch
Tools
Help
ESP32C3 Dev Module
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'ESP32C3 Dev Module' on 'COM15')
New Line
9600 baud
Red = 210 - Green = 35 - Blue = 20 Red = 215 - Green = 38 - Blue = 22 Red = 208 - Green = 33 - Blue = 18 Red = 25 - Green = 200 - Blue = 40 Red = 28 - Green = 205 - Blue = 42 Red = 22 - Green = 198 - Blue = 38 Red = 30 - Green = 45 - Blue = 215 Red = 33 - Green = 48 - Blue = 220 Red = 28 - Green = 42 - Blue = 210
Ln 11, Col 1
ESP32C3 Dev Module on COM15
2

Understanding the output:

  • Values range from 0 (no color detected) to 255 (maximum intensity)
  • Higher numbers mean more of that color is reflected
  • First three lines show a red object (high red value, low green/blue)
  • Middle three lines show a green object (high green value)
  • Last three lines show a blue object (high blue value)

Project Applications

Build creative color-sensing projects with your ESP32 C3 Super Mini and TCS3200 sensor:

  • Automated color sorter: Sort M&Ms, LEGO bricks, or beads by color using a servo mechanism
  • Color matching game: Challenge users to find objects matching a target RGB value
  • Line-following robot: Create a robot that follows colored tape paths on the floor
  • Quality control system: Detect defective products by comparing colors to reference standards
  • Smart lighting controller: Automatically adjust RGB LED colors to match detected ambient colors
  • Paint color identifier: Build a handheld device that identifies paint colors for home decorating
  • Educational color mixer: Demonstrate additive color theory by displaying RGB values of mixed colors

Video Section

Watch the video below for a visual walkthrough of this project.

Challenge Yourself

Expand your TCS3200 color sensor skills with these project challenges:

  • Easy: Add an RGB LED that lights up with the same color the sensor detects
  • Easy: Display color names ("Red", "Green", "Blue") instead of just numbers when primary colors are detected
  • Medium: Build a color memory game that shows random colors and tests if users can match them
  • Medium: Create a color-based security system that only unlocks when shown a specific colored object
  • Advanced: Build a full color sorter with servo motors that physically separate objects into bins by color
  • Advanced: Develop a smartphone app that receives RGB values from ESP32 C3 Super Mini via Bluetooth and displays the actual color on screen

Learn More

※ OUR MESSAGES

  • As freelancers, We are AVAILABLE for HIRE. See how to outsource your project to us
  • Please feel free to share the link of this tutorial. However, Please do not use our content on any other websites. We invested a lot of effort and time to create the content, please respect our work!