Using a LTR-303 Ambient Light sensor with an ESP8266

In this article we look at an Ambient Light sensor, the LTR-303 and connect it to an ESP8266 board – a Wemos D1 Mini pro was what I had at hand

Sensor Information

The LTR-303ALS is a low cost,small, I2C Ambient Light sensor. The LTR-303ALS comes in a 2.0×2.0×0.7mm 6pin DFN package.

The LTR-303ALS has an operating voltage of 2.4-3.6V with I2C operation down to 1.7V. The LTR-303ALS provides a full dynamic range from 0.01-64K lux while providing close to the eye spectral response with immunity to IR/UV light sources and automatically rejects 50/60Hz light flicker.

There are 6 gain settings available 1X, 2X, 3X, 4X, 8X, 48X, and 96X) to the user and provides a 16-bit effective resolution output.


I2C interface (Fast Mode @ 400kbit/s)
Ultra-small 6-pin ChipLED package 2.0mm(L), 2.0mm(B), 0.7mm(H)
Built-in temperature compensation circuit
Low active power consumption with standby mode
Supply voltage range from 2.4V to 3.6V capable of 1.7V logic voltage
Operating temperature range from -30C to +70C
RoHS and Halogen free compliant
Close to human eye spectral response
Immunity to IR / UV Light Source
Automatically rejects 50 / 60 Hz lightings flicker
Full dynamic range from 0.01 lux to 64k lux
16-bit effective resolution

Parts Required

You can connect to the sensor using dupont style jumper wire.

Name Link
Arduino Uno Aliexpress Link
Ebay Link
Amazon Link
Connecting cables Aliexpress Link
Ebay Link
Amazon Link


I used 3.3v from the Wemos  – 5v should be ok as the adafruit sensor has a voltage regulator on it.

Code Example

I installed the adafruit library using the arduino ide which also installed the dependency library

Click the Manage Libraries … menu item, search for LTR329_LTR303, and select the Adafruit LTR329 LTR303 library

If asked about dependencies, click on the “Install all” option

If the Dependencies window does appear, then you already have the required dependencies already installed.

If the dependencies are already installed, make sure that you have the latest ones installed using the Arduino Library Manager

This is the default example with the delay set to 1000ms rather than 100ms which seemed a bit to short a delay for simple testing

#include "Adafruit_LTR329_LTR303.h"

Adafruit_LTR303 ltr = Adafruit_LTR303();

void setup() {
  while (!Serial) {
    delay(10); // wait for serial port to open
  Serial.println("Adafruit LTR-303 simple test");

  if ( ! ltr.begin() ) {
    Serial.println("Couldn't find LTR sensor!");
    while (1) delay(10);
  Serial.println("Found LTR sensor!");

  // Set gain of 1 (see advanced demo for all options!
  // Set integration time of 50ms (see advanced demo for all options!
  // Set measurement rate of 50ms (see advanced demo for all options!

void loop() {
  bool valid;
  uint16_t visible_plus_ir, infrared;

  if (ltr.newDataAvailable()) {
    valid = ltr.readBothChannels(visible_plus_ir, infrared);
    if (valid) {
      Serial.print("CH0 Visible + IR: ");
      Serial.print("\t\tCH1 Infrared: ");




Here is  an example of what I saw in the serial monitor window – you may see some different results

This was the results I saw

Found LTR sensor!
CH0 Visible + IR: 9 CH1 Infrared: 7
CH0 Visible + IR: 5 CH1 Infrared: 4
CH0 Visible + IR: 5 CH1 Infrared: 4
CH0 Visible + IR: 5 CH1 Infrared: 4
CH0 Visible + IR: 5 CH1 Infrared: 4
CH0 Visible + IR: 4 CH1 Infrared: 4
CH0 Visible + IR: 5 CH1 Infrared: 3