-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTemperatureHumidity.ino
48 lines (42 loc) · 1.36 KB
/
TemperatureHumidity.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
/**
* Example of reading temperature and humidity from the Nicla Sense Env's HS4001 sensor.
*
* Initial author: Sebastian Romero (s.romero@arduino.cc)
*/
#include "Arduino_NiclaSenseEnv.h" // Include the NiclaSenseEnv library
void displaySensorData(TemperatureHumiditySensor& sensor) {
if (sensor.enabled()) {
float temperature = sensor.temperature();
if (isnan(temperature)) {
Serial.println("🌡 Temperature: N/A");
} else {
Serial.print("🌡 Temperature: ");
Serial.print(temperature, 2);
Serial.println("°C");
}
Serial.print("💧 Relative Humidity: ");
Serial.print(sensor.humidity(), 2);
Serial.println();
} else {
Serial.println("🙅 Temperature 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 temperatureSensor = device.temperatureHumiditySensor();
displaySensorData(temperatureSensor);
// Optionally disable the sensor
// temperatureSensor.setEnabled(false);
} else {
Serial.println("🤷 Device could not be found. Please double check the wiring.");
}
}
void loop() {
// Your main code here
}