Home Learning LTR-329 Ambient Light sensor and Arduino example

LTR-329 Ambient Light sensor and Arduino example

by shedboy71

In this article we look at an Ambient Light sensor, the LTR-329 and connect it to an Arduino Uno

Sensor Information

The LTR-329 provides 16-bit light measurements for both Infrared and Visible+IR spectrums. Subtract one from the other to get human-visible light. Thanks to configurable gain and integration time settings, the LTR-329 can measure from 0 to 65K+ lux.

I bought an Adafruit breakout board, so the LTR-329 comes integrated with a voltage regulator and level-shifting circuitry to allow it to be used with 3.3V devices or 5V devices.

Along with a header, there is a SparkFun Qwiic compatible STEMMA QT connectors for the I2C bus so you just need to fit a suitable cable

Features

I2C interface with up to Fast Mode @ 400kbit/s with address 0x29
Ultra-small 4-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 UNO R3 CH340G with usb cable
LTR329 https://www.adafruit.com/product/5591
Connecting cables Male to Male + Male to Female and Female to Female Jumper Wire Dupont Cable

 

Schematic/Connection

I used 3.3v from the Arduino Uno – 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, you already have the required dependencies 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 ltr329_simpletest example with the delay set to 1000ms rather than 100ms which seemed a bit too short a delay for simple testing. I also removed code from the setup routine which basically displayed the settings that you can change in the setup.

These are

ltr.setGain(LTR3XX_GAIN_2);
ltr.setIntegrationTime(LTR3XX_INTEGTIME_100);
ltr.setMeasurementRate(LTR3XX_MEASRATE_200);

#include "Adafruit_LTR329_LTR303.h"

Adafruit_LTR329 ltr = Adafruit_LTR329();

void setup() {
  Serial.begin(115200);
  Serial.println("Adafruit LTR-329 advanced test");

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

  ltr.setGain(LTR3XX_GAIN_2);
  ltr.setIntegrationTime(LTR3XX_INTEGTIME_100);
  ltr.setMeasurementRate(LTR3XX_MEASRATE_200);

}

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

Adafruit LTR-329 advanced test
Found LTR sensor!
Gain : 2
Integration Time (ms): 100
Measurement Rate (ms): 200
CH0 Visible + IR: 69 CH1 Infrared: 49
CH0 Visible + IR: 69 CH1 Infrared: 49
CH0 Visible + IR: 69 CH1 Infrared: 49
CH0 Visible + IR: 37 CH1 Infrared: 21
CH0 Visible + IR: 1 CH1 Infrared: 1
CH0 Visible + IR: 0 CH1 Infrared: 2
CH0 Visible + IR: 1 CH1 Infrared: 2
CH0 Visible + IR: 44 CH1 Infrared: 22
CH0 Visible + IR: 42 CH1 Infrared: 22

Links

 

 

 

 

Share

You may also like

Leave a Comment