Home Learning LTR-303 Ambient Light sensor and Arduino example

LTR-303 Ambient Light sensor and Arduino example

by shedboy71

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

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.

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
Arduino Uno UNO R3 CH340G with usb cable
LTR303 https://www.adafruit.com/product/5610
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, 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() {
  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

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
CH0 Visible + IR: 8 CH1 Infrared: 4
CH0 Visible + IR: 8 CH1 Infrared: 4
CH0 Visible + IR: 1 CH1 Infrared: 0

Links

 

 

 

 

Share

You may also like

Leave a Comment