In this example we connect a TCS34725 Color sensor to an Intel Galileo, lets look at some details about this sensor first
The TCS34725 device provides a digital return of red, green, blue (RGB), and clear light sensing values. An IR blocking filter, integrated on-chip and localized to the color sensing photodiodes, minimizes the IR spectral component of the incoming light and allows color measurements to be made accurately.
The high sensitivity, wide dynamic range, and IR blocking filter make the TCS3472 an ideal color sensor solution for use under varying lighting conditions and through attenuating materials. This data is transferred via an I2C to the host.
- Minimizes IR and UV spectral component effects to produce accurate color measurement
- Enables accurate color and ambient light sensing under varying lighting conditions
- Minimizes motion / transient errors
- Clear-Channel provides a reference allows for isolation of color content
Parts List
Label | Part Type |
---|---|
Part1 | Intel Galileo Gen2 |
Part4 | Adafruit TCS34725 RGB Color Sensor |
Layout
Code
This example uses the https://github.com/adafruit/Adafruit_TCS34725
[codesyntax lang=”cpp”]
#include <Wire.h> #include "Adafruit_TCS34725.h" /* Example code for the Adafruit TCS34725 breakout library */ /* Connect SCL to analog 5 Connect SDA to analog 4 Connect VDD to 3.3V DC Connect GROUND to common ground */ /* Initialise with default values (int time = 2.4ms, gain = 1x) */ // Adafruit_TCS34725 tcs = Adafruit_TCS34725(); /* Initialise with specific int time and gain values */ Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_700MS, TCS34725_GAIN_1X); void setup(void) { Serial.begin(9600); if (tcs.begin()) { Serial.println("Found sensor"); } else { Serial.println("No TCS34725 found ... check your connections"); while (1); } // Now we're ready to get readings! } void loop(void) { uint16_t r, g, b, c, colorTemp, lux; tcs.getRawData(&r, &g, &b, &c); colorTemp = tcs.calculateColorTemperature(r, g, b); lux = tcs.calculateLux(r, g, b); Serial.print("Color Temp: "); Serial.print(colorTemp, DEC); Serial.print(" K - "); Serial.print("Lux: "); Serial.print(lux, DEC); Serial.print(" - "); Serial.print("R: "); Serial.print(r, DEC); Serial.print(" "); Serial.print("G: "); Serial.print(g, DEC); Serial.print(" "); Serial.print("B: "); Serial.print(b, DEC); Serial.print(" "); Serial.print("C: "); Serial.print(c, DEC); Serial.print(" "); Serial.println(" "); }
[/codesyntax]
Testing
Open the serial monitor and you should see the following
Color Temp: 3476 K – Lux: 64 – R: 129 G: 103 B: 77 C: 304
Color Temp: 2864 K – Lux: 286 – R: 495 G: 392 B: 234 C: 1149
Color Temp: 1667 K – Lux: 1342 – R: 4339 G: 2248 B: 1089 C: 7677
Color Temp: 1629 K – Lux: 1576 – R: 5522 G: 2727 B: 1277 C: 9540
Color Temp: 3263 K – Lux: 217 – R: 295 G: 271 B: 156 C: 740
Color Temp: 3173 K – Lux: 44 – R: 95 G: 72 B: 53 C: 211
Color Temp: 2867 K – Lux: 35 – R: 86 G: 61 B: 45 C: 183
Color Temp: 3941 K – Lux: 53 – R: 789 G: 283 B: 187 C: 1239
Color Temp: 5384 K – Lux: 92 – R: 2359 G: 788 B: 527 C: 3656
Link
1PCS CJMCU-34725 TCS34725 Color Sensor RGB color sensor development board module