[22] Environment sensor
Description
Module with multiple integrated sensors for measuring environment conditions. It contains light, humidity and barometer sensors, allowing to monitor a variety of parameters.
Features:
Detection of:
- Luminosity
- Infrared
- Color (RGB)
- Air temperature (internal & external NTC)
- Air humidity
- Atmospheric pressure
- Altitude
Code examples
Arduino projects: 22_sensor
Module22 module;
Function usage (click to expand)
/* Light */
// Get HEX color code from light sensor "0xFF05A5E6"
int colorRGB = module.color.getHex();
// Get RGB color red channel "0x05" → "5"
int colorR = module.color.getR();
// Get RGB color green channel "0xA5" → "165"
int colorG = module.color.getG();
// Get RGB color blue channel "0xE6" → "230"
int colorB = module.color.getB();
// Get precise amount of red color "1561"
int colorPreciseR = module.colorR.get();
// Get precise amount of green color "156581"
int colorPreciseG = module.colorG.get();
// Get precise amount of green color "215017"
int colorPreciseB = module.colorB.get();
// Get amount of infrared light
int getIR = module.IR.get();
// Get luminosity
int getLumen = module.lumen.get();
// Set light sensor gain
module.setLightSensorGain(18);
/* Temperature */
// Get air temperature Celsius
float tempC = module.temp.getC();
// Get air temperature Fahrenheit
float tempF = module.temp.getF();
// Get air temperature Kelvin
float tempK = module.temp.getK();
/* NTC temperature */
// Get NTC sensor air temperature Celsius
float ntcTempC = module.ntc.getC();
// Get NTC sensor air temperature Fahrenheit
float ntcTempF = module.ntc.getF();
// Get NTC sensor air temperature Kelvin
float ntcTempK = module.ntc.getK();
// Get NTC sensor resistance
int ntcR = module.ntc.getResistance();
/* Humidity */
// Get air humidity
int humidity = module.humidity.get();
/* Pressure */
// Get air pressure Pascal
float pressurePa = module.pressure.getPa();
// Get air pressure Hectopascal
float pressurehPa = module.pressure.gethPa();
// Get air pressure Millibar
float pressureMbar = module.pressure.getMbar();
// Get air pressure Bar
float pressureBar = module.pressure.getBar();
// Get air pressure Pound per Square Inch
float pressurePsi = module.pressure.getPsi();
/* Altitude */
// Get altitude Meters
float altitudeM = module.altitude.getMeter();
// Get altitude Foot
float altitudeFt = module.altitude.getFoot();
// Get altitude Inches
float altitudeInch = module.altitude.getInch();
// Set sea level air pressure
module.setSeaLevel(101325);
/* LED control */
// Turn LED on
module.led.on();
// Turn LED off
module.led.off();
// Set LED to on
module.led.set(HIGH);
// Toggle LED state on / off
module.led.toggle();
// Check if LED is on
bool isOn = module.led.isOn();
Functions
Light
Light sensor is able to read amount of detected light and it's color saturation. If you trying to get precise measurements, turn of on-board red LED which may induce some red shade into sensor. Use function module.led.off()
for that.
(color
) module.color.getHex()
- Get 32-bit HEX RGB color code of light.
32-bit:0xFFAABBCC
→0xFF
(255 brightness),0xAA
(170 red),0xBB
(187 green),0xCC
(204 blue).
Returns:
color
- 32-bit color code [0xFF000000
:0xFFFFFFFF
]. First byte (brightness) is always 255
(color
) module.color.getR()
(color
) module.color.getG()
(color
) module.color.getB()
- Get amount of specified RGB color (red, green, blue). Parsed from
getHex()
function.
Returns:
color
- 8-bit amount of color [0
:255
]
(saturation
) module.colorR.get()
(saturation
) module.colorG.get()
(saturation
) module.colorB.get()
- Get precise amount of specified color. Higher value means more color in light is detected.
Returns:
saturation
- 18-bit amount of red color [0
:262143
]
(saturation
) module.IR.get()
- Get precise amount of infrared light hitting the sensor.
Returns:
saturation
- 18-bit amount of infrared light [0
:262143
]
(saturation
) module.lumen.get()
- Get precise amount of light (luminosity) hitting the sensor.
Returns:
saturation
- 18-bit amount of light [0
:262143
]
module.setLightSensorGain(gain
)
- Set light sensor gain.
Parameter:
gain
- gain value [1
,3
,6
,9
,18
]. Default:18
Temperature
(temperatureC
) module.temp.getC()
(temperatureF
) module.temp.getF()
(temperatureK
) module.temp.getK()
- Get air temperature. Multiple units available.
Returns:
temperatureC
- Celsius (float) (24.75
)C
temperatureF
- Fahrenheit (float) (76.55
)F
temperatureK
- Kelvin (float) (297.9
)K
NTC temperature
Module supports external Thermistor. It should be soldered or connected to NTC pins. Once connected, module will start measurements automatically.
(temperatureC
) module.ntc.getC()
(temperatureF
) module.ntc.getF()
(temperatureK
) module.ntc.getK()
- Get NTC sensor temperature. Multiple units available.
Returns:
temperatureC
- Celsius (float) (24.75
)C
temperatureF
- Fahrenheit (float) (76.55
)F
temperatureK
- Kelvin (float) (297.9
)K
(resistance
) module.ntc.getResistance()
- Get NTC sensor resistance in (Ohms). Module use it to compute air temperature.
Returns:
resistance
- thermistor resistance in Ohms.0
- not connected
Humidity
(humidity
) module.humidity.get()
- Get percentage of air humidity.
Returns:
humidity
- humidity [0
:100
]%
Pressure
(pressurePa
) module.pressure.getPa()
(pressurehPa
) module.pressure.gethPa()
(pressureMbar
) module.pressure.getMbar()
(pressureBar
) module.pressure.getBar()
(pressurePsi
) module.pressure.getPsi()
- Get atmospheric air pressure. Multiple units available.
Returns:
pressurePa
- Pascal (float) (90000
)Pa
pressurehPa
- Hectopascal (float) (900
)hPa
pressureMbar
- Millibar (float) (900
)mbar
pressureBar
- Bar (float) (0.9
)bar
pressurePsi
- Pound per Square Inch (float) (13.05
)psi
Altitude
Altitude calculation (altimeter) works by comparing current air pressure to a reference point (sea level). Sea level air pressure vary between locations and weather. For precise measurements - set it with function setSeaLevel()
. Default setting is 101325
Pascals (1013.25 mbar).
(altitudeM
) module.altitude.getMeter()
(altitudeFt
) module.altitude.getFoot()
(altitudeInch
) module.altitude.getInch()
- Get sensor altitude above sea level. Multiple units available.
Returns:
altitudeM
- Meters (float) (100
)m
altitudeFt
- Foot (float) (328.084
)ft
altitudeInch
- Inches (float) (3937.01
)inch
module.setSeaLevel(pressure
)
- Set air pressure at sea level for altitude calculation.
Parameter:
pressure
- pressure at sea level in Pascal units. Default:101325
Pa
LED control
module.led.on()
- Turn LED on.
module.led.off()
- Turn LED off.
module.led.set(state
)
- Set LED to specific state (on / off).
Parameter:
state
- state on / off [HIGH
:LOW
] or [true
:false
]
module.led.toggle()
- Toggle LED between on / off states.
(state
) module.led.isOn()
- Check if LED is on.
Returns:
state
- LED is on [true
:false
] or [HIGH
:LOW
].
Low level commands
These are low level TotemBUS commands accepted by module. Is not required when using objective API described above.
Command | Parameters | Description |
---|---|---|
color |
Returns:(int ) |
Get RGB HEX color |
color/R |
Returns:(int ) |
Get precise red color |
color/G |
Returns:(int ) |
Get precise blue color |
color/B |
Returns:(int ) |
Get precise green color |
light/IR |
Returns:(int ) |
Get infrared amount |
light/lumen |
Returns:(int ) |
Get lumen amount |
light/gain |
(byte ) |
Set sensor gain |
nfc |
Returns:(int ) |
Get external NTC temperature Celsius |
nfc/C |
Returns:(int ) |
Get external NTC temperature Celsius |
nfc/F |
Returns:(int ) |
Get external NTC temperature Fahrenheit |
nfc/K |
Returns:(int ) |
Get external NTC temperature Kelvin |
nfc/R |
Returns:(int ) |
Get external NTC resistance (Ohms) |
temperature |
Returns:(int ) |
Get temperature Celsius |
temperature/C |
Returns:(int ) |
Get temperature Celsius |
temperature/F |
Returns:(int ) |
Get temperature Fahrenheit |
temperature/K |
Returns:(int ) |
Get temperature Kelvin |
humidity |
Returns:(int ) |
Get humidity (%) |
pressure |
Returns:(int ) |
Get pressure Millibar |
pressure/mbar |
Returns:(int ) |
Get pressure Millibar |
pressure/Pa |
Returns:(int ) |
Get pressure Pascal |
pressure/hPa |
Returns:(int ) |
Get pressure Hectopascal |
pressure/psi |
Returns:(int ) |
Get pressure Pound per square inch |
altitude |
Returns:(int ) |
Get altitude meters |
altitude/m |
Returns:(int ) |
Get altitude meters |
altitude/ft |
Returns:(int ) |
Get altitude foot |
altitude/seaLevel |
(int ) |
Set sea level pressure (Pascal) |
led |
(bool ) |
Set LED on/off |