Home » Connect an LTR-303 Ambient Light sensor to an ESP32

Connect an LTR-303 Ambient Light sensor to an ESP32

by shedboy71

In this article, we look at an Ambient Light sensor, the LTR-303, and connect it to an ESP32 board

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 6-pin 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 a 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.

Features

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
ESP32 Aliexpress link
LTR303 Ebay link
Connecting cables Male to Male + Male to Female and Female to Female Jumper Wire Dupont Cable

 

Schematic/Connection

I used 3.3v from the ESP32 and connected using the qwic sensor

 

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 too short a delay for simple testing

#include "Adafruit_LTR329_LTR303.h"

Adafruit_LTR303 ltr = Adafruit_LTR303();

void setup() {
  Serial.begin(115200);
  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!
  ltr.setGain(LTR3XX_GAIN_1);
  // Set integration time of 50ms (see advanced demo for all options!
  ltr.setIntegrationTime(LTR3XX_INTEGTIME_50);
  // Set measurement rate of 50ms (see advanced demo for all options!
  ltr.setMeasurementRate(LTR3XX_MEASRATE_50);
}

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(visible_plus_ir);
      Serial.print("\t\tCH1 Infrared: ");
      Serial.println(infrared);
    }
  }

  delay(1000);
}

 

Output

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

This was covering and uncovering the sensor

CH0 Visible + IR: 1 CH1 Infrared: 2
CH0 Visible + IR: 7 CH1 Infrared: 6
CH0 Visible + IR: 6 CH1 Infrared: 6
CH0 Visible + IR: 6 CH1 Infrared: 7
CH0 Visible + IR: 1 CH1 Infrared: 2

Links

https://optoelectronics.liteon.com/upload/download/DS86-2013-0004/LTR-303ALS-01_DS_V1.pdf

 

 

 

You may also like

Leave a Comment

%d bloggers like this:

Adblock Detected

Please support us by disabling your AdBlocker extension from your browsers for our website.