TCS3472x I2C Color Sensor


The TCS34725 can be purchased as a module, for example from Adafruit. In this case, simply connect Vcc, Gnd, SDA, and SCL to the corresponding pins on the Espruino. Many of these modules also feature a white LED which can be used to illuminate the object being viewed by the color sensor; this may or may not be a useful feature.

If using the bare chip, you will meed an appropriate breakout board for a DFN-6 package, with extended pads so that you can solder to it (unless you're using a reflow oven to solder it). A 0.1uf cap should be used for bypassing - a 0603 cap is the right length that it can be placed right across the Vcc and Gnd pads, provided they're large enough. Soldering the DFN-6 part is tricky, but using the drag soldering technique and some flux, it can be done by hand. If there are not already pullup resistors on the I2C bus (for example, from other connected modules), a 10k pullup resistor must be included from SCL and SDA to Vcc.


Setup I2C, then call:

var tcs=require("TCS3472x").connect(i2c, integration_cycles, gain)

i2c is the i2c bus.

integration_cycles is number of integration cycles to use for each reading 1 to 256. Each cycle takes 2.4ms, and the output of the ADC from each cycle are summed, so the values can be up to 1024*integration_cycles. This means that values of higher than 64 will result in data being clipped at the high end. Using more integration cycles results in more stable readings and reduces the impact of noise, at the cost of making the sensing less responsive to rapid changes and brief events.

gain sets the gain of the sensor, for use in low light conditions. Valid options are 1, 4, 16, or 64.

These support the same interface as the SPI (AT25) and OneWire EEPROM modules


Returns an object with properties clear, red, green, and blue. These are all numbers from 0-0xFFFF on a successful read, or -1 if the chip reports that no data was ready to read for whatever reason.


Sets the gain - gain must be 1, 4, 16, or 60 - no other values of gain are supported.


Sets the number of integration cycles to use, from 1 to 256.


I2C1.setup({scl:B6, sda:B7});
var tcs=require("TCS3472x").connect(I2C1, 1 /*integration cycles*/, 1 /*gain*/);

var v = tcs.getValue();

If you want to use the colour from the sensor, you may want to discard the brightness and saturation information. You can do this as follows:

var v = tcs.getValue();
var min = Math.min(,,;
var range = Math.max(,, - min;
var rgb = [ // values between 0 and 255
  ( - min)*255/range,
  ( - min)*255/range,
  ( - min)*255/range,

This page is auto-generated from GitHub. If you see any mistakes or have suggestions, please let us know.