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 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

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