Angled view of the pre-soldered TSL2591 sensor board and side connectors

TSL2591 Pre-Soldered Digital Light Sensor Module | ShillehTek Product Manual

ArduinoESP32Raspberry PiPicomanual-product-10645385904415
$9.99 USD In stock · Order by 3pm ET, ships today

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

Sensor
TSL2591 light-to-digital
Range
188 µlux – 88,000 lux
Interface
I2C, address 0x29
Supply
3 – 5 V on VIN
Channels
Full spectrum + infrared
Gain
1× to 9876× in 4 steps

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.

TSL2591 light sensor module pinout diagram showing VIN, 3Vo, GND, SCL, SDA and INT pins

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
5 V friendly: The board is labeled for 3 to 5 V, so an Uno or Nano connects directly with no level converter.

ESP32 Wiring

TSL2591 Pin ESP32 Pin Notes
VIN 3V3 Power
GND GND Ground
SCL GPIO 22 I2C clock
SDA GPIO 21 I2C data
Address 0x29: 0x29 is fixed on the TSL2591 and is also the default address of the VL53L0X and VL53L1X distance sensors. To use them together, put one on a second I2C bus or behind a TCA9548A multiplexer.

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
Use 3.3 V: Power VIN from the Pi's 3.3 V pin, not 5 V, so that SDA and SCL stay at the 3.3 V level the Pi's GPIO pins require.
Enable I2C: Run sudo raspi-config, open Interface Options and turn on I2C. Then i2cdetect -y 1 should show the sensor as 29.

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
No driver: The MicroPython example below talks to the sensor's registers directly, so there is nothing extra to copy onto the Pico.

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_lux.ino
// 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

tsl2591_lux.py
#!/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_pico.py
# 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)

Frequently Asked Questions

Does the TSL2591 work with both 5 V and 3.3 V boards?
Yes. The board is labeled for 3 to 5 V on VIN. Power it from the same voltage your microcontroller uses for logic: the 5V pin on an Uno or Nano, and the 3.3 V pin on an ESP32, Raspberry Pi or Pico. That keeps the I2C lines at a level your board can safely read.
What do the two channels and the lux number mean?
Channel 0 is full spectrum, meaning visible plus infrared light, and channel 1 is infrared only. Subtracting channel 1 from channel 0 leaves roughly the visible part. Lux is then calculated from both counts, the gain and the integration time with an empirical formula. Treat it as a good estimate of brightness rather than a calibrated lab measurement.
Which gain and integration time should I use?
Start with 25× gain and 300 ms, the setting used in the examples, for normal indoor light. For bright daylight drop to 1× gain and 100 ms. For very dim scenes go up to 428× or 9876× with a longer integration time. Higher gain and longer times make the sensor more sensitive, but it also saturates sooner.
Why do I get an overflow message or a negative lux value?
One of the channels has hit its maximum count, so there is too much light for the current setting. The Arduino library returns -1 in that case and the Python library raises an error, which the examples report as an overflow. Lower the gain or shorten the integration time and the readings return.
Why does the sensor not show up at 0x29?
Check the four wires first: SDA and SCL swapped is the most common mistake, followed by a missing ground. The On LED should be lit when the board has power. On a Raspberry Pi make sure I2C is enabled in raspi-config. Also remember that 0x29 is shared with the VL53L0X and VL53L1X, so two such devices on one bus will clash.
What are the white side sockets and the INT pin for?
The sockets carry the same power and I2C signals as the header, in the style of STEMMA QT and Qwiic plug-in cables, so sensors can be chained without soldering. The pin order inside them is not published for this board, so confirm it with a multimeter before plugging in a ready-made cable. INT is an optional interrupt output that can signal when the light level crosses a threshold. Basic readings do not need it.
pip3 reports externally-managed-environment on my Raspberry Pi. What now?
Current Raspberry Pi OS blocks system-wide pip installs. Create a virtual environment once with python3 -m venv --system-site-packages ~/sensors, activate it with source ~/sensors/bin/activate, and then run the pip3 install line from the example inside it. Activate the environment again whenever you open a new terminal to run the script.

Related Tutorials

Datasheets & downloads

Reference documents for the TSL2591 Pre-Soldered Digital Light Sensor Module. This manual covers wiring and code; the documents below carry the full electrical specifications.