Advertisement
chillichump

Beginners Guide to Automation Episode 6

Feb 25th, 2020
1,425
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.64 KB | None | 0 0
  1. // youtube.com/chillichump2
  2.  
  3. #include "DHT.h"
  4.  
  5. #define DHTPIN 13
  6.  
  7. #define DHTTYPE DHT22
  8.  
  9. DHT dht(DHTPIN, DHTTYPE);
  10.  
  11. void setup() {
  12.   Serial.begin(9600);
  13.   dht.begin();
  14. }
  15.  
  16. void loop() {
  17.  
  18.   delay(2000);
  19.  
  20.   float h = dht.readHumidity();
  21.  
  22.   float t = dht.readTemperature();
  23.  
  24.   float f = dht.readTemperature(true);
  25.  
  26.   if (isnan(h) || isnan(t) || isnan(f)) {
  27.     Serial.println("No Reading from DHT sensor!");
  28.     return;
  29.   }
  30.  
  31.   Serial.print("Humidity: ");
  32.   Serial.print(h);
  33.   Serial.println("%");
  34.   Serial.print("Temperature: ");
  35.   Serial.print(t);
  36.   Serial.print("°C - ");
  37.   Serial.print(f);
  38.   Serial.print("°F");
  39.  
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement