ESP8266 - TCS3200D/TCS230 Color Sensor
This tutorial guides you through using ESP8266 with the TCS3200D/TCS230 color sensor for precise color detection and RGB measurement.
In detail, we will learn:
- How to connect the TCS3200D/TCS230 sensor to ESP8266
- How to calibrate the sensor for accurate readings
- How to program ESP8266 to read and display RGB values
Hardware Preparation
Or you can buy the following kits:
| 1 | × | DIYables Sensor Kit (30 sensors/displays) | |
| 1 | × | DIYables Sensor Kit (18 sensors/displays) |
Additionally, some of these links are for products from our own brand, DIYables .
Overview of TCS3200D/TCS230 Color Sensor
The TCS3200D/TCS230 color sensor utilizes a grid of 64 photodiodes arranged in an 8×8 matrix for color detection through wavelength-specific filtering. Within this array, 16 photodiodes incorporate red wavelength filters, 16 use green wavelength filters, 16 employ blue wavelength filters, and 16 operate without filtering (clear response). Color measurement occurs by selecting particular filter sets and evaluating the frequency of the output signal.
Common TCS3200D modules feature built-in white LED illumination arrays that provide consistent target lighting, ensuring measurement stability regardless of external lighting fluctuations and enhancing sensitivity in dim conditions.
Pinout
Pin configuration of the TCS3200D/TCS230 sensor module:
- VCC pin: Supply voltage input (+5V).
- GND pin: Ground reference (0V).
- S0, S1 pins: Output frequency scaling selectors.
- S2, S3 pins: Color channel filter selectors.
- OUT pin: Frequency-modulated square wave output.
- OE pin: Output enable input (enables when LOW). Standard modules typically hard-wire this to GND internally. If not connected, manually wire to GND.

How It Works
Sensor operation depends on two primary controls: which photodiode filter group to activate and what output frequency range to generate. Two control pin pairs manage these functions:
Frequency scaling control (S0 and S1 pins):
- S0=LOW, S1=LOW: Power down state
- S0=LOW, S1=HIGH: 2% scaling factor
- S0=HIGH, S1=LOW: 20% scaling factor
- S0=HIGH, S1=HIGH: 100% scaling factor (full speed)
Color channel selection (S2 and S3 pins):
- S2=LOW, S3=LOW: Red photodiodes active
- S2=LOW, S3=HIGH: Blue photodiodes active
- S2=HIGH, S3=LOW: Clear photodiodes active (no filtering)
- S2=HIGH, S3=HIGH: Green photodiodes active
The OUT pin delivers square-wave frequencies spanning approximately 2 Hz to 500 kHz. Higher light intensity produces higher frequency output. ESP8266's pulseIn() function measures pulse duration, which correlates inversely—brighter illumination produces shorter durations. Calibrated measurements translate into conventional 0-255 RGB format.
Achieving Optimal Precision
- Keep sensor positioned 1-3 cm from measurement target with stable angular alignment.
- Utilize integrated white LED illumination for repeatable lighting.
- Shield sensor from variable ambient light to enhance measurement consistency.
Wiring Diagram
Connect the TCS3200 color sensor to ESP8266 as follows:
| TCS3200 Color Sensor | ESP8266 |
|---|---|
| VCC | 3V3 |
| GND | GND |
| S0 | D6 (GPIO12) |
| S1 | D7 (GPIO13) |
| S2 | D2 (GPIO4) |
| S3 | D5 (GPIO14) |
| OUT | D1 (GPIO5) |

This image is created using Fritzing. Click to enlarge image
See more in ESP8266's pinout and how to supply power to the ESP8266 and other components.
ESP8266 Code - Sensor Calibration
Calibration eliminates environmental interference from raw measurements. Variables including LED output strength, target spacing, material reflectivity, and room lighting all affect readings. The calibration routine identifies minimum and maximum pulse widths across all color channels, establishing reference boundaries for converting raw data into accurate 0–255 RGB values matched to your deployment environment.
Detailed Instructions
To get started with ESP8266 on Arduino IDE, follow these steps:
- Check out the how to setup environment for ESP8266 on Arduino IDE tutorial if this is your first time using ESP8266.
- Wire the components as shown in the diagram.
- Connect the ESP8266 board to your computer using a USB cable.
- Open Arduino IDE on your computer.
- Choose the correct ESP8266 board, such as (e.g. NodeMCU 1.0 (ESP-12E Module)), and its respective COM port.
- Copy the calibration code and open it in Arduino IDE.
- Click the Upload button to compile and upload to ESP8266.
- Launch the Serial Monitor.
- Direct the sensor at different surfaces: white (paper), black, and various colors.
- Watch the Min/Max values update automatically.
- When values stabilize (typically 10-20 seconds), record all six calibration parameters.
Sample calibration parameters extracted from above output:
- RedMin = 42, redMax = 210
- GreenMin = 55, greenMax = 185
- BlueMin = 60, blueMax = 172
ESP8266 Code - Reading RGB Values
Detailed Instructions
- Locate the calibration variables at the code start:
- Replace all six zero placeholders with measured calibration data. Example using values redMin = 42, redMax = 210, greenMin = 55, greenMax = 185, blueMin = 60, blueMax = 172:
- Upload the updated code to ESP8266.
- Position a colored object in front of the sensor.
- Open Serial Monitor to view RGB measurements.
Displayed RGB values conform to standard 0-255 scaling. Reduced pulse widths (indicating brighter reflections) generate higher RGB outputs; extended pulse widths (dimmer reflections) yield lower values.
From the RGB values, you can:
- Identify specific colors by comparing RGB ratios
- Sort objects by color detection
- Match colors between different samples
- Trigger actions based on detected colors
Project Applications
With operational RGB measurement capability, you can develop:
- Chromatic sorting system: Categorize objects by color (red/green/blue differentiation)
- Color verification device: Confirm color consistency between samples
- Colored path follower: Robots that navigate along chromatic markers
- Visual quality inspection: Detect production defects via color analysis
- Color-triggered automation: Execute actions when specific hues are detected