Overview
The TSL2591 is a high-dynamic-range digital light sensor. It has two photodiodes, one that sees visible plus infrared light and one that sees infrared only, with a 16-bit converter for each. Your code subtracts the infrared part and calculates illuminance in lux, close to the way the human eye judges brightness. Four gain settings and six integration times give it a 600,000,000:1 range, from 188 µlux up to 88,000 lux.
This pre-soldered breakout has a 6-pin header (VIN, 3Vo, GND, SCL, SDA and INT) plus two white 4-pin sockets on the sides for plug-in I2C cables. The board is labeled for 3 to 5 V, so it wires straight to 5 V Arduinos as well as 3.3 V boards such as the ESP32, Raspberry Pi and Pico. It talks I2C at the fixed address 0x29.
Use it for lux meters, automatic display dimming, grow-light and daylight logging, night-sky brightness, or any project that needs to tell visible light from infrared. This manual covers the pinout, wiring for Arduino, ESP32, Raspberry Pi and Pico, working code for each, and answers on gain, overflow readings and the side sockets.
At a Glance
Specifications
| Parameter | Value |
| Sensor IC | ams TSL2591 light-to-digital converter |
| Measuring range | 188 µlux to 88,000 lux |
| Dynamic range | 600,000,000:1 |
| Channels | CH0 full spectrum (visible + IR) · CH1 infrared, 16 bits each |
| Gain settings | 1× · 25× · 428× · 9876× |
| Integration time | 100 to 600 ms in 100 ms steps |
| Interface | I2C, fixed address 0x29 |
| Supply (VIN) | 3 – 5 V DC, as labeled on the board |
| 3Vo pin | 3.3 V output from the on-board regulator |
| INT pin | Optional interrupt output, not needed for basic readings |
| Connections | 6-pin header plus two 4-pin side sockets |
Pinout Diagram
Six pins run along the bottom edge: VIN (3 – 5 V power in), 3Vo (3.3 V out from the on-board regulator), GND, SCL and SDA (I2C), and INT (optional interrupt output). The two white 4-pin sockets on the sides carry the same I2C bus for plug-in cables. The pin order inside those sockets is not published for this board, so check it with a multimeter before trusting a ready-made cable. The small part in the center is the light sensor itself, so keep it uncovered and pointed at the light you want to measure.
Wiring Guide
Only four wires are needed: power, ground and the two I2C lines. Power VIN from the same voltage your board uses for logic: 5V on an Uno or Nano, 3.3 V on an ESP32, Raspberry Pi or Pico. 3Vo and INT stay unconnected.
Arduino Uno / Nano Wiring
| TSL2591 Pin | Arduino Pin | Notes |
|---|---|---|
| VIN | 5V | Power |
| GND | GND | Ground |
| SCL | A5 | I2C clock |
| SDA | A4 | I2C data |
ESP32 Wiring
| TSL2591 Pin | ESP32 Pin | Notes |
|---|---|---|
| VIN | 3V3 | Power |
| GND | GND | Ground |
| SCL | GPIO 22 | I2C clock |
| SDA | GPIO 21 | I2C data |
Raspberry Pi Wiring
| TSL2591 Pin | Raspberry Pi Pin | Notes |
|---|---|---|
| VIN | 3.3V (Pin 1) | Power |
| GND | GND (Pin 6) | Ground |
| SCL | GPIO 3 (Pin 5) | I2C clock |
| SDA | GPIO 2 (Pin 3) | I2C data |
Raspberry Pi Pico Wiring
| TSL2591 Pin | Pico Pin | Notes |
|---|---|---|
| VIN | 3V3(OUT) (Pin 36) | Power |
| GND | GND (Pin 38) | Ground |
| SCL | GP5 (Pin 7) | I2C0 clock |
| SDA | GP4 (Pin 6) | I2C0 data |
Code Examples
View or download this product's example code on GitHub.
All three examples use 25× gain and a 300 ms integration time, a good starting point for indoor light, and print the lux value once a second together with the raw channel counts.
Arduino and ESP32 — Lux, Full Spectrum and Infrared
// TSL2591 light sensor - lux, visible and infrared readings
// Library Manager: install "Adafruit TSL2591 Library" (it pulls in Adafruit Unified Sensor)
// Uno/Nano: SDA = A4, SCL = A5, VIN = 5V ESP32: SDA = GPIO 21, SCL = GPIO 22, VIN = 3V3
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_TSL2591.h>
Adafruit_TSL2591 tsl = Adafruit_TSL2591(2591); // the number is only a sensor ID
void setup() {
Serial.begin(115200);
if (!tsl.begin()) {
Serial.println("TSL2591 not found - check wiring (I2C address 0x29)");
while (true) { delay(1000); }
}
tsl.setGain(TSL2591_GAIN_MED); // 25x suits indoor light
tsl.setTiming(TSL2591_INTEGRATIONTIME_300MS); // longer time = more sensitive
}
void loop() {
uint32_t both = tsl.getFullLuminosity(); // upper 16 bits = infrared, lower 16 = full spectrum
uint16_t ir = both >> 16;
uint16_t full = both & 0xFFFF;
float lux = tsl.calculateLux(full, ir);
Serial.print("Full: ");
Serial.print(full);
Serial.print(" IR: ");
Serial.print(ir);
Serial.print(" Lux: ");
if (lux < 0) {
Serial.println("overflow - lower the gain");
} else {
Serial.println(lux, 2);
}
delay(1000);
}
Raspberry Pi — Python
#!/usr/bin/env python3
# TSL2591 light sensor on Raspberry Pi (I2C bus 1)
# Install once: pip3 install adafruit-circuitpython-tsl2591 (enable I2C in raspi-config)
import time
import board
import adafruit_tsl2591
i2c = board.I2C() # GPIO 2 = SDA, GPIO 3 = SCL
sensor = adafruit_tsl2591.TSL2591(i2c) # fixed address 0x29
sensor.gain = adafruit_tsl2591.GAIN_MED # 25x suits indoor light
sensor.integration_time = adafruit_tsl2591.INTEGRATIONTIME_300MS # longer = more sensitive
while True:
try:
print(f"Lux: {sensor.lux:.2f} Visible: {sensor.visible} "
f"IR: {sensor.infrared} Full: {sensor.full_spectrum}")
except RuntimeError:
print("Sensor overflow - lower the gain") # raised when a channel saturates
time.sleep(1.0)
Raspberry Pi Pico — MicroPython (Raw Registers)
# TSL2591 light sensor on Raspberry Pi Pico (MicroPython, no driver file needed)
# SDA = GP4 (pin 6), SCL = GP5 (pin 7), VIN = 3V3(OUT), GND = GND
from machine import I2C, Pin
import time
ADDR = 0x29
CMD = 0xA0 # command bit for normal register access
REG_ENABLE = 0x00
REG_CONTROL = 0x01
REG_ID = 0x12 # reads 0x50 on a TSL2591
REG_CH0_LOW = 0x14 # full spectrum, 2 bytes, low byte first
REG_CH1_LOW = 0x16 # infrared, 2 bytes, low byte first
GAIN = 0x10 # 0x00 = 1x, 0x10 = 25x, 0x20 = 428x, 0x30 = 9876x
GAIN_FACTOR = 25.0
TIME = 0x02 # 0x00 to 0x05 = 100 to 600 ms
TIME_MS = 300.0
i2c = I2C(0, sda=Pin(4), scl=Pin(5), freq=400000)
if i2c.readfrom_mem(ADDR, CMD | REG_ID, 1)[0] != 0x50:
raise RuntimeError("TSL2591 not found - check wiring")
i2c.writeto_mem(ADDR, CMD | REG_CONTROL, bytes([GAIN | TIME]))
i2c.writeto_mem(ADDR, CMD | REG_ENABLE, bytes([0x03])) # power on + enable the ADC
def read_channels():
time.sleep_ms(int(TIME_MS) + 120) # wait for one full integration
ch0 = int.from_bytes(i2c.readfrom_mem(ADDR, CMD | REG_CH0_LOW, 2), "little")
ch1 = int.from_bytes(i2c.readfrom_mem(ADDR, CMD | REG_CH1_LOW, 2), "little")
return ch0, ch1
def to_lux(ch0, ch1):
if ch0 == 0xFFFF or ch1 == 0xFFFF:
return None # saturated: lower the gain
if ch0 == 0:
return 0.0
cpl = (TIME_MS * GAIN_FACTOR) / 408.0 # counts per lux
return (ch0 - ch1) * (1.0 - ch1 / ch0) / cpl
while True:
full, ir = read_channels()
lux = to_lux(full, ir)
if lux is None:
print("Overflow - lower the gain")
else:
print("Lux: {:.2f} Full: {} IR: {}".format(lux, full, ir))
time.sleep(1)



