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


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