-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIndoorAirQuality.ino
75 lines (63 loc) · 2.78 KB
/
IndoorAirQuality.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/**
* Example of reading various sensor properties from the Nicla Sense Env's indoor air quality sensor ZMOD4410.
* To read sulfur odor and odor intensity, the sensor mode must be changed.
*
* Initial author: Sebastian Romero (s.romero@arduino.cc)
*/
#include "Arduino_NiclaSenseEnv.h"
void displaySensorData(IndoorAirQualitySensor& sensor) {
if (sensor.enabled()) {
auto iaqMode = sensor.mode();
Serial.print("🔧 Indoor air quality sensor mode: ");
Serial.println(sensor.modeString());
if (iaqMode == IndoorAirQualitySensorMode::sulfur) {
Serial.print("👃 Sulfur odor: ");
Serial.println(sensor.sulfurOdor());
if (sensor.sulfurOdor()) {
Serial.print("👃 Odor intensity: ");
Serial.println(sensor.odorIntensity(), 2);
}
}
if (iaqMode == IndoorAirQualitySensorMode::indoorAirQuality || iaqMode == IndoorAirQualitySensorMode::indoorAirQualityLowPower) {
Serial.print("🏠 Indoor air quality value: ");
Serial.println(sensor.airQuality(), 2);
Serial.print("🏠 Indoor air quality: ");
Serial.println(sensor.airQualityInterpreted());
Serial.print("🏠 Relative indoor air quality: ");
Serial.println(sensor.relativeAirQuality(), 2);
Serial.print("🌬 CO2 (ppm): ");
Serial.println(sensor.CO2(), 2);
Serial.print("🌬 TVOC (mg/m3): ");
Serial.println(sensor.TVOC(), 2);
Serial.print("🍺 Ethanol (ppm): ");
Serial.println(sensor.ethanol(), 2);
}
} else {
Serial.println("🙅 Indoor air quality sensor is disabled");
}
}
void setup() {
Serial.begin(115200);
while (!Serial) {
// Wait for Serial to be ready
}
NiclaSenseEnv device;
if (device.begin()) {
Serial.println("🔌 Device is connected");
auto indoorAirQualitySensor = device.indoorAirQualitySensor();
// Please note that it may take some time for the sensor to deliver the first data.
indoorAirQualitySensor.setMode(IndoorAirQualitySensorMode::indoorAirQuality);
displaySensorData(indoorAirQualitySensor);
// Set indoor air quality sensor mode to sulfur odor (default is indoor air quality)
// After switching modes, you may need to wait some time before the sensor delivers the first data.
// indoorAirQualitySensor.setMode(IndoorAirQualitySensorMode::sulfur);
// display_sensor_data(indoorAirQualitySensor);
// Optionally disable the sensor
// indoorAirQualitySensor.setEnabled(false);
} else {
Serial.println("🤷 Device could not be found. Please double-check the wiring.");
}
}
void loop() {
// Your code here
}