Home SensorsLight Connect a LTR-329 Ambient Light sensor to an Arduino

Connect a LTR-329 Ambient Light sensor to an Arduino

by shedboy71

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

Parts Required

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

This should work with other Arduino boards – I have tried a Mega as well for example

Name   Link
Arduino Uno
LTR-329
  • Aliexpress link
  • Amazon
  • Ebay
Connecting cables

 

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

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

Links

https://optoelectronics.liteon.com/en-global/Led/led-component/Detail/926

https://optoelectronics.liteon.com/upload/download/DS86-2014-0006/LTR-329ALS-01_DS_V1.6.PDF

You may also like

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More