Advertisement
ossipee

DHT22

Aug 7th, 2014
361
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.93 KB | None | 0 0
  1.    
  2.  
  3.     #include <DHT.h>
  4.      
  5.     #define DHTPIN 6
  6.      
  7.     #define DHTYPE DHT22
  8.      
  9.     DHT dht(DHTPIN, DHTYPE);
  10.      
  11.     void setup(){
  12.       Serial.begin(115200);
  13.       Serial.println("Type,\tstatus,\tHumidity (%),\tTemperature (C)");
  14.     }
  15.     void loop(){
  16.       Serial.print("DHT22, \t");
  17.        delay(2000);
  18.      
  19.       // Reading temperature or humidity takes about 250 milliseconds!
  20.       // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  21.       float h = dht.readHumidity();
  22.       // Read temperature as Celsius
  23.       float t = dht.readTemperature();
  24.       // Read temperature as Fahrenheit
  25.       float f = dht.readTemperature(true);
  26.      
  27.       Serial.print("Humidity: ");
  28.       Serial.print(h);
  29.       Serial.print(" %\t");
  30.       Serial.print("Temperature: ");
  31.       Serial.print(t);
  32.       Serial.print(" *C ");
  33.       Serial.print(f);
  34.       Serial.println(" *F\t");
  35.      
  36.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement