Advertisement
pleasedontcode

Sensor Readings rev_01

Feb 27th, 2024
71
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: Sensor Readings
  13.     - Source Code compiled for: ESP32 DevKit V1
  14.     - Source Code created on: 2024-02-27 09:05:22
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* print tempature value in serial monitor */
  21. /****** END SYSTEM REQUIREMENTS *****/
  22.  
  23. /****** DEFINITION OF LIBRARIES *****/
  24. #include "DHT.h"
  25.  
  26. /****** FUNCTION PROTOTYPES *****/
  27. void setup(void);
  28. void loop(void);
  29.  
  30. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  31. const uint8_t dht_DHT11_DOUT_PIN_D4 = 4;
  32.  
  33. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  34. DHT dht(dht_DHT11_DOUT_PIN_D4, DHT11); // Create DHT object
  35.  
  36. void setup(void)
  37. {
  38.     // put your setup code here, to run once:
  39.     pinMode(dht_DHT11_DOUT_PIN_D4, INPUT_PULLUP);
  40.     dht.begin(); // Initialize DHT sensor
  41.  
  42.     // Add any other setup code here
  43. }
  44.  
  45. void loop(void)
  46. {
  47.     // put your main code here, to run repeatedly:
  48.     // Read temperature and humidity from DHT sensor
  49.     float temperature = dht.readTemperature();
  50.     float humidity = dht.readHumidity();
  51.  
  52.     // Check if temperature and humidity values are valid
  53.     if (isnan(temperature) || isnan(humidity))
  54.     {
  55.         Serial.println(F("Failed to read from DHT sensor!"));
  56.         return;
  57.     }
  58.  
  59.     // Print temperature and humidity values to serial monitor
  60.     Serial.print(F("Temperature: "));
  61.     Serial.print(temperature);
  62.     Serial.print(F("°C, Humidity: "));
  63.     Serial.print(humidity);
  64.     Serial.println(F("%"));
  65.  
  66.     // Add your code to process temperature and humidity values
  67.  
  68.     delay(2000); // Delay for 2 seconds before next reading
  69. }
  70.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement