-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDHT22 HTU21 comp.ino
72 lines (58 loc) · 1.57 KB
/
DHT22 HTU21 comp.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
#include <Adafruit_Sensor.h>
#include <DHT.h>
#include <DHT_U.h>
#include <Wire.h>
#include "SparkFunHTU21D.h"
//Create an instance of the object
HTU21D myHumidity;
#define DHTPIN D3
#define DHTTYPE DHT22 // DHT 22 (AM2302)
DHT_Unified dht(DHTPIN, DHTTYPE);
uint32_t delayMS;
void setup() {
Serial.begin(9600);
dht.begin();
sensor_t sensor;
dht.temperature().getSensor(&sensor); // Set delay between sensor readings based on sensor details.
delayMS = sensor.min_delay / 1000;
Serial.println("HTU21D Example!");
myHumidity.begin();
}
void loop() {
// Delay between measurements.
delay(delayMS);
// Get temperature event and print its value.
sensors_event_t event;
dht.temperature().getEvent(&event);
Serial.print(F(" DHT22:"));
if (isnan(event.temperature)) {
Serial.println(F("Error reading temperature!"));
}
else {
Serial.print(F(" Temperature:"));
Serial.print(event.temperature);
Serial.print(F("C"));
}
// Get humidity event and print its value.
dht.humidity().getEvent(&event);
if (isnan(event.relative_humidity)) {
Serial.print(F("Error reading humidity!"));
}
else {
Serial.print(F(" Humidity:"));
Serial.print(event.relative_humidity);
Serial.print(F("%"));
}
Serial.println();
Serial.print(F(" HTU21:"));
float humd = myHumidity.readHumidity();
float temp = myHumidity.readTemperature();
Serial.print(" Temperature:");
Serial.print(temp, 1);
Serial.print("C");
Serial.print(" Humidity:");
Serial.print(humd, 1);
Serial.print("%");
Serial.println();
delay(1000);
}