Stufin
Home Quick Cart Profile

TCS34725 RGB Color Sensor

Buy Now on Stufin

Operating Temperature

-40C to 85C

Storage Temperature

-40C to 125C

Supply Voltage

2.5V to 3.6V

Supply Current

2.5mA (typical)

Conclusion

The TCS34725 RGB color sensor is a highly capable and versatile component, offering a high degree of accuracy, sensitivity, and flexibility. Its low power consumption, small form factor, and digital output make it an ideal choice for a wide range of IoT applications, from smart lighting systems to color detection and industrial automation.

Pin Configuration

  • TCS34725 RGB Color Sensor Pinout and Connection Guide
  • The TCS34725 is a high-sensitivity, low-power RGB color sensor with an I2C interface. This sensor is commonly used in various IoT applications, including color recognition, ambient light sensing, and proximity detection. The following pinout and connection guide will help you understand the functionality of each pin and connect them correctly.
  • Pinout:
  • 1. VCC:
  • Function: Power supply pin
  • Description: Connect to a 2.5V to 3.5V power source
  • Recommended voltage: 3.3V
  • 2. GND:
  • Function: Ground pin
  • Description: Connect to the ground of your microcontroller or power supply
  • 3. SCL:
  • Function: I2C clock pin
  • Description: Connect to the I2C clock pin of your microcontroller (e.g., SCL on Arduino)
  • 4. SDA:
  • Function: I2C data pin
  • Description: Connect to the I2C data pin of your microcontroller (e.g., SDA on Arduino)
  • 5. INT:
  • Function: Interrupt pin
  • Description: Optional connection to an interrupt pin on your microcontroller. This pin is active-low and goes low when an interrupt event occurs.
  • 6. ADDR:
  • Function: Address select pin
  • Description: Connect to either VCC or GND to select one of two possible I2C addresses (0x29 or 0x39)
  • 7. OE:
  • Function: Output enable pin
  • Description: Active-low output enable pin. Connect to GND to enable the sensor output.
  • Connection Structure:
  • To connect the TCS34725 RGB Color Sensor to your microcontroller or development board:
  • 1. Connect VCC to a 2.5V to 3.5V power source (e.g., 3.3V on Arduino).
  • 2. Connect GND to the ground of your microcontroller or power supply.
  • 3. Connect SCL to the I2C clock pin of your microcontroller (e.g., SCL on Arduino).
  • 4. Connect SDA to the I2C data pin of your microcontroller (e.g., SDA on Arduino).
  • 5. If desired, connect INT to an interrupt pin on your microcontroller (optional).
  • 6. Connect ADDR to either VCC or GND to select the I2C address (0x29 or 0x39).
  • 7. Connect OE to GND to enable the sensor output.
  • Note:
  • Make sure to use level shifters or voltage dividers if your microcontroller operates at a voltage different from the sensor's recommended voltage (3.3V).
  • Refer to the TCS34725 datasheet and your microcontroller's documentation for specific connection details and I2C communication protocols.
  • Always double-check your connections to avoid damage to the sensor or your microcontroller.

Code Examples

TCS34725 RGB Color Sensor Documentation
Overview
The TCS34725 is a high-sensitivity, low-power, and low-noise RGB color sensor from ams OSRAM. It is a popular choice for various applications, including color detection, ambient light sensing, and optical proximity sensing.
Pinout
The TCS34725 has a total of 6 pins:
| Pin | Function |
| --- | --- |
| VCC | Power supply (1.8V to 3.6V) |
| GND | Ground |
| SCL | I2C clock |
| SDA | I2C data |
| INT | Interrupt output |
| ADDR | Address selection (optional) |
Communication Protocol
The TCS34725 uses the I2C protocol for communication. The device address can be set to one of two possible addresses (0x29 or 0x39) using the ADDR pin.
Code Examples
### Example 1: Basic Color Reading using Arduino
This example demonstrates how to read RGB color values from the TCS34725 using an Arduino board.
```c
#include <Wire.h>
#include <TCS34725.h>
TCS34725 tcs = TCS34725();
void setup() {
  Serial.begin(9600);
  Wire.begin();
  tcs.begin();
}
void loop() {
  uint16_t r, g, b;
  tcs.getRGB(r, g, b);
  Serial.print("R: ");
  Serial.print(r);
  Serial.print(" G: ");
  Serial.print(g);
  Serial.print(" B: ");
  Serial.println(b);
  delay(1000);
}
```
### Example 2: Color Detection using Raspberry Pi (Python)
This example demonstrates how to use the TCS34725 with a Raspberry Pi to detect specific colors and trigger an action.
```python
import smbus
import time
# Define the I2C bus and device address
bus = smbus.SMBus(1)
address = 0x29
# Define the color detection thresholds
RED_THRESHOLD = 200
GREEN_THRESHOLD = 150
BLUE_THRESHOLD = 100
while True:
  # Read the RGB values
  rgb = bus.read_i2c_block_data(address, 0x14, 6)
  r = rgb[0] << 8 | rgb[1]
  g = rgb[2] << 8 | rgb[3]
  b = rgb[4] << 8 | rgb[5]
# Detect specific colors
  if r > RED_THRESHOLD:
    print("Red detected!")
  elif g > GREEN_THRESHOLD:
    print("Green detected!")
  elif b > BLUE_THRESHOLD:
    print("Blue detected!")
time.sleep(0.5)
```
### Example 3: Ambient Light Sensing using ESP32 (C++)
This example demonstrates how to use the TCS34725 with an ESP32 board to read ambient light levels and adjust the brightness of an LED accordingly.
```c
#include <WiFi.h>
#include <TCS34725.h>
TCS34725 tcs = TCS34725();
const int ledPin = 2;
void setup() {
  Serial.begin(115200);
  pinMode(ledPin, OUTPUT);
  tcs.begin();
}
void loop() {
  uint16_t lux;
  tcs.getLux(lux);
  Serial.print("Lux: ");
  Serial.println(lux);
// Adjust the LED brightness based on the ambient light level
  if (lux < 100) {
    analogWrite(ledPin, 255);
  } else if (lux < 500) {
    analogWrite(ledPin, 128);
  } else {
    analogWrite(ledPin, 0);
  }
delay(1000);
}
```
These examples demonstrate the basic usage of the TCS34725 RGB color sensor in various contexts. You can modify and extend these examples to suit your specific application requirements.