The TCS34725 is a color sensor made by AMS (now part of Renesas).
It detects Red, Green, Blue, and Clear light (ambient).
Detects RGB colors
I2C interface (perfect for ESP32)
Built-in IR filter for accurate color detection
Built-in white LED for illumination
Measures light intensity (lux) and color temperature (K)
| Component | Description |
|---|---|
| ESP32 board | Any variant (e.g., DevKit V1) |
| TCS34725 sensor module | Usually via I2C |
| Jumper wires | Female-to-male if needed |
| Library | Adafruit_TCS34725 |
| TCS34725 Pin | Connect To ESP32 |
|---|---|
| VIN | 3.3V or 5V |
| GND | GND |
| SDA | GPIO 21 (I2C SDA) |
| SCL | GPIO 22 (I2C SCL) |
You can change SDA/SCL in software if needed, but 21/22 are default.
Go to Sketch > Include Library > Manage Libraries
Search and install:
โ
Adafruit TCS34725
โ
Adafruit Unified Sensor
| Application | Description |
|---|---|
| ๐จ Color Picker | Detect colors from surfaces |
| ๐ฅ Line/Fruit Sorting | Distinguish red/green/yellow |
| ๐ก Ambient Lighting | Adjust RGB LEDs based on surroundings |
| ๐ฆ Product Classification | Use color to classify packaging |
| ๐ฎ DIY Game Controllers | Color-based input |
| Tip | Info |
|---|---|
| Sensor too slow? | Use TCS34725_INTEGRATIONTIME_2_4MS for faster readings |
| Low light? | Set gain to TCS34725_GAIN_60X |
| Washed-out color? | Reduce LED brightness or cover with diffusion material |
| Not detecting? | Use an I2C scanner to confirm address (default: 0x29) |
HOW TO OPERATE
#include <Wire.h>
#include "Adafruit_TCS34725.h"
// Initialize with default I2C address (0x29)
Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_50MS, TCS34725_GAIN_4X);
void setup() {
Serial.begin(115200);
if (tcs.begin()) {
Serial.println("TCS34725 found!");
} else {
Serial.println("No TCS34725 found ... check your connections");
while (1);
}
// Turn on LED for illumination (if supported)
tcs.setInterrupt(false);
}
void loop() {
uint16_t r, g, b, c;
tcs.getRawData(&r, &g, &b, &c);
// Calculate color temperature and lux
uint16_t colorTemp = tcs.calculateColorTemperature_dn40(r, g, b, c);
uint16_t lux = tcs.calculateLux(r, g, b);
Serial.print("R: "); Serial.print(r);
Serial.print(" G: "); Serial.print(g);
Serial.print(" B: "); Serial.print(b);
Serial.print(" C: "); Serial.print(c);
Serial.print(" Color Temp: "); Serial.print(colorTemp); Serial.print(" K");
Serial.print(" Lux: "); Serial.println(lux);
delay(1000);
}
OUTPUT
R: 1234 G: 1320 B: 1100 C: 3700 Color Temp: 4350 K Lux: 75