Advertisement
pleasedontcode

DHT22 Monitor rev_01

Aug 6th, 2024
316
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: DHT22 Monitor
  13.     - Source Code NOT compiled for: ESP32 DevKit V1
  14.     - Source Code created on: 2024-08-06 12:05:36
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Hőmérséklet- és páratartalom-ellenőrző rendszert */
  21.     /* valósítson meg a D4 digitális érintkezőhöz */
  22.     /* csatlakoztatott DHT22 érzékelővel. Biztosítsa a */
  23.     /* pontos leolvasásokat, és kecsesen kezelje az */
  24.     /* esetleges érzékelőhibákat. */
  25. /****** END SYSTEM REQUIREMENTS *****/
  26.  
  27. /****** DEFINITION OF LIBRARIES *****/
  28. #include <DHT.h>    // https://github.com/adafruit/DHT-sensor-library
  29.  
  30. /****** FUNCTION PROTOTYPES *****/
  31. void setup(void);
  32. void loop(void);
  33.  
  34. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  35. const uint8_t dht_DHT22_DOUT_PIN_D4 = 4; // Define the pin for DHT22 sensor
  36.  
  37. /***** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  38. // Create an instance of the DHT class for the DHT22 sensor
  39. DHT dht(dht_DHT22_DOUT_PIN_D4, DHT22); // Initialize DHT sensor on pin D4
  40.  
  41. void setup(void)
  42. {
  43.     // Initialize serial communication at 9600 baud
  44.     Serial.begin(9600);
  45.     dht.begin(); // Initialize the DHT sensor
  46. }
  47.  
  48. void loop(void)
  49. {
  50.     // Wait a few seconds between measurements
  51.     delay(2000);
  52.  
  53.     // Read temperature as Celsius
  54.     float temperature = dht.readTemperature();
  55.     if (isnan(temperature)) {
  56.         // Handle the case where the temperature reading failed
  57.         Serial.println(F("Failed to read temperature from DHT sensor!"));
  58.     } else {
  59.         // Print the temperature value
  60.         Serial.print(F("Temperature: "));
  61.         Serial.print(temperature);
  62.         Serial.println(F("°C"));
  63.     }
  64.  
  65.     // Read humidity
  66.     float humidity = dht.readHumidity();
  67.     if (isnan(humidity)) {
  68.         // Handle the case where the humidity reading failed
  69.         Serial.println(F("Failed to read humidity from DHT sensor!"));
  70.     } else {
  71.         // Print the humidity value
  72.         Serial.print(F("Humidity: "));
  73.         Serial.print(humidity);
  74.         Serial.println(F("%"));
  75.     }
  76. }
  77.  
  78. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement