mpmcws

DHT11

Jun 15th, 2018
81
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* for DHT11,
  2. VCC: 5V or 3V
  3. GND: GND
  4. DATA: 2
  5. MPMC workshop aprile 2018 Open source
  6. Ultima modifica il 4 aprile 2018 alle 20:46
  7. Versione 1.0 utilizzo: impianto fitodepurazione
  8. This example code is in the public domain.*/
  9.  
  10. #include <SimpleDHT.h>
  11. int pinDHT11 = 2;
  12. SimpleDHT11 dht11;
  13. void setup() {
  14.   Serial.begin(9600);
  15.   Serial.println ("Hallo Marco, I'm ready!");
  16.   delay(2000);
  17. }
  18. void loop() {
  19.   byte temperature = 0;
  20.   byte humidity = 0;
  21.   int err = SimpleDHTErrSuccess;
  22.   if ((err = dht11.read(pinDHT11, &temperature, &humidity, NULL)) != SimpleDHTErrSuccess) {
  23.     Serial.print("Read DHT11 failed, err="); Serial.println(err);delay(1000);
  24.     return;
  25.   }
  26.   Serial.print((int)temperature); Serial.print(" C ");
  27.   Serial.print((int)humidity); Serial.println(" %");
  28.   delay(5000);
  29. }
RAW Paste Data