Advertisement
pleasedontcode

**Alert System** rev_03

Feb 15th, 2025
120
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: **Alert System**
  13.     - Source Code NOT compiled for: Arduino Uno
  14.     - Source Code created on: 2025-02-15 21:28:08
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* The project shall continuously read data from */
  21.     /* connected sensors and actuate outputs based on */
  22.     /* predefined thresholds, ensuring real-time */
  23.     /* responsiveness to environmental changes. */
  24. /****** END SYSTEM REQUIREMENTS *****/
  25.  
  26. /* START CODE */
  27.  
  28. /****** DEFINITION OF LIBRARIES *****/
  29. #include <DHT.h> // Include the DHT library
  30.  
  31. /****** FUNCTION PROTOTYPES *****/
  32. void setup(void);
  33. void loop(void);
  34.  
  35. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  36. const uint8_t myDHT22_DHT22_DOUT_PIN_D2 = 2;
  37.  
  38. // Create an instance of the DHT class
  39. DHT dht(myDHT22_DHT22_DOUT_PIN_D2, DHT22); // Initialize DHT sensor
  40.  
  41. // Define thresholds
  42. float temperatureThreshold = 25.0; // Example threshold for temperature
  43. float humidityThreshold = 60.0;     // Example threshold for humidity
  44.  
  45. void setup(void)
  46. {
  47.     // put your setup code here, to run once:
  48.     pinMode(myDHT22_DHT22_DOUT_PIN_D2, INPUT_PULLUP);
  49.     dht.begin(); // Start the DHT sensor
  50. }
  51.  
  52. void loop(void)
  53. {
  54.     // put your main code here, to run repeatedly:
  55.     delay(2000); // Wait a few seconds between measurements
  56.  
  57.     // Read temperature and humidity
  58.     float humidity = dht.readHumidity();
  59.     float temperature = dht.readTemperature();
  60.  
  61.     // Check if any reads failed and exit early (to try again).
  62.     if (isnan(humidity) || isnan(temperature)) {
  63.         Serial.println("Failed to read from DHT sensor!");
  64.         return;
  65.     }
  66.  
  67.     // Actuate outputs based on thresholds
  68.     if (temperature > temperatureThreshold) {
  69.         // Code to actuate output for high temperature
  70.         Serial.println("Temperature is above threshold!");
  71.     }
  72.     if (humidity > humidityThreshold) {
  73.         // Code to actuate output for high humidity
  74.         Serial.println("Humidity is above threshold!");
  75.     }
  76.  
  77.     // Optionally, print the values for debugging
  78.     Serial.print("Humidity: ");
  79.     Serial.print(humidity);
  80.     Serial.print("%  Temperature: ");
  81.     Serial.print(temperature);
  82.     Serial.println("°C");
  83. }
  84.  
  85. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement