-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDHT22_sensor.ino
63 lines (47 loc) · 1.33 KB
/
DHT22_sensor.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
#include "DHT.h"
#define DHTPIN1 2
#define DHTPIN2 4
#define DHTTYPE DHT22
DHT dht1(DHTPIN1, DHTTYPE);
DHT dht2(DHTPIN2, DHTTYPE);
float h1,h2,t1,t2,hic1,hic2;
void setup() {
Serial.begin(9600);
Serial.println(F("DHTxx test!"));
dht1.begin();
dht2.begin();
}
void loop() {
delay(2000);
float h1 = dht1.readHumidity();
float t1 = dht1.readTemperature();
float h2 = dht2.readHumidity();
float t2 = dht2.readTemperature();
if (isnan(h1) || isnan(t1) ) {
Serial.println(F("Failed to read from DHT sensor 1!"));
return;
}
if (isnan(h2) || isnan(t2)) {
Serial.println(F("Failed to read from DHT sensor 2!"));
return;
}
// Compute heat index in Celsius (isFahreheit = false)
hic1 = dht1.computeHeatIndex(t1, h1, false);
hic2 = dht2.computeHeatIndex(t2, h2, false);
Serial.print(F("Humidity(1): "));
Serial.print(h1);
Serial.print(F("% Temperature(1): "));
Serial.print(t1);
Serial.print(F("°C "));
Serial.print(F(" Heat index(1): "));
Serial.print(hic1);
Serial.print(F("°C "));
Serial.print(F("Humidity(2): "));
Serial.print(h2);
Serial.print(F("% Temperature(2): "));
Serial.print(t2);
Serial.print(F("°C "));
Serial.print(F(" Heat index(2): "));
Serial.print(hic2);
Serial.print(F("°C "));
}