diff options
Diffstat (limited to 'devices/DHT22_auslesen/DHT22_auslesen.ino')
| -rw-r--r-- | devices/DHT22_auslesen/DHT22_auslesen.ino | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/devices/DHT22_auslesen/DHT22_auslesen.ino b/devices/DHT22_auslesen/DHT22_auslesen.ino new file mode 100644 index 0000000..f635c30 --- /dev/null +++ b/devices/DHT22_auslesen/DHT22_auslesen.ino @@ -0,0 +1,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); +} |
