Assembly and Wiring
Both color sensors come with all surface mount components pre-soldered. The breakout-board version comes with an optional header for breadboard use. Soldering the header is a simple process:
Assembly (breakout version only)
Position the header
Trim the header to length if necessary and insert it (long pins down) into your breadboard.
Position the Breakout
Place the breakout over the exposed short end of the header pins.
And Solder!
Solder all pins to ensure good electrical contact.
Wiring
These sensors communicate via a 2-wire I2C interface. To connect to the processor, you need a total of just 4 wires.
Flora Wiring:
Connect from:
- 3.3v -> 3v (red wire)
- GND -> GND (black wire)
- SDA -> SDA (white wire)
- SCL -> SCL (green wire)
Arduino Wiring:
Connect jumpers from:
- 5v -> VIN (red wire)
- GND -> GND (black wire)
- SDA -> SDA (orange wire)
- SCL -> SCL (white wire)
Note: On older Arduinos such as the Duemilanove and pre R3 UNOs, SDA is on Analog 4 and SCL is on Analog 5.
On pre-R2 Megas, SDA is on Digtital 20 and SCL is on digital 21.
For the Leonardo, SDA is digital pin 2 and SCL is digital pin 3.
To control the LED
(Breakout version only) – The LED pin can be pulled low to turn off the LED. This can be done in three ways:
- Wire directly to ground to turn it off completely.
- Wire to a spare digital pin and control it with digitalWrite().
- Wire the LED pin to the INT pin and control with setInterrupt() (See Library Reference for details).
Demo Program
#include <Wire.h>
#include “Adafruit_TCS34725.h”
// Pick analog outputs, for the UNO these three work well
// use ~560 ohm resistor between Red & Blue, ~1K for green (its brighter)
#define redpin 3
#define greenpin 5
#define bluepin 6
// for a common anode LED, connect the common pin to +5V
// for common cathode, connect the common to ground
// set to false if using a common cathode LED
#define commonAnode true
// our RGB -> eye-recognized gamma color
byte gammatable[256];
Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_50MS, TCS34725_GAIN_4X);
void setup() {
Serial.begin(9600);
//Serial.println(“Color View Test!”);
if (tcs.begin()) {
//Serial.println(“Found sensor”);
} else {
Serial.println(“No TCS34725 found … check your connections”);
while (1); // halt!
}
// use these three pins to drive an LED
#if defined(ARDUINO_ARCH_ESP32)
ledcAttach(redpin, 12000, 8);
ledcAttach(greenpin, 12000, 8);
ledcAttach(bluepin, 12000, 8);
#else
pinMode(redpin, OUTPUT);
pinMode(greenpin, OUTPUT);
pinMode(bluepin, OUTPUT);
#endif
// thanks PhilB for this gamma table!
// it helps convert RGB colors to what humans see
for (int i=0; i<256; i++) {
float x = i;
x /= 255;
x = pow(x, 2.5);
x *= 255;
if (commonAnode) {
gammatable[i] = 255 – x;
} else {
gammatable[i] = x;
}
//Serial.println(gammatable[i]);
}
}
// The commented out code in loop is example of getRawData with clear value.
// Processing example colorview.pde can work with this kind of data too, but It requires manual conversion to
// [0-255] RGB value. You can still uncomments parts of colorview.pde and play with clear value.
void loop() {
float red, green, blue;
//tcs.setInterrupt(false); // turn on LED
delay(60); // takes 50ms to read
tcs.getRGB(&red, &green, &blue);
tcs.setInterrupt(true); // turn off LED
Serial.print(“R:t”); Serial.print(int(red));
Serial.print(“tG:t”); Serial.print(int(green));
Serial.print(“tB:t”); Serial.print(int(blue));
Serial.print(“n”);
#if defined(ARDUINO_ARCH_ESP32)
ledcWrite(1, gammatable[(int)red]);
ledcWrite(2, gammatable[(int)green]);
ledcWrite(3, gammatable[(int)blue]);
#else
analogWrite(redpin, gammatable[(int)red]);
analogWrite(greenpin, gammatable[(int)green]);
analogWrite(bluepin, gammatable[(int)blue]);
#endif
}





