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
Sensor Constructors
Construct a new EverlightALSPT19 object with pins and resistors for the EnviroDIY Mayfly 1.x. 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. Construct a new EverlightALSPT19 object with custom supply voltage and loading resistor values. The pin on the mcu controlling power to the AOSong ALS-PT19. Use -1 if it is continuously powered. 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
EverlightALSPT19::
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.
EverlightALSPT19::
Parameters
powerPin
dataPin
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
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
Construct a new EverlightALSPT19_
EverlightALSPT19_
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
Construct a new EverlightALSPT19_
EverlightALSPT19_
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
Construct a new EverlightALSPT19_
EverlightALSPT19_
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
#include <src/sensors/EverlightALSPT19.h>
Sensor::
#define ALSPT19_INC_CALC_VARIABLES = 2
#include <src/sensors/EverlightALSPT19.h>
Sensor::
#define MAYFLY_ALS_POWER_PIN = -1
#include <src/sensors/EverlightALSPT19.h>
The power pin for the ALS on the EnviroDIY Mayfly v1.x.
#define MAYFLY_ALS_DATA_PIN = A4
#include <src/sensors/EverlightALSPT19.h>
The data pin for the ALS on the EnviroDIY Mayfly v1.x.
#define MAYFLY_ALS_SUPPLY_VOLTAGE = 3.3
#include <src/sensors/EverlightALSPT19.h>
The supply voltage for the ALS on the EnviroDIY Mayfly v1.x.
#define MAYFLY_ALS_LOADING_RESISTANCE = 10
#include <src/sensors/EverlightALSPT19.h>
The loading resistance for the ALS on the EnviroDIY Mayfly v1.x.
#define ALSPT19_ADC_RESOLUTION = 10
#include <src/sensors/EverlightALSPT19.h>
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 <<
#include <src/sensors/EverlightALSPT19.h>
The maximum possible value of the ADC - one less than the resolution shifted up one bit.
#define ALSPT19_ADC_RANGE = (1 <<
#include <src/sensors/EverlightALSPT19.h>
The maximum possible range of the ADC - the resolution shifted up one bit.
#define ALSPT19_ADC_REFERENCE_MODE = DEFAULT
#include <src/sensors/EverlightALSPT19.h>
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.3VAR_INTERNAL
: a built-in 2.23V referenceAR_INTERNAL1V0
: a built-in 1.0V referenceAR_INTERNAL1V65
: a built-in 1.65V referenceAR_INTERNAL2V23
: a built-in 2.23V referenceAR_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
#include <src/sensors/EverlightALSPT19.h>
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.3VAR_INTERNAL
: a built-in 2.23V referenceAR_INTERNAL1V0
: a built-in 1.0V referenceAR_INTERNAL1V65
: a built-in 1.65V referenceAR_INTERNAL2V23
: a built-in 2.23V referenceAR_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
#include <src/sensors/EverlightALSPT19.h>
Sensor::
#define ALSPT19_STABILIZATION_TIME_MS = 1
#include <src/sensors/EverlightALSPT19.h>
Sensor::
#define ALSPT19_MEASUREMENT_TIME_MS = 1
#include <src/sensors/EverlightALSPT19.h>
Sensor::
#define ALSPT19_VOLTAGE_RESOLUTION = 3
#include <src/sensors/EverlightALSPT19.h>
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
#include <src/sensors/EverlightALSPT19.h>
Sensor variable number; current is stored in sensorValues[0].
#define ALSPT19_VOLTAGE_VAR_NAME = "voltage"
#include <src/sensors/EverlightALSPT19.h>
Variable name in ODM2 controlled vocabulary; "electricCurrent".
#define ALSPT19_VOLTAGE_UNIT_NAME = "volt"
#include <src/sensors/EverlightALSPT19.h>
Variable unit name in ODM2 controlled vocabulary; "microampere".
#define ALSPT19_VOLTAGE_DEFAULT_CODE = "ALSPT19Voltage"
#include <src/sensors/EverlightALSPT19.h>
Default variable short code; "ALSPT19Voltage".
#define ALSPT19_CURRENT_RESOLUTION = 0
#include <src/sensors/EverlightALSPT19.h>
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
#include <src/sensors/EverlightALSPT19.h>
Sensor variable number; current is stored in sensorValues[0].
#define ALSPT19_CURRENT_VAR_NAME = "electricCurrent"
#include <src/sensors/EverlightALSPT19.h>
Variable name in ODM2 controlled vocabulary; "electricCurrent".
#define ALSPT19_CURRENT_UNIT_NAME = "microampere"
#include <src/sensors/EverlightALSPT19.h>
Variable unit name in ODM2 controlled vocabulary; "microampere".
#define ALSPT19_CURRENT_DEFAULT_CODE = "ALSPT19Current"
#include <src/sensors/EverlightALSPT19.h>
Default variable short code; "ALSPT19Current".
#define ALSPT19_ILLUMINANCE_RESOLUTION = 1
#include <src/sensors/EverlightALSPT19.h>
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
#include <src/sensors/EverlightALSPT19.h>
Sensor variable number; illuminance is stored in sensorValues[1].
#define ALSPT19_ILLUMINANCE_VAR_NAME = "illuminance"
#include <src/sensors/EverlightALSPT19.h>
Variable name in ODM2 controlled vocabulary; "illuminance".
#define ALSPT19_ILLUMINANCE_UNIT_NAME = "lux"
#include <src/sensors/EverlightALSPT19.h>
Variable unit name in ODM2 controlled vocabulary; "lux".
#define ALSPT19_ILLUMINANCE_DEFAULT_CODE = "ALSPT19Lux"
#include <src/sensors/EverlightALSPT19.h>
Default variable short code; "ALSPT19Lux".