Skip to content

Color Sensor Wireling Tutorial

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

Use this sensor for colorful projects and lighting necessities!


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

Required Software


Hardware Assembly

Plug your Wireling into the port you plan on using!

If you want to use a different port, you just need to change the port value in the program mentioned later.


Programming

Install the necessary library:

pip3 install adafruit-circuitpython-tcs34725

Then you can download (above under Software) the Color Sensor Wireling Python example:

tcs34725_example.py
# TinyCircuits Color Sensor Wireling Python Example
# Prints color temperature, lux, and RGB values. There is a commented 
# out option that can be used to turn the LEDs on.
# Adapted from Adafruit example by: Laverena Wienclaw for TinyCircuits
# Last updated: 1-10-20

import time
import board
import busio
import adafruit_tcs34725
import tinycircuits_wireling

# Enable and power Wireling Pi Hat
wireling = tinycircuits_wireling.Wireling()

# Set and selectPort matching Color Sensor Wireling and Pi Hat port
port = 0
wireling.selectPort(0)

# Initialize I2C bus and sensor.
i2c = busio.I2C(board.SCL, board.SDA)
sensor = adafruit_tcs34725.TCS34725(i2c)

# Main loop reading color temp, lux, and RGB values and printing it every second
while True:
    # Turn on on-board LEDs
    #sensor.cycles = 0 # Set to -1 to turn off

    # Read  and print the color temperature and lux of the sensor 
    temp = sensor.color_temperature
    lux = sensor.lux
    print('Temperature: {0}K Lux: {1}'.format(temp, lux))

    # Read and print the RGB values read by sensor
    r, g, b = sensor.color_rgb_bytes
    print('R: {0}  G: {1}  B: {2}'.format(r, g, b))

    # Delay for a second and repeat.
    time.sleep(1.0)

Run Program

Navigate in the terminal to the directory with the file parent to the examples folder.

python3 tcs34725_example.py

Every second, the example program will print out the color temperature in terms of Kelvin, the illuminance in terms of lux, and the rgb colors on a scale of 0-255.


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