Advertisement
pleasedontcode

Sensor Readings rev_03

Jan 12th, 2024
73
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: Arduino Uno
  14.     - Source Code created on: 2024-01-12 11:43:32
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* read temperature in every 5 mins */
  21. /****** END SYSTEM REQUIREMENTS *****/
  22.  
  23. /****** DEFINITION OF LIBRARIES *****/
  24. #include <Arduino.h>
  25. #include <DHT.h>
  26.  
  27. /****** FUNCTION PROTOTYPES *****/
  28. void setup(void);
  29. void loop(void);
  30.  
  31. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  32. const uint8_t DHTPIN = 2;
  33.  
  34. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  35. DHT dht(DHTPIN, DHT11);
  36.  
  37. void setup(void)
  38. {
  39.   // put your setup code here, to run once:
  40.   dht.begin();
  41.   Serial.begin(9600);
  42. }
  43.  
  44. void loop(void)
  45. {
  46.   // put your main code here, to run repeatedly:
  47.   float temperature = dht.readTemperature();
  48.   if (isnan(temperature)) {
  49.     Serial.println("Error reading temperature!");
  50.   } else {
  51.     Serial.print("Temperature: ");
  52.     Serial.print(temperature);
  53.     Serial.println("°C");
  54.   }
  55.  
  56.   float humidity = dht.readHumidity();
  57.   if (isnan(humidity)) {
  58.     Serial.println("Error reading humidity!");
  59.   } else {
  60.     Serial.print("Humidity: ");
  61.     Serial.print(humidity);
  62.     Serial.println("%");
  63.   }
  64.  
  65.   delay(300000); // Delay for 5 minutes (300000 milliseconds)
  66. }
  67.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement