-40C to 85C
-40C to 85C
-40C to 125C
2.5V to 3.6V
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.
TCS34725 RGB Color Sensor DocumentationOverviewThe 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.PinoutThe 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 ProtocolThe 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 ArduinoThis 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 = 100while 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.