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.


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
5#if defined(ENVIRODIY_STONEFLY_M4)
6const int8_t alsData = A8; // The ALS PT-19 data pin
7#else
8const int8_t alsData = A4; // The ALS PT-19 data pin
9#endif
10const int8_t alsSupply = 3.3; // The ALS PT-19 supply power voltage
11const int8_t alsResistance = 10; // The ALS PT-19 loading resistance (in kΩ)
12const uint8_t alsNumberReadings = 10;
13
14// Create a Everlight ALS-PT19 sensor object
15EverlightALSPT19 alsPt19(alsPower, alsData, alsSupply, alsResistance,
16 alsNumberReadings);
17
18// For an EnviroDIY Mayfly, you can use the abbreviated version
19// EverlightALSPT19 alsPt19(alsNumberReadings);
20
21// Create voltage, current, and illuminance variable pointers for the ALS-PT19
22Variable* alsPt19Volt = new EverlightALSPT19_Voltage(
23 &alsPt19, "12345678-abcd-1234-ef00-1234567890ab");
24Variable* alsPt19Current = new EverlightALSPT19_Current(
25 &alsPt19, "12345678-abcd-1234-ef00-1234567890ab");
26Variable* alsPt19Lux = new EverlightALSPT19_Illuminance(
27 &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.

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_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".