Uncategorized

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.

TCS34725 Color SensorKey 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 Range380nm-780nm (Visible Light Spectrum)
Resolution16-bit per channel (RGB and Clear)
InterfaceI2C (0x29 default address)
Supply Voltage2.7V – 3.6V (5V tolerant I/O)
Current Consumption0.65mA (typical at 50ms integration)
Integration Time2.4ms – 614ms (programmable)
Gain Settings1x, 4x, 16x, 60x

Pin Configuration

TCS34725 Pinout
PinLabelDescriptionArduino Connection
1VCCPower (3.3V)3.3V
2GNDGroundGND
3SCLI2C ClockA5 (Uno) or SCL
4SDAI2C DataA4 (Uno) or SDA
5LEDLED control (optional)Digital pin (optional)
6INTInterrupt output (optional)Digital pin (optional)
Note: The sensor requires proper lighting conditions for accurate color detection

Wiring with Arduino

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

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

// Calculate color temperature
uint16_t colorTemp = tcs.calculateColorTemperature(r, g, b);
Serial.print("Color Temp: "); Serial.print(colorTemp); Serial.println(" K");

Lux Calculation

// Calculate illuminance (lux)
uint16_t lux = tcs.calculateLux(r, g, b);
Serial.print("Lux: "); Serial.println(lux);

Interrupt Function

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

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