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

Connect a LTR-303 Ambient Light sensor to an Arduino

by shedboy71

In this article we look at an Ambient Light sensor, the LTR-303 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
LTR303
  • 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 installs the dependency library if it is required

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 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() {
  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

Adafruit LTR-303 simple test
Found LTR sensor!
CH0 Visible + IR: 1 CH1 Infrared: 0
CH0 Visible + IR: 0 CH1 Infrared: 1
CH0 Visible + IR: 7 CH1 Infrared: 5

Links

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

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

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