blob: f635c30f28943523f49d1a5666c73cafa62b79a7 (
plain)
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
|
// Including the ESP8266 WiFi library
#include <ESP8266WiFi.h>
// Including the DHT library
#include "DHT.h"
// Uncomment one of the lines below for whatever DHT sensor type you're using!
//#define DHTTYPE DHT11 // DHT 11
//#define DHTTYPE DHT21 // DHT 21 (AM2301)
#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321
// DHT Sensor
const int DHTPin = D4;
// Initialize DHT sensor.
DHT dht(DHTPin, DHTTYPE);
void setup() {
Serial.begin(9600); //Output to Serial at 9600 baud
//connectWifi(); // Start ConnecWifi
Serial.print("\n");
Serial.println("ChipId: ");
Serial.println(ESP.getChipId());
dht.begin();
delay(10000);
}
void loop() {
float h = dht.readHumidity();
// Read temperature as Celsius (the default)
float t = dht.readTemperature();
if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
} else {
Serial.print("Humidity: ");
Serial.print(h);
Serial.println("%");
Serial.print("Temperature: ");
Serial.print(t);
Serial.println("°C");
}
delay(5000);
}
|