Advertisement
Guest User

CCCHUMIDITY

a guest
Feb 25th, 2020
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. /* How to use the DHT-22 sensor with Arduino uno
  2. Temperature and humidity sensor
  3. */
  4.  
  5. //Libraries
  6. #include <DHT.h>;
  7.  
  8. //Constants
  9. #define DHTPIN 7 // what pin we're connected to
  10. #define DHTTYPE DHT22 // DHT 22 (AM2302)
  11. DHT dht(DHTPIN, DHTTYPE); //// Initialize DHT sensor for normal 16mhz Arduino
  12.  
  13.  
  14. //Variables
  15. int chk;
  16. float hum; //Stores humidity value
  17. float temp; //Stores temperature value
  18.  
  19. void setup()
  20. {
  21. Serial.begin(9600);
  22. dht.begin();
  23. }
  24.  
  25. void loop()
  26. {
  27. delay(2000);
  28. //Read data and store it to variables hum and temp
  29. hum = dht.readHumidity();
  30. temp= dht.readTemperature();
  31. //Print temp and humidity values to serial monitor
  32. Serial.print("Humidity: ");
  33. Serial.print(hum);
  34. Serial.print(" %, Temp: ");
  35. Serial.print(temp);
  36. Serial.println(" Celsius");
  37. delay(10000); //Delay 2 sec.
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement