Skip to main content

Ltr 507 - Initialization and Settings

This page contains an example of how to modify parameters of the LTR-507 light sensor.


Initialization

To use the LTR-507 sensor, include the required library, create the light_sensor object, and initialize the light_sensor in the setup() function using light_sensor.init(). You can adjust the sensor’s settings, such as ALS (ambient light sensor) gain, measurement rates, and IR LED configuration.

// Include needed libraries
#include "LTR-507-Light-And-Proximity-Sensor-SOLDERED.h"

// Create light_sensor object
LTR507 light_sensor;

void setup()
{
// Begin Serial for debugging purposes
Serial.begin(115200);

// Initialize the light_sensor!
// This function initializes the light_sensor with the default settings
light_sensor.init();
}
// ...

light_sensor.init()

Initializes the LTR507 light_sensor by setting up I2C communication and configuring default settings for ALS (ambient light sensor) and PS (proximity sensor) modes. This includes configuring gain, measurement rates, LED settings, and proximity sensor pulses.

Returns value: None


Other Settings

Turning the sensor on and off

    light_sensor.setALSMode(false);
light_sensor.setPSMode(false);

light_sensor.setALSMode()

Enables or disables the ambient light sensing (ALS) mode. The 'mode' parameter determines whether ALS is turned on or off.

Returns value: None

Function parameters:

TypeNameDescription
boolmodeSet to 'true' to enable ALS mode or 'false' to disable it.

light_sensor.setPSMode()

Enables or disables the proximity sensing (PS) mode. The 'mode' parameter determines whether proximity sensing is turned on or off.

Returns value: None

Function parameters:

TypeNameDescription
boolmodeSet to 'true' to enable proximity sensing mode or 'false' to disable it.

Setting the gain of the sensor

  light_sensor.setALSGain(LTR507_ALS_GAIN_RANGE1);

light_sensor.setALSGain()

Sets the gain for the ALS (Ambient Light sensor) to adjust its sensitivity. The 'gain' parameter controls the amplification of the sensor's signal. (See table below).

Returns value: None

Function parameters:

TypeNameDescription
uint8_tgainThe gain level to set for the ALS sensor. Higher values increase sensitivity, while lower values decrease it.
Gain RangeLux RangeLux per Count
LTR507_ALS_GAIN_RANGE11 lux to 64k lux1 lux/count
LTR507_ALS_GAIN_RANGE20.5 lux to 32k lux0.5 lux/count
LTR507_ALS_GAIN_RANGE30.02 lux to 640 lux0.01 lux/count
LTR507_ALS_GAIN_RANGE40.01 lux to 320 lux0.005 lux/count

Setting the measurement rate for ambient lighting

  light_sensor.setALSMeasRate(LTR507_ALS_MEASUREMENT_RATE_100MS);

light_sensor.setALSMeasRate()

Sets the measurement rate for the Ambient Light sensor (ALS). The 'rate' parameter defines how frequently the sensor takes measurements. (See table below).

Returns value: None

Function parameters:

TypeNameDescription
uint8_trateThe measurement rate to set for the ALS sensor, typically represented in Hz or cycles per second.
Measurement RateDescription
LTR507_ALS_MEASUREMENT_RATE_100MSDefault measurement rate
LTR507_ALS_MEASUREMENT_RATE_200MS200 milliseconds per measurement
LTR507_ALS_MEASUREMENT_RATE_500MS500 milliseconds per measurement
LTR507_ALS_MEASUREMENT_RATE_1000MS1000 milliseconds per measurement
LTR507_ALS_MEASUREMENT_RATE_2000MS2000 milliseconds per measurement

Setting the measurement rate for proximity

  light_sensor.setPSMeasRate(LTR507_PS_MEASUREMENT_RATE_100MS);

light_sensor.setPSMeasRate()

Sets the measurement rate for the proximity sensor. The 'rate' parameter defines how often the sensor performs measurements. (See table below).

Returns value: None

Function parameters:

TypeNameDescription
uint8_trateThe measurement rate to set for the proximity sensor, typically represented in Hz or cycles per second.
Measurement RateDescription
LTR507_PS_MEASUREMENT_RATE_12_5MS12.5 milliseconds per measurement
LTR507_PS_MEASUREMENT_RATE_50MS50 milliseconds per measurement
LTR507_PS_MEASUREMENT_RATE_70MS70 milliseconds per measurement
LTR507_PS_MEASUREMENT_RATE_100MSDefault measurement rate
LTR507_PS_MEASUREMENT_RATE_200MS200 milliseconds per measurement
LTR507_PS_MEASUREMENT_RATE_500MS500 milliseconds per measurement
LTR507_PS_MEASUREMENT_RATE_1000MS1000 milliseconds per measurement
LTR507_PS_MEASUREMENT_RATE_2000MS2000 milliseconds per measurement

Setting the maximum current supplied to the IR LED

  light_sensor.setLEDPeakCurrent(LTR507_LED_PEAK_CURRENT_50MA);

light_sensor.setLEDPeakCurrent()

Sets the peak current for the IR LED used in proximity sensing. The 'current' parameter controls the maximum current supplied to the LED. (See table below).

Returns value: None

Function parameters:

TypeNameDescription
uint8_tcurrentThe peak current to set for the IR LED, which affects the intensity of the emitted light.
LED Peak CurrentDescription
LTR507_LED_PEAK_CURRENT_5MA5 milliamps peak current
LTR507_LED_PEAK_CURRENT_10MA10 milliamps peak current
LTR507_LED_PEAK_CURRENT_20MA20 milliamps peak current
LTR507_LED_PEAK_CURRENT_50MADefault peak current (50 milliamps)

Setting the pulse frequency of the IR LED

  light_sensor.setLEDPulseFreq(LTR507_LED_PULSE_FREQ_60KHZ);

// Set the number of pulses for a proximity measurement
// You can use any number from 1 to 15, default is 1
light_sensor.setPSNumPulses(1);
}
// ...

light_sensor.setLEDPulseFreq()

Sets the pulse frequency for the IR LED used in proximity sensing. The 'freq' parameter controls how often the LED pulses. (See table below).

Returns value: None

Function parameters:

TypeNameDescription
uint8_tfreqThe pulse frequency to set for the IR LED, typically represented in Hz or pulses per second.
LED Pulse FrequencyDescription
LTR507_LED_PULSE_FREQ_30KHZ30 kilohertz pulse frequency
LTR507_LED_PULSE_FREQ_40KHZ40 kilohertz pulse frequency
LTR507_LED_PULSE_FREQ_50KHZ50 kilohertz pulse frequency
LTR507_LED_PULSE_FREQ_60KHZDefault pulse frequency (60 kHz)
LTR507_LED_PULSE_FREQ_70KHZ70 kilohertz pulse frequency
LTR507_LED_PULSE_FREQ_80KHZ80 kilohertz pulse frequency
LTR507_LED_PULSE_FREQ_90KHZ90 kilohertz pulse frequency
LTR507_LED_PULSE_FREQ_100KHZ100 kilohertz pulse frequency

Full Setup (default settings)

This section outlines the default settings used when initializing the sensor. It can be helpful to refer to these if you wish to modify any of the settings during your project.

// Include needed libraries
#include "LTR-507-Light-And-Proximity-Sensor-SOLDERED.h"

// Create light_sensor object
LTR507 light_sensor;

void setup()
{
// Begin Serial for debugging purposes
Serial.begin(115200);

// Initialize the light_sensor!
light_sensor.init();

// Set the gain of the light_sensor
light_sensor.setALSGain(LTR507_ALS_GAIN_RANGE1);

// Set the automatic measurement rate
light_sensor.setALSMeasRate(LTR507_ALS_MEASUREMENT_RATE_100MS);

// Set the auto measurement rate for proximity
light_sensor.setPSMeasRate(LTR507_PS_MEASUREMENT_RATE_100MS);

// Set the max current supplied to the IR LED
light_sensor.setLEDPeakCurrent(LTR507_LED_PEAK_CURRENT_50MA);

// Set the pulse frequency of the IR LED
light_sensor.setLEDPulseFreq(LTR507_LED_PULSE_FREQ_60KHZ);

// Set the number of pulses for a proximity measurement (1-15)
light_sensor.setPSNumPulses(1);
}

adjustSettings.ino

Example file for adjusting the settings with the LTR-507 sensor