Everlight ALS-PT19 topic

Classes for the Everlight ALS-PT19 ambient light sensor.

Quick Notes

  • A simple analog current sensor
  • Requires a 2.5 - 5.5V power source

Sensor Datasheet

Datasheet

Sensor Constructors

EverlightALSPT19::EverlightALSPT19(uint8_t measurementsToAverage = 10) explicit

Construct a new EverlightALSPT19 object with pins and resistors for the EnviroDIY Mayfly 1.x.

Parameters
measurementsToAverage The number of measurements to take and average before giving a "final" result from the sensor; optional with a default value of 10.

This is a short-cut constructor to help users of our own board so they can change the number of readings without changing other arguments or enter no arguments at all.


EverlightALSPT19::EverlightALSPT19(int8_t powerPin, int8_t dataPin, float supplyVoltage, float loadResistor, uint8_t measurementsToAverage = 10)

Construct a new EverlightALSPT19 object with custom supply voltage and loading resistor values.

Parameters
powerPin

The pin on the mcu controlling power to the AOSong ALS-PT19. Use -1 if it is continuously powered.

  • The ALS-PT19 requires a 2.5 - 5.5V power source
dataPin

The processor ADC port pin to read the voltage from the EC probe. Not all processor pins can be used as analog pins. Those usable as analog pins generally are numbered with an "A" in front of the number

  • ie, A1.
supplyVoltage The power supply voltage (in volts) of the ALS-PT19.
loadResistor The size of the loading resistor, in kilaohms (kΩ).
measurementsToAverage The number of measurements to take and average before giving a "final" result from the sensor; optional with a default value of 10.

Example Code

The ALS-PT19 is used in the menu a la carte example

1#include <sensors/EverlightALSPT19.h>
2
3// NOTE: Use -1 for any pins that don't apply or aren't being used.
4const int8_t alsPower = sensorPowerPin; // Power pin
5const int8_t alsData = A4; // The ALS PT-19 data pin
6const int8_t alsSupply = 3.3; // The ALS PT-19 supply power voltage
7const int8_t alsResistance = 10; // The ALS PT-19 loading resistance (in kΩ)
8const uint8_t alsNumberReadings = 10;
9
10// Create a Everlight ALS-PT19 sensor object
11EverlightALSPT19 alsPt19(alsPower, alsData, alsSupply, alsResistance,
12 alsNumberReadings);
13
14// For an EnviroDIY Mayfly, you can use the abbreviated version
15// EverlightALSPT19 alsPt19(alsNumberReadings);
16
17// Create voltage, current, and illuminance variable pointers for the ALS-PT19
18Variable* alsPt19Volt = new EverlightALSPT19_Voltage(
19 &alsPt19, "12345678-abcd-1234-ef00-1234567890ab");
20Variable* alsPt19Current = new EverlightALSPT19_Current(
21 &alsPt19, "12345678-abcd-1234-ef00-1234567890ab");
22Variable* alsPt19Lux = new EverlightALSPT19_Illuminance(
23 &alsPt19, "12345678-abcd-1234-ef00-1234567890ab");

Classes

class EverlightALSPT19
The Sensor sub-class for the Everlight ALS-PT19.
class EverlightALSPT19_Voltage
The Variable sub-class used for the relative current output from an Everlight ALS-PT19.
class EverlightALSPT19_Current
The Variable sub-class used for the relative current output from an Everlight ALS-PT19.
class EverlightALSPT19_Illuminance
The Variable sub-class used for the calculated illuminance output from an Everlight ALS-PT19.

Sensor Variable Counts

The number of variables that can be returned by an ALS-PT19

#define ALSPT19_NUM_VARIABLES = 3
Sensor::_numReturnedValues; the ALS-PT19 can report 1 "raw" value (voltage) and we calculate current and illuminance from it.
#define ALSPT19_INC_CALC_VARIABLES = 2
Sensor::_incCalcValues; we calculate photocurrent from the supply voltage and loading resistance and illuminance from the photocurrent.

Pin Definitions for the Mayfly

Specific pin definitions for the ALS-PT19 built in to the EnviroDIY Mayfly v1.x

#define MAYFLY_ALS_POWER_PIN = -1
The power pin for the ALS on the EnviroDIY Mayfly v1.x.
#define MAYFLY_ALS_DATA_PIN = A4
The data pin for the ALS on the EnviroDIY Mayfly v1.x.
#define MAYFLY_ALS_SUPPLY_VOLTAGE = 3.3
The supply voltage for the ALS on the EnviroDIY Mayfly v1.x.
#define MAYFLY_ALS_LOADING_RESISTANCE = 10
The loading resistance for the ALS on the EnviroDIY Mayfly v1.x.

Configuration Defines

Defines to help configure the range and resolution of the ALS-PT119 depending on the processor and ADC in use.

#define ALSPT19_ADC_RESOLUTION = 10
Default resolution (in bits) of the voltage measurement.
#define ALSPT19_ADC_MAX = ((1 <<
The maximum possible value of the ADC - one less than the resolution shifted up one bit.
#define ALSPT19_ADC_RANGE = (1 <<
The maximum possible range of the ADC - the resolution shifted up one bit.
#define ALSPT19_ADC_REFERENCE_MODE = DEFAULT
The voltage reference mode for the processor's ADC.
#define ALSPT19_ADC_REFERENCE_MODE = AR_DEFAULT
The voltage reference mode for the processor's ADC.

Sensor Timing

The sensor timing for an Everlight ALS-PT19

#define ALSPT19_WARM_UP_TIME_MS = 2
Sensor::_warmUpTime_ms; the ALS-PT19 should not need to warm up.
#define ALSPT19_STABILIZATION_TIME_MS = 1
Sensor::_stabilizationTime_ms; the ALS-PT19 rise time is 0.11 ms (typical).
#define ALSPT19_MEASUREMENT_TIME_MS = 1
Sensor::_measurementTime_ms; essentially 0 time is taken in a reading, just the analog read time, but we want to give more than the rise (0.11 ms) or fall (0.22 ms) time between readings.

Voltage

The voltage variable from an Everlight ALS-PT19

  • Range is dependent on supply voltage and loading resistor
    • 0 to 4.6 V with a 5V power supply and 75K resistor

EverlightALSPT19_Voltage::EverlightALSPT19_Voltage(EverlightALSPT19* parentSense, const char* uuid = "", const char* varCode = "ALSPT19Voltage") explicit

Construct a new EverlightALSPT19_Voltage object.

Parameters
parentSense The parent EverlightALSPT19 providing the result values.
uuid A universally unique identifier (UUID or GUID) for the variable; optional with the default value of an empty string.
varCode A short code to help identify the variable in files; optional with a default value of "ALSPT19Current".

#define ALSPT19_VOLTAGE_RESOLUTION = 3
Decimals places in string representation; voltage should have 0.
#define ALSPT19_VOLTAGE_VAR_NUM = 0
Sensor variable number; current is stored in sensorValues[0].
#define ALSPT19_VOLTAGE_VAR_NAME = "voltage"
Variable name in ODM2 controlled vocabulary; "electricCurrent".
#define ALSPT19_VOLTAGE_UNIT_NAME = "volt"
Variable unit name in ODM2 controlled vocabulary; "microampere".
#define ALSPT19_VOLTAGE_DEFAULT_CODE = "ALSPT19Voltage"
Default variable short code; "ALSPT19Voltage".

Current

The current variable from an Everlight ALS-PT19

  • Range is 5 to 520 µA

EverlightALSPT19_Current::EverlightALSPT19_Current(EverlightALSPT19* parentSense, const char* uuid = "", const char* varCode = "ALSPT19Current") explicit

Construct a new EverlightALSPT19_Current object.

Parameters
parentSense The parent EverlightALSPT19 providing the result values.
uuid A universally unique identifier (UUID or GUID) for the variable; optional with the default value of an empty string.
varCode A short code to help identify the variable in files; optional with a default value of "ALSPT19Current".

#define ALSPT19_CURRENT_RESOLUTION = 0
Decimals places in string representation; voltage should have 0.
#define ALSPT19_CURRENT_VAR_NUM = 1
Sensor variable number; current is stored in sensorValues[0].
#define ALSPT19_CURRENT_VAR_NAME = "electricCurrent"
Variable name in ODM2 controlled vocabulary; "electricCurrent".
#define ALSPT19_CURRENT_UNIT_NAME = "microampere"
Variable unit name in ODM2 controlled vocabulary; "microampere".
#define ALSPT19_CURRENT_DEFAULT_CODE = "ALSPT19Current"
Default variable short code; "ALSPT19Current".

Illuminance

The illuminance variable from an Everlight ALS-PT19

  • Range is 0 to 10000 lux

EverlightALSPT19_Illuminance::EverlightALSPT19_Illuminance(EverlightALSPT19* parentSense, const char* uuid = "", const char* varCode = "ALSPT19Lux") explicit

Construct a new EverlightALSPT19_Illuminance object.

Parameters
parentSense The parent EverlightALSPT19 providing the result values.
uuid A universally unique identifier (UUID or GUID) for the variable; optional with the default value of an empty string.
varCode A short code to help identify the variable in files; optional with a default value of "ALSPT19Lux".

#define ALSPT19_ILLUMINANCE_RESOLUTION = 1
Decimals places in string representation; illuminance should have 0.
#define ALSPT19_ILLUMINANCE_VAR_NUM = 2
Sensor variable number; illuminance is stored in sensorValues[1].
#define ALSPT19_ILLUMINANCE_VAR_NAME = "illuminance"
Variable name in ODM2 controlled vocabulary; "illuminance".
#define ALSPT19_ILLUMINANCE_UNIT_NAME = "lux"
Variable unit name in ODM2 controlled vocabulary; "lux".
#define ALSPT19_ILLUMINANCE_DEFAULT_CODE = "ALSPT19Lux"
Default variable short code; "ALSPT19Lux".

Define documentation

#define ALSPT19_NUM_VARIABLES = 3

Sensor::_numReturnedValues; the ALS-PT19 can report 1 "raw" value (voltage) and we calculate current and illuminance from it.


#define ALSPT19_INC_CALC_VARIABLES = 2

Sensor::_incCalcValues; we calculate photocurrent from the supply voltage and loading resistance and illuminance from the photocurrent.


#define MAYFLY_ALS_POWER_PIN = -1

The power pin for the ALS on the EnviroDIY Mayfly v1.x.


#define MAYFLY_ALS_DATA_PIN = A4

The data pin for the ALS on the EnviroDIY Mayfly v1.x.


#define MAYFLY_ALS_SUPPLY_VOLTAGE = 3.3

The supply voltage for the ALS on the EnviroDIY Mayfly v1.x.


#define MAYFLY_ALS_LOADING_RESISTANCE = 10

The loading resistance for the ALS on the EnviroDIY Mayfly v1.x.


#define ALSPT19_ADC_RESOLUTION = 10

Default resolution (in bits) of the voltage measurement.

The default for all boards is 10, use a build flag to change this, if necessary.


#define ALSPT19_ADC_MAX = ((1 <<

The maximum possible value of the ADC - one less than the resolution shifted up one bit.


#define ALSPT19_ADC_RANGE = (1 <<

The maximum possible range of the ADC - the resolution shifted up one bit.


#define ALSPT19_ADC_REFERENCE_MODE = DEFAULT

The voltage reference mode for the processor's ADC.

For an AVR board, this must be one of:

  • DEFAULT: the default built-in analog reference of 5 volts (on 5V Arduino boards) or 3.3 volts (on 3.3V Arduino boards)
  • INTERNAL: a built-in reference, equal to 1.1 volts on the ATmega168 or ATmega328P and 2.56 volts on the ATmega32U4 and ATmega8 (not available on the Arduino Mega)
  • INTERNAL1V1: a built-in 1.1V reference (Arduino Mega only)
  • INTERNAL2V56: a built-in 2.56V reference (Arduino Mega only)
  • EXTERNAL: the voltage applied to the AREF pin (0 to 5V only) is used as the reference.

If not set on an AVR board DEFAULT is used.

For the best accuracy, use an EXTERNAL reference with the AREF pin connected to the power supply for the EC sensor.

For a SAMD board, this must be one of:

  • AR_DEFAULT: the default built-in analog reference of 3.3V
  • AR_INTERNAL: a built-in 2.23V reference
  • AR_INTERNAL1V0: a built-in 1.0V reference
  • AR_INTERNAL1V65: a built-in 1.65V reference
  • AR_INTERNAL2V23: a built-in 2.23V reference
  • AR_EXTERNAL: the voltage applied to the AREF pin is used as the reference

If not set on an SAMD board AR_DEFAULT is used.

For the best accuracy, use an EXTERNAL reference with the AREF pin connected to the power supply for the EC sensor.


#define ALSPT19_ADC_REFERENCE_MODE = AR_DEFAULT

The voltage reference mode for the processor's ADC.

For an AVR board, this must be one of:

  • DEFAULT: the default built-in analog reference of 5 volts (on 5V Arduino boards) or 3.3 volts (on 3.3V Arduino boards)
  • INTERNAL: a built-in reference, equal to 1.1 volts on the ATmega168 or ATmega328P and 2.56 volts on the ATmega32U4 and ATmega8 (not available on the Arduino Mega)
  • INTERNAL1V1: a built-in 1.1V reference (Arduino Mega only)
  • INTERNAL2V56: a built-in 2.56V reference (Arduino Mega only)
  • EXTERNAL: the voltage applied to the AREF pin (0 to 5V only) is used as the reference.

If not set on an AVR board DEFAULT is used.

For the best accuracy, use an EXTERNAL reference with the AREF pin connected to the power supply for the EC sensor.

For a SAMD board, this must be one of:

  • AR_DEFAULT: the default built-in analog reference of 3.3V
  • AR_INTERNAL: a built-in 2.23V reference
  • AR_INTERNAL1V0: a built-in 1.0V reference
  • AR_INTERNAL1V65: a built-in 1.65V reference
  • AR_INTERNAL2V23: a built-in 2.23V reference
  • AR_EXTERNAL: the voltage applied to the AREF pin is used as the reference

If not set on an SAMD board AR_DEFAULT is used.

For the best accuracy, use an EXTERNAL reference with the AREF pin connected to the power supply for the EC sensor.


#define ALSPT19_WARM_UP_TIME_MS = 2

Sensor::_warmUpTime_ms; the ALS-PT19 should not need to warm up.


#define ALSPT19_STABILIZATION_TIME_MS = 1

Sensor::_stabilizationTime_ms; the ALS-PT19 rise time is 0.11 ms (typical).


#define ALSPT19_MEASUREMENT_TIME_MS = 1

Sensor::_measurementTime_ms; essentially 0 time is taken in a reading, just the analog read time, but we want to give more than the rise (0.11 ms) or fall (0.22 ms) time between readings.


#define ALSPT19_VOLTAGE_RESOLUTION = 3

Decimals places in string representation; voltage should have 0.

The true resolution depends on the ADC, the supply voltage, and the loading resistor, but for simplicity we will use 3, which is an appropriate value for the Mayfly.


#define ALSPT19_VOLTAGE_VAR_NUM = 0

Sensor variable number; current is stored in sensorValues[0].


#define ALSPT19_VOLTAGE_VAR_NAME = "voltage"

Variable name in ODM2 controlled vocabulary; "electricCurrent".


#define ALSPT19_VOLTAGE_DEFAULT_CODE = "ALSPT19Voltage"

Default variable short code; "ALSPT19Voltage".


#define ALSPT19_CURRENT_RESOLUTION = 0

Decimals places in string representation; voltage should have 0.

The true resolution depends on the ADC, the supply voltage, and the loading resistor, but for simplicity we will use 0 as this is not a high precision sensor.


#define ALSPT19_CURRENT_VAR_NUM = 1

Sensor variable number; current is stored in sensorValues[0].


#define ALSPT19_CURRENT_VAR_NAME = "electricCurrent"

Variable name in ODM2 controlled vocabulary; "electricCurrent".


#define ALSPT19_CURRENT_UNIT_NAME = "microampere"

Variable unit name in ODM2 controlled vocabulary; "microampere".


#define ALSPT19_CURRENT_DEFAULT_CODE = "ALSPT19Current"

Default variable short code; "ALSPT19Current".


#define ALSPT19_ILLUMINANCE_RESOLUTION = 1

Decimals places in string representation; illuminance should have 0.

The true resolution depends on the ADC, the supply voltage, the loading resistor, and the light source, but for simplicity we will use 0 as this is not a high precision sensor.


#define ALSPT19_ILLUMINANCE_VAR_NUM = 2

Sensor variable number; illuminance is stored in sensorValues[1].


#define ALSPT19_ILLUMINANCE_DEFAULT_CODE = "ALSPT19Lux"

Default variable short code; "ALSPT19Lux".