Overview
The Adafruit OPT4048 Tri-Stimulus XYZ Color, Light Temperature and Lux Sensor is a modern take on the common 'RGB' color sensor: this time with true "CIE" XYZ output so you can match it to your existing color space. It's also excellent for calculating color temperature, which is based on CIE, and as a bonus also has Lux calculation, up to 144 kLux for light measurement, even in the brightest situations.
The OPT4048 has a lot of configurability, with the ability to adjust the integration time (how long light is being measured) to set the sensitivity of your measurements depending on the lighting conditions, from 600 μs for ultra-bright to 800 ms-per-channel in dim situations. There's also an interrupt for low/high threshold.
To make the sensor easy to use, we've taken the OPT4048 and put it onto a breakout PCB along with support circuitry to let you use this little wonder with 3.3V (Feather/Raspberry Pi) or 5V (Arduino/ Metro328) logic levels. Additionally since it speaks I2C you can easily connect it up with two wires (plus power and ground!). We've even included SparkFun qwiic compatible STEMMA QT connectors for the I2C bus so you don't even need to solder!
Just wire up to your favorite microcontroller and you can use our CircuitPython/Python or Arduino drivers to easily interface with the OPT4048 and get CIE, Lux and light color temperature readings in a minute! QT Cable is not included, but we have a variety in the shop.
Page last edited June 02, 2025
Text editor powered by tinymce.
Pinouts
The default I2C address is 0x44.
Power Pins
- VIN - this is the power pin. To power the board, give it the same power as the logic level of your microcontroller - e.g. for a 5V micro like Arduino, use 5V
- GND - common ground for power and logic
I2C Logic Pins
- SCL - I2C clock pin, connect to your microcontroller's I2C clock line. This pin can use 3-5V logic, and there's a 10K pullup on this pin.
- SDA - I2C data pin, connect to your microcontroller's I2C data line. This pin can use 3-5V logic, and there's a 10K pullup on this pin.
- STEMMA QT - These connectors allow you to connect to dev boards with STEMMA QT (qwiic) connectors or to other things with various associated accessories
Address Pin and Jumper
- ADDR - The address pin for setting the I2C address. You can chain up to two of these boards together on one I2C bus. Leave this pin low for default I2C address 0x44 or tie it high for I2C address 0x45.
- Addr Jumper - On the back of the board is the address jumper, labeled Addr. You can leave this jumper closed (low) to keep the board on the default I2C address 0x44. Cut the jumper open (high) to change the I2C address to 0x45.
- INT - This is the interrupt pin. It is an open-drain interrupt. To use, connect the pin to a GPIO along with a 10K pull-up resistor to VIN. When an interrupt is trigged, the pin will be pulled LOW.
Power LED and LED Jumper
- Power LED - In the upper left corner, above the STEMMA connector, on the front of the board, is the power LED, labeled on. It is a green LED.
- LED jumper - This jumper, labeled LED on the board silk, is located on the front of the board, in the upper left corner. Cut the trace on this jumper to cut power to the "on" LED.
Page last edited June 02, 2025
Text editor powered by tinymce.
CircuitPython and Python
It's easy to use the OPT4048 with Python or CircuitPython, and the Adafruit_CircuitPython_OPT4048 module. This module allows you to easily write Python code to read data from the sensor.
You can use this driver with any CircuitPython microcontroller board or with a computer that has GPIO and Python thanks to Adafruit_Blinka, our CircuitPython-for-Python compatibility library.
CircuitPython Microcontroller Wiring
First wire up a OPT4048 to your board exactly as shown below. Here's an example of wiring a Feather RP2040 to the sensor with I2C using one of the handy STEMMA QT connectors:
-
Board STEMMA 3V to sensor VCC (red wire)
-
Board STEMMA GND to sensor GND (black wire)
-
Board STEMMA SCL to sensor SCL (yellow wire)
- Board STEMMA SDA to sensor SDA (blue wire)
The following is the OPT4048 wired to a Feather RP2040 using a solderless breadboard:
-
Board 3V to sensor VCC (red wire)
-
Board GND to sensor GND (black wire)
-
Board SCL to sensor SCL (yellow wire)
- Board SDA to sensor SDA (blue wire)
Python Computer Wiring
Since there are dozens of Linux computers/boards you can use, we will show wiring for Raspberry Pi. For other platforms, please visit the guide for CircuitPython on Linux to see whether your platform is supported.
Here's the Raspberry Pi wired with I2C using the STEMMA connector:
-
Pi 3V to sensor VCC (red wire)
-
Pi GND to sensor GND (black wire)
-
Pi SCL to sensor SCL (yellow wire)
- Pi SDA to sensor SDA (blue wire)
Here's the Raspberry Pi wired with I2C using a solderless breadboard:
-
Pi 3V to sensor VCC (red wire)
-
Pi GND to sensor GND (black wire)
-
Pi SCL to sensor SCL (yellow wire)
- Pi SDA to sensor SDA (blue wire)
Python Installation of OPT4048 Library
You'll need to install the Adafruit_Blinka library that provides the CircuitPython support in Python. This may also require enabling I2C on your platform and verifying you are running Python 3. Since each platform is a little different, and Linux changes often, please visit the CircuitPython on Linux guide to get your computer ready!
Once that's done, from your command line run the following command:
pip3 install adafruit-circuitpython-opt4048
If your default Python is version 3 you may need to run 'pip' instead. Just make sure you aren't trying to use CircuitPython on Python 2.x, it isn't supported!
CircuitPython Usage
To use with CircuitPython, you need to first install the Adafruit_CircuitPython_OPT4048 library, and its dependencies, into the lib folder on your CIRCUITPY drive. Then you need to update code.py with the example script.
Thankfully, we can do this in one go. In the example below, click the Download Project Bundle button below to download the necessary libraries and the code.py file in a zip file. Extract the contents of the zip file, and copy the entire lib folder and the code.py file to your CIRCUITPY drive.
Your CIRCUITPY/lib folder should contain the following folder and file:
- adafruit_bus_device/
- adafruit_register/
- adafruit_opt4048.mpy
Python Usage
Once you have the library pip3 installed on your computer, copy or download the following example to your computer, and run the following, replacing code.py with whatever you named the file:
python3 code.py
Example Code
If running CircuitPython: Once everything is saved to the CIRCUITPY drive, connect to the serial console to see the data printed out!
If running Python: The console output will appear wherever you are running Python.
# SPDX-FileCopyrightText: Copyright (c) 2025 Tim C for Adafruit Industries
# SPDX-License-Identifier: MIT
"""
A basic demo for using the OPT4048 tristimulus XYZ color sensor
This example reads the sensor values from all four channels (X, Y, Z, W),
demonstrates setting and getting threshold values, and displays the results.
"""
import time
from time import sleep
import board
from adafruit_opt4048 import OPT4048, ConversionTime, Mode, Range
i2c = board.I2C() # uses board.SCL and board.SDA
# i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller
sensor = OPT4048(i2c)
sensor.range = Range.AUTO
sensor.conversion_time = ConversionTime.TIME_100MS
sensor.mode = Mode.CONTINUOUS
while True:
try:
x, y, lux = sensor.cie
print(f"CIE x:{x}, y:{y}, lux: {lux}", end=" ")
print(f"K: {sensor.calculate_color_temperature(x, y)}")
time.sleep(1)
except RuntimeError:
# CRC check failed while reading data
pass
First, the sensor gets initialized over I2C, then configured for automatic range, 100ms conversion time, and continuous reading mode. In the main loop CIE color and lux data are read from the sensor and printed to the serial console once per second.
Page last edited June 02, 2025
Text editor powered by tinymce.
Arduino
Using the OPT4048 breakout with Arduino involves wiring up the breakout to your Arduino-compatible microcontroller, installing the Adafruit_OPT4048 library, and running the provided example code.
Wire as shown for a 5V board like an Uno. If you are using a 3V board, like an Adafruit Feather, wire the board's 3V pin to the sensor VIN.
Here is an Adafruit Metro wired up to the sensor using the STEMMA QT connector:
-
Board 5V to sensor VCC (red wire)
-
Board GND to sensor GND (black wire)
-
Board SCL to sensor SCL (yellow wire)
- Board SDA to sensor SDA (blue wire)
Here is an Adafruit Metro wired up using a solderless breadboard:
-
Board 5V to sensor VCC (red wire)
-
Board GND to sensor GND (black wire)
-
Board SCL to sensor SCL (yellow wire)
- Board SDA to sensor SDA (blue wire)
Library Installation
You can install the Adafruit_OPT4048 library for Arduino using the Library Manager in the Arduino IDE.
Search for Adafruit_OPT4048, and select the Adafruit_OPT4048 library, then click the Install button.
If asked about dependencies, click "Install all".
If the "Dependencies" window does not come up, then you already have the dependencies installed.
/*!
* @file test_opt4048.ino
*
* A basic demo for using the OPT4048 tristimulus XYZ color sensor
*
* This example reads the sensor values from all four channels (X, Y, Z, W),
* demonstrates setting and getting threshold values, and displays the results.
*/
#include <Wire.h>
#include "Adafruit_OPT4048.h"
// Create sensor object
Adafruit_OPT4048 sensor;
void setup() {
// Initialize serial communication
Serial.begin(115200);
// Wait for serial monitor to open
while (!Serial) {
delay(10);
}
Serial.println(F("Adafruit OPT4048 Tristimulus XYZ Color Sensor Test"));
// Initialize the sensor
if (!sensor.begin()) {
Serial.println(F("Failed to find OPT4048 chip"));
while (1) {
delay(10);
}
}
Serial.println(F("OPT4048 sensor found!"));
sensor.setRange(OPT4048_RANGE_AUTO); // Set range to auto
sensor.setConversionTime(OPT4048_CONVERSION_TIME_100MS); // Set conversion time to 100ms
sensor.setMode(OPT4048_MODE_CONTINUOUS); // Set operating mode to continuous
}
void loop() {
// Calculate and display CIE chromaticity coordinates and lux
double CIEx, CIEy, lux;
if (sensor.getCIE(&CIEx, &CIEy, &lux)) {
Serial.println(F("\nCIE Coordinates:"));
Serial.print(F("CIE x: ")); Serial.println(CIEx, 8);
Serial.print(F("CIE y: ")); Serial.println(CIEy, 8);
Serial.print(F("Lux: ")); Serial.println(lux, 4);
// Calculate and display color temperature
double colorTemp = sensor.calculateColorTemperature(CIEx, CIEy);
Serial.print(F("Color Temperature: "));
Serial.print(colorTemp, 2);
Serial.println(F(" K"));
} else {
Serial.println(F("Error reading sensor data"));
}
delay(1000); // Read once per second
}
Page last edited June 02, 2025
Text editor powered by tinymce.
Webserial Demo
The OPT4048 sensor outputs color as true "CIE" XYZ output so you can match it to your existing color space. It's also excellent for calculating color temperature, which is based on CIE, and as a bonus also has Lux calculation, up to 144 kLux for light measurement even in the brightest situations.
This example will visualize what the "CIE" XYZ data coming out the sensor actually means. Data will be plotted onto a chart depicting the full range of colors.
The example works with the following web page:
Microcontroller Wiring
First wire up a OPT4048 to your board exactly as shown below. Here's an example of wiring a Feather RP2040 to the sensor with I2C using one of the handy STEMMA QT connectors:
-
Board STEMMA 3V to sensor VCC (red wire)
-
Board STEMMA GND to sensor GND (black wire)
-
Board STEMMA SCL to sensor SCL (yellow wire)
- Board STEMMA SDA to sensor SDA (blue wire)
The following is the OPT4048 wired to a Feather RP2040 using a solderless breadboard:
-
Board 3V to sensor VCC (red wire)
-
Board GND to sensor GND (black wire)
-
Board SCL to sensor SCL (yellow wire)
- Board SDA to sensor SDA (blue wire)
Following the instructions from the CircuitPython guide page, download the project bundle and copy the libraries and code file to your device.
# SPDX-FileCopyrightText: Copyright (c) 2025 Tim C for Adafruit Industries
# SPDX-License-Identifier: MIT
"""
This example reads color data from the OPT4048 sensor and outputs it
in a format suitable for displaying on a web page using Web Serial API.
It continuously measures CIE x,y coordinates, lux, and color temperature.
This example works with the web interface in the /webserial directory of the
gh-pages branch of the Arduino driver repo: https://github.com/adafruit/Adafruit_OPT4048/tree/gh-pages,
which can be accessed at: https://adafruit.github.io/Adafruit_OPT4048/webserial/
"""
import time
from time import sleep
import board
from adafruit_opt4048 import OPT4048, ConversionTime, Mode, Range
READ_INTERVAL = 0.1 # seconds
i2c = board.I2C() # uses board.SCL and board.SDA
# i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller
sensor = OPT4048(i2c)
sensor.range = Range.AUTO
sensor.conversion_time = ConversionTime.TIME_100MS
sensor.mode = Mode.CONTINUOUS
last_read_time = 0
while True:
if time.monotonic() > last_read_time + READ_INTERVAL:
try:
last_read_time = time.monotonic()
x, y, lux = sensor.cie
print("---CIE Data---")
print(f"CIE x: {x}")
print(f"CIE y: {y}")
print(f"Lux: {lux}")
print(f"Color Temperature: {sensor.calculate_color_temperature(x, y)} K")
print("-------------")
except RuntimeError:
# CRC check failed while reading data
pass
Follow the instructions from the Arduino guide page to install the required libraries, then run the following code on your device.
/*!
* @file opt4048_webserial.ino
*
* This example reads color data from the OPT4048 sensor and outputs it
* in a format suitable for displaying on a web page using Web Serial API.
*
* It continuously measures CIE x,y coordinates, lux, and color temperature.
*
* This sketch works with the web interface in the /webserial directory of the
* gh-pages branch: https://github.com/adafruit/Adafruit_OPT4048/tree/gh-pages,
* which can be accessed at: https://adafruit.github.io/Adafruit_OPT4048/webserial/
*/
#include <Wire.h>
#include "Adafruit_OPT4048.h"
// Create sensor object
Adafruit_OPT4048 sensor;
// Set how often to read data (in milliseconds)
const unsigned long READ_INTERVAL = 100;
unsigned long lastReadTime = 0;
void setup() {
// Initialize serial communication at 115200 baud
Serial.begin(115200);
// Wait briefly for serial to connect (not needed for all boards)
delay(100);
Serial.println(F("Adafruit OPT4048 WebSerial Example"));
Serial.println(F("This sketch works with the OPT4048 CIE Color Plotter web page"));
// Initialize the sensor
if (!sensor.begin()) {
Serial.println(F("Failed to find OPT4048 chip"));
while (1) {
delay(10);
}
}
Serial.println(F("OPT4048 sensor found!"));
// Set sensor configuration
sensor.setRange(OPT4048_RANGE_AUTO); // Auto-range for best results across lighting conditions
sensor.setConversionTime(OPT4048_CONVERSION_TIME_100MS); // 100ms conversion time
sensor.setMode(OPT4048_MODE_CONTINUOUS); // Continuous mode
}
void loop() {
// Only read at the specified interval
unsigned long currentTime = millis();
if (currentTime - lastReadTime >= READ_INTERVAL) {
lastReadTime = currentTime;
// Calculate and display CIE chromaticity coordinates and lux
double CIEx, CIEy, lux;
if (sensor.getCIE(&CIEx, &CIEy, &lux)) {
// Print the values in a format that can be easily parsed by the web page
Serial.println(F("---CIE Data---"));
Serial.print(F("CIE x: ")); Serial.println(CIEx, 8);
Serial.print(F("CIE y: ")); Serial.println(CIEy, 8);
Serial.print(F("Lux: ")); Serial.println(lux, 4);
// Calculate and display color temperature
double colorTemp = sensor.calculateColorTemperature(CIEx, CIEy);
Serial.print(F("Color Temperature: "));
Serial.print(colorTemp, 2);
Serial.println(F(" K"));
Serial.println(F("-------------"));
} else {
Serial.println(F("Error reading sensor data"));
}
}
// Check for any incoming serial commands
if (Serial.available() > 0) {
String command = Serial.readStringUntil('\n');
command.trim();
// Process any commands here if needed
}
}
Plotter Usage
Once the demo code is loaded onto the microcontroller, then open the OPT4048 CIE Color Plotter Page on your computer.
- Click on the Connect to Microcontroller button.
- Click on the Feather RP2040 or whichever microcontroller is connected via USB to the computer. Then click the Connect button.
The page will read data sent to it by the microcontroller and plot the CIE x/y values onto the CIE 1931 Chromaticity Diagram.
Page last edited June 02, 2025
Text editor powered by tinymce.
Downloads
Page last edited June 02, 2025
Text editor powered by tinymce.