#include <DHT.h> #include <DHT_U.h> #define DHTPIN 2 #define DHTTYPE DHT11 DHT dht(DHTPIN,DHTTYPE); void setup() { // put your setup code here, to run once: Serial.begin(9600); Serial.println(F("DHTxx test!")); dht.begin(); } void loop() { // put your main code here, to run repeatedly: delay(2000); float h= dht.readHumidity(); float t = dht.readTemperature(); float f = dht.readTemperature(true); if(isnan(h)||isnan(t)||isnan(f)) { Serial.println(F("Failed to read fromDHT sensor !")); return; } Serial.print(F("Humidity : ")); Serial.print(h); Serial.print(F("% Temperature : ")); Serial.print(t); Serial.print(F(" C : ")); Serial.print(f); Serial.print(F(" F : ")); Serial.println(" "); }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter