SHARE
TWEET

Untitled

a guest Jun 15th, 2019 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "DHT.h"
  2.  
  3. #define DHTPIN D1
  4. //#define DHTTYPE DHT11   // DHT 11
  5. #define DHTTYPE DHT22   // DHT 22  (AM2302), AM2321
  6. //#define DHTTYPE DHT21   // DHT 21 (AM2301)
  7.  
  8. DHT dht(DHTPIN, DHTTYPE);
  9.  
  10. void setup() {
  11.   Serial.begin(9600);
  12.   Serial.println(F("DHTxx test!"));
  13.   dht.begin();
  14. }
  15.  
  16. void loop() {
  17.   delay(2000);
  18.   float h = dht.readHumidity();
  19.   float t = dht.readTemperature();
  20.   float f = dht.readTemperature(true);
  21.  
  22.   if (isnan(h) || isnan(t) || isnan(f)) {
  23.     Serial.println(F("Failed to read from DHT sensor!"));
  24.     return;
  25.   }
  26.  
  27.   float hif = dht.computeHeatIndex(f, h);
  28.   float hic = dht.computeHeatIndex(t, h, false);
  29.  
  30.   Serial.print(F("Humidity: "));
  31.   Serial.print(h);
  32.   Serial.print(F("%  Temperature: "));
  33.   Serial.print(t);
  34.   Serial.print(F(" C "));
  35.   Serial.print(f);
  36.   Serial.print(F(" F  Heat index: "));
  37.   Serial.print(hic);
  38.   Serial.print(F(" C "));
  39.   Serial.print(hif);
  40.   Serial.println(F(" F"));
  41. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top