tutorialspinouttools
Sensors · ESP32-C3

TSL2561 on OLED: Light Level (Broadband + IR)

Free ESP32 & Arduino tutorial · wiring, code & parts · gokul.builds

Overview & Wiring

What it is: The TSL2561 is a light sensor with two photodiodes — one for visible+IR and one for IR only — so it can compute lux accurately across a huge range (0.1 to 40000 lux) and auto-range for both dim and bright scenes. How it works: I2C device (default address 0x39). The Adafruit Unified Sensor library combines the two channels into a calibrated lux value and can auto-select gain and integration time. Shares SDA/SCL with the OLED. Wiring (shared I2C bus with the OLED): TSL2561 SDA -> GPIO4 TSL2561 SCL -> GPIO5 TSL2561 VCC -> 3V3 TSL2561 GND -> GND OLED VCC=3V3, GND=GND, SDA=GPIO4, SCL=GPIO5 Libraries: "Adafruit TSL2561" and "Adafruit Unified Sensor" (installs "Adafruit BusIO"), plus "Adafruit SSD1306" and "Adafruit GFX Library". On screen / Serial: light in lux. A reading of 0 in a very bright scene usually means saturation — auto-range handles most cases. Gotchas: Address is 0x39 by default (0x29 if ADDR to GND, 0x49 if to VCC). Keep the plastic window clean; fingerprints skew the lux.

Circuit Diagram

TSL2561 on OLED: Light Level (Broadband + IR) wiring diagram for ESP32-C3

Parts You Need

ESP32-C3 SuperMiniBuy →
0.96" SSD1306 OLEDBuy →

Source Code (Arduino / ESP32)

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_TSL2561_U.h>

Adafruit_SSD1306 display(128, 64, &Wire, -1);
Adafruit_TSL2561_Unified tsl = Adafruit_TSL2561_Unified(TSL2561_ADDR_FLOAT, 12345);

void setup() {
  Serial.begin(115200);
  Wire.begin(4, 5);
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  if (!tsl.begin()) {
    Serial.println("TSL2561 not found");
    display.setTextColor(SSD1306_WHITE);
    display.setCursor(0, 28); display.println("TSL2561 not found");
    display.display();
    while (1) delay(10);
  }
  tsl.enableAutoRange(true);
  tsl.setIntegrationTime(TSL2561_INTEGRATIONTIME_101MS);
}

void loop() {
  sensors_event_t event;
  tsl.getEvent(&event);
  float lux = event.light;                    // 0 if overloaded

  display.clearDisplay();
  display.setTextColor(SSD1306_WHITE);
  display.setTextSize(1);
  display.setCursor(0, 0);
  display.println("TSL2561 Light");
  display.setTextSize(3);
  display.setCursor(0, 22);
  display.printf("%.0f", lux);
  display.setTextSize(1);
  display.setCursor(0, 54); display.print("lux");
  display.display();

  Serial.printf("Light: %.1f lux\n", lux);
  delay(500);
}
Browse all tutorials ESP32-C3 pinout Calculators