ESP32 with TCS34725 RGB Sensor
🎨 What is the TCS34725?
The TCS34725 is a color sensor made by AMS (now part of Renesas).
It detects Red, Green, Blue, and Clear light (ambient).
🧠 Key Features:
- 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)
🧰 What You Need
| 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 Pinout
| 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.
📚 Step 1: Install Libraries in Arduino IDE
- Go to Sketch > Include Library > Manage Libraries
- Search and install:
- ✅
Adafruit TCS34725 - ✅
Adafruit Unified Sensor - 🎯 What You Can Do with TCS34725ApplicationDescription🎨 Color PickerDetect colors from surfaces🚥 Line/Fruit SortingDistinguish red/green/yellow💡 Ambient LightingAdjust RGB LEDs based on surroundings📦 Product ClassificationUse color to classify packaging🎮 DIY Game ControllersColor-based input🧠 Pro TipsTipInfoSensor too slow?Use
TCS34725_INTEGRATIONTIME_2_4MSfor faster readingsLow light?Set gain toTCS34725_GAIN_60XWashed-out color?Reduce LED brightness or cover with diffusion materialNot 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

Leave a Reply
You must be logged in to post a comment.