Back to Tutorial

ESP32 with TCS34725 RGB Sensor


🎨 What is the TCS34725?

The TCS34725 is a color sensor made by AMS (now part of Renesas).
It detects RedGreenBlue, 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

ComponentDescription
ESP32 boardAny variant (e.g., DevKit V1)
TCS34725 sensor moduleUsually via I2C
Jumper wiresFemale-to-male if needed
LibraryAdafruit_TCS34725

📌 TCS34725 Pinout

TCS34725 PinConnect To ESP32
VIN3.3V or 5V
GNDGND
SDAGPIO 21 (I2C SDA)
SCLGPIO 22 (I2C SCL)

You can change SDA/SCL in software if needed, but 21/22 are default.


📚 Step 1: Install Libraries in Arduino IDE

  1. Go to Sketch > Include Library > Manage Libraries
  2. 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_4MS for faster readingsLow light?Set gain to TCS34725_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
    •  
ESP32 with TCS34725 RGB Sensor

Share this post

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Back to Tutorial