Advertisement
Guest User

DHT22 code

a guest
Jun 17th, 2024
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. /* DHT11/ DHT22 Sensor Temperature and Humidity Tutorial
  2. * Program made by Dejan Nedelkovski,
  3. * www.HowToMechatronics.com
  4. */
  5. /*
  6. * You can find the DHT Library from Arduino official website
  7. * https://playground.arduino.cc/Main/DHTLib
  8. */
  9.  
  10. #include "DHT.h"
  11. #define DHTPIN 2
  12. #define DHTTYPE DHT22
  13. DHT dht(DHTPIN, DHTTYPE);
  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.  
  26. void loop()
  27. {
  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(2000); //Delay 2 sec
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement