Blogs
TCS34725 RGB Color Sensor Module
TCS34725 RGB Color Sensor Module
High-Accuracy Digital Color Detection with IR Filter
Introduction
The TCS34725 is a digital RGB color sensor with IR blocking filter that provides precise color sensing through an I2C interface. This sensor offers better color accuracy than traditional light-to-frequency sensors by providing direct digital outputs for red, green, blue, and clear light sensing.
Key Features
True RGB Sensing
Separate digital outputs for red, green, blue, and clear channels
IR Filter
Integrated IR blocking filter for accurate color measurement
Programmable
Adjustable integration time and gain
I2C Interface
Simple connection with 3.3V or 5V microcontrollers
Technical Specifications
Detection Range | 380nm-780nm (Visible Light Spectrum) |
---|---|
Resolution | 16-bit per channel (RGB and Clear) |
Interface | I2C (0x29 default address) |
Supply Voltage | 2.7V – 3.6V (5V tolerant I/O) |
Current Consumption | 0.65mA (typical at 50ms integration) |
Integration Time | 2.4ms – 614ms (programmable) |
Gain Settings | 1x, 4x, 16x, 60x |
Pin Configuration

Pin | Label | Description | Arduino Connection |
---|---|---|---|
1 | VCC | Power (3.3V) | 3.3V |
2 | GND | Ground | GND |
3 | SCL | I2C Clock | A5 (Uno) or SCL |
4 | SDA | I2C Data | A4 (Uno) or SDA |
5 | LED | LED control (optional) | Digital pin (optional) |
6 | INT | Interrupt output (optional) | Digital pin (optional) |
Note: The sensor requires proper lighting conditions for accurate color detection
Wiring with Arduino
1 2 3 4 5 6 7 8 9 10 11 |
// Basic I2C Connections: // VCC → 3.3V // GND → GND // SCL → A5 (Uno) or SCL // SDA → A4 (Uno) or SDA // Optional connections: // LED → Digital pin (to control illumination LED) // INT → Digital pin (for interrupt functionality) // Requires Adafruit TCS34725 library |
Important: Use 3.3V power supply for the sensor, though I/O pins are 5V tolerant
Basic Color Detection Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
// TCS34725 Color Sensor Basic Example #include <Wire.h> #include <Adafruit_TCS34725.h> Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_50MS, TCS34725_GAIN_4X); void setup() { Serial.begin(9600); if (!tcs.begin()) { Serial.println("Could not find TCS34725 sensor"); while (1); } } void loop() { uint16_t r, g, b, c; tcs.getRawData(&r, &g, &b, &c); Serial.print("R: "); Serial.print(r); Serial.print(" G: "); Serial.print(g); Serial.print(" B: "); Serial.print(b); Serial.print(" C: "); Serial.println(c); delay(500); } |
Advanced Features
Color Temperature
1 2 3 |
// Calculate color temperature uint16_t colorTemp = tcs.calculateColorTemperature(r, g, b); Serial.print("Color Temp: "); Serial.print(colorTemp); Serial.println(" K"); |
Lux Calculation
1 2 3 |
// Calculate illuminance (lux) uint16_t lux = tcs.calculateLux(r, g, b); Serial.print("Lux: "); Serial.println(lux); |
Interrupt Function
1 2 3 4 |
// Set interrupt thresholds tcs.setInterrupt(true); // Enable interrupt tcs.setIntLimits(1000, 2000); // Set low and high thresholds // Connect INT pin to handle interrupts |
RGB to Hex
1 2 3 4 5 6 |
// Convert RGB to hex color code String rgbToHex(uint16_t r, uint16_t g, uint16_t b) { char hexColor[8]; sprintf(hexColor, "#%02X%02X%02X", r>>8, g>>8, b>>8); return String(hexColor); } |
Troubleshooting
Sensor Not Detected
- Verify I2C connections (SCL/SDA)
- Check sensor address (default 0x29)
- Ensure proper power supply (3.3V)
Inaccurate Readings
- Adjust integration time for lighting conditions
- Use proper gain setting (1x, 4x, 16x, 60x)
- Ensure consistent lighting and distance
Saturation Issues
- Reduce integration time
- Lower gain setting
- Move sensor further from light source