Skip to content

[22] Environment sensor

Features:

Detection of:

  • Luminosity
  • Infrared
  • Color (RGB)
  • Air temperature (internal & external NTC)
  • Air humidity
  • Atmospheric pressure
  • Altitude

Arduino example: 22_sensor.ino

TotemModule module(22);

Totem Module 22

Module commands

Before start

• Install programming environment by following tutorial on Arduino setup.
• Join our community forum for any questions: https://forum.totemmaker.net.

Command naming convention

Some commands controls various channels (A, B, C, ...). There is a logic behind command naming for flexibility:
write("commandA", 10) - will set value 10 for individual channel A.
write("commandAll", 100) - will set value 100 for all existing channels.
write("commandABCD", 10, 20, 30, 40) - will set individual values for A, B, C, D channels.
write("commandABC", 10, 20, 30) - will set individual values for A, B, C channels.
Only commands listed in "Module commands" will be accepted. Other variations will be discarded.
All commands are case sensitive! Calls like CommandA, COMMANDa, motorA/BRAKE will be ignored.

Light

color ( )

Red Green Blue color of light.
Returns HEX color code. First byte (brightness) is always 255.
Tip: On board red LED can interfere with color sensor. Turn it off with command module.write("led", false) for more precise reading.
Encoding: [A:[255]; R:[0:255]; G:[0:255]; B:[0:255]].
Returns: 32-bit color code [0xFF000000:0xFFFFFFFF].
int color = module.readWait("color").getInt();
int red = (color >> 16) & 0xFF;
int green = (color >> 8) & 0xFF;
int blue = (color >> 0) & 0xFF;
Totem.X4.write("rgbAll", color); // Set X4 LED with color from sensor

color/R ( )

color/G ( )

color/B ( )

Precise color channel value. Higher value means more certain color of light is detected.
Returns: 18-bit amount of color [0:262143].
int redColor = module.readWait("color/R").getInt();
int greenColor = module.readWait("color/G").getInt();
int blueColor = module.readWait("color/B").getInt();

light/IR ( )

Precise amount of infrared light.
Returns: 18-bit amount of infrared light [0:262143].
int infrared = module.readWait("light/IR").getInt();

light/lumen ( )

Precise amount of light. Higher value means more brighter environment.
Returns: 18-bit luminosity [0:262143].
int lumen = module.readWait("light/lumen").getInt();

light/gain ( gain )

Light sensor gain.
Parameter:
gain - gain value [1;3;6;9;18].
Default: 18.
module.write("light/gain", 9); // Set sensor gain to 9

Temperature

temperature ( )

temperature/C ( )

temperature/F ( )

temperature/K ( )

Current temperature in Celsius. Value 2715 -> 27.15C.
Other units: C - Celsius, F - Fahrenheit, K - Kelvin.
Returns: temperature reading in units.
float celsius = module.readWait("temperature").getInt();
Serial.println(celsius/100); // Print in 27.15 notation.
float fahrenheit = module.readWait("temperature/F").getInt();
Serial.println(fahrenheit/100); // Prints in 80.87 notation.
float kelvin = module.readWait("temperature/K").getInt();
Serial.println(kelvin/100); // Prints in 300.3 notation.

Thermistor

Module supports external Thermistor. It should be soldered or connected to NTC pins. Once connected, module will start measurements automatically.

ntc ( )

ntc/C ( )

ntc/F ( )

ntc/K ( )

Current temperature of external NTC sensor (must be connected separately).
Value 2715 -> 27.15C.
If external NTC is not connected, value 0 is returned.
Other units: C - Celsius, F - Fahrenheit, K - Kelvin.
Returns: temperature reading in units.
float temp = module.readWait("ntc").getInt();
Serial.println(temp/100); // Print in 27.15 notation.

ntc/R ( )

Current resistance (Ohms) of external NTC sensor (must be connected separately).
If external NTC is not connected, value 0 is returned.
Returns: thermistor resistance in Ohms.
int resistance = module.readWait("ntc/R").getInt();

Humidity

humidity ( )

Percentage of humidity in air.
Returns: humidity [0:100]%.
int humidity = module.readWait("humidity").getInt();

Pressure

pressure ( )

pressure/mbar ( )

pressure/Pa ( )

pressure/hPa ( )

pressure/psi ( )

Atmospheric pressure in millibars.
Other units: mbar - Millibar, Pa - Pascal, hPa - Hectopascal, psi - Pound per square inch.
Returns: pressure in units.
int pressure = module.readWait("pressure").getInt();

altitude ( )

altitude/m ( )

altitude/ft ( )

Current altitude from sea level.
Other units: m - meters, ft - feets.
Returns: altitude in units.
int altitude = module.readWait("altitude").getInt();

altitude/seaLevel ( pressure )

This command allows to set current pressure at sea level for more precise altitude calculation. By default it is set to 101325 Pascals (1013.25 mbar).
Parameter:
pressure - pressure at sea level in Pascal units.
Default: 101325.
module.write("altitude/seaLevel", 101325);

LED

led ( on )

Control on-board led. Values (true, false) = (on, off)
Parameter:
on - toggle LED [true:false].
module.write("led", false); // Turn LED off