Skip to content

Color Sensor Wireling Tutorial

This tutorial will teach you the basic methods of reading the color temperature, RGB, lux, and clearness values of the area in proximity to the color sensor.

Use this sensor for colorful projects and lighting necessities!

To learn more about the TinyDuino Platform, click here


Description

This Wireling features a VL53L0X Infrared Time-of-Flight sensor, most often used for distance detection between 2cm and 2m!

TCS34725 Background
  • The high sensitivity, wide dynamic range, and IR blocking filter make the TCS34725 an ideal color sensor solution for use under varying lighting conditions and through attenuating materials.
  • Common applications include: Verification and sorting, fluid and gas analysis, ambient light sensing or RGB LED for backlight control, light color temperature measurement, etc.
  • Fun fact: It is common practice to have your home lighting measure around 500 lumens
  • This sensor can read a lot of interesting things based on color, light, and so on, but they're not exactly common knowledge things. Here's some background on the readings we'll demonstrate in this tutorial:
    • Color Temperature: The color temperature of an atmosphere is very important to fields like photography and horticulture. Measured in Kelvin for the absolute temperature, the heat of a color is a metric based on colors from a reddish orange, to a white, to a light blue. This range of hues measures the color temperature from cool to hot. There is a helpful table on Wikipedia that shows the color to temperature reading correlation. Since blue is hotter, and the reddish-orange is cooler and that's opposite of what one may initially think, it may help to think about the temperature difference in a blue or orange flame.
    • Lux: The official Merriam Webster definition is: "a unit of illumination equal to the direct illumination on a surface that is everywhere one meter from a uniform point source of one candle intensity or equal to one lumen per square meter." So basically, lux is the amount of light in an area in the proximity of the sensor. Check out the Wikipedia for another helpful table to better understand lux readings put out by the sensor.
    • R, G, B: The redness(R), greenness(G), and the blueness(B) of colors influencing the sensor.
    • Clr: The measured value of clear light. This figure from the datasheet may help explain the relationship between the RGB colors and the Clear value:
Diagram from TCS3472 datasheet showing relationship between RGB and Clear wavelengths.
Technical Details

AMS TCS3472 Color Sensor Specs

  • 16-bit color resolution 
  • I²C Communication Protocol
  • Ambient Light Detection
  • Color Temperature Detection
  • 2.5µA typ. during Sleep Mode
  • 65µA typ. during Wait State

LEDs

  • Populated for aid in color sensing
  • Can be toggled on/off in Arduino Sketch

TinyDuino Power Requirements

  • Voltage: 3.0V - 5.5V 
  • Current: 2.5uA (Low Power Sleep Mode)

Pins Used

  • A5/SCL - I²C Serial Clock line
  • A4/SDA - I²C Serial Data line

Dimensions

  • 10mm x 10mm (.394 inches x .394 inches)
  • Max Height (from the lower bottom of Wireling to upper top Wireling Connector): 4.30mm (0.17 inches)
  • Weight: 1 gram (.04 ounces)

Materials

Hardware

Software


Hardware Assembly

Hardware Assembled

Depending on the development system you choose, you will need to put together a TinyDuino stack using the 32-pin tan connectors, or you will just need to plug in your Wireling to Port 0 using a Wireling Cable. (You can change this port in the included Arduino Sketch using the Wireling.selectPort() function)


Software Setup

For this sensor, you will need the Adafruit_TCS34725 Arduino Library.

Upload Program

This program prints all the above mentioned sensor values from the TCS3472 sensor to the Serial Monitor and the TinyScreen+. The RGBC values will print out values between 0-65535, the Color Temperature will be within a range of 0-8890 degrees Kelvin, and the Lux value will be between 0-34196.

Code
/*************************************************************************
 * Color Sensor TCS34725 Wireling Tutorial:
 * This program will print the TCS34725 RGB, lux, and clearness values to 
 * the Serial Monitor
 * 
 * Note: I²C Address for Wireling board is different than the Adafruit 
 * component, this address change is reflected in the library that
 * should be included with this sketch 
 * 
 * Hardware by: TinyCircuits
 * Code by: Laveréna Wienclaw for TinyCircuits
 *
 * Initiated: 11/29/2017 
 * Updated: 12/18/2019
 ************************************************************************/

#include <Wire.h>         // For I2C communication with sensor
#include "Adafruit_TCS34725.h"  // The library used for the Color Sensor
#include <Wireling.h>     // For interfacing with Wirelings

/* Initialise with default values (int time = 2.4ms, gain = 1x) */
// Adafruit_TCS34725 tcs = Adafruit_TCS34725();

// Make compatible with all TinyCircuits processors
#if defined(ARDUINO_ARCH_AVR)
  #define SerialMonitorInterface Serial
#elif defined(ARDUINO_ARCH_SAMD)
  #define SerialMonitorInterface SerialUSB
#endif

/* Initialise with specific int time and gain values */
Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_700MS, TCS34725_GAIN_1X);

// Variables to hold the values the sensor reads
uint16_t r, g, b, c, colorTemp, lux;

void setup(void) {
  SerialMonitorInterface.begin(9600);
  Wire.begin();
  Wireling.begin();

  //The port is the number on the Adapter board where the sensor is attached
  Wireling.selectPort(0);

  if (tcs.begin()) {
    SerialMonitorInterface.println("Found sensor");
  } else {
    SerialMonitorInterface.println("No TCS34725 found ... check your connections");
    while (1);
  }

  // Turn Wireling LEDs on 
  LEDon();
}

void loop(void) {
  tcs.getRawData(&r, &g, &b, &c);
  colorTemp = tcs.calculateColorTemperature(r, g, b);
  lux = tcs.calculateLux(r, g, b);

  SerialMonitorInterface.print("Color Temp: "); SerialMonitorInterface.print(colorTemp); SerialMonitorInterface.print(" K, ");
  SerialMonitorInterface.print("Lux: "); SerialMonitorInterface.print(lux, DEC); SerialMonitorInterface.print(", ");
  SerialMonitorInterface.print("R: "); SerialMonitorInterface.print(r, DEC); SerialMonitorInterface.print(", ");
  SerialMonitorInterface.print("G: "); SerialMonitorInterface.print(g, DEC); SerialMonitorInterface.print(", ");
  SerialMonitorInterface.print("B: "); SerialMonitorInterface.print(b); SerialMonitorInterface.print(", ");
  SerialMonitorInterface.print("Clr: "); SerialMonitorInterface.print(c, DEC);
  SerialMonitorInterface.println(" ");

  delay(500);
}

// Turn Wireling LEDs on
void LEDon() {
  tcs.setInterrupt(true);
}

// Turn Wireling LEDs off
void LEDoff() {
  tcs.setInterrupt(false);
}

Contact Us

If you have any questions or feedback, feel free to email us at info@tinycircuits.com or make a post on the forum.

Show us what you make by tagging @TinyCircuits on Instagram, Twitter, or Facebook so we can feature it!

Thanks for making with us!


Downloads