Advertisement
pleasedontcode

Temperature Monitor rev_06

Dec 28th, 2023
97
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: Temperature Monitor
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2023-12-29 03:41:44
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Si la temperatura supera los 35° entonces enciende */
  21.     /* L1 y A=1, si no apaga L1 y A=0.   Si la humedad */
  22.     /* supera los 30 entonces enciende L2 y B=1, si no */
  23.     /* apaga L1 y B=0. Si A=1 o B=1 entonces encienda */
  24.     /* Buzzer. Si A=0 y B=0 entonces apague Buzzer. */
  25. /****** SYSTEM REQUIREMENT 2 *****/
  26.     /* Si se pulsa el pulsador entonces apague el buzzer */
  27.     /* y espere 5s. */
  28. /****** END SYSTEM REQUIREMENTS *****/
  29.  
  30. /****** DEFINITION OF LIBRARIES *****/
  31. #include <Arduino.h>
  32. #include <EasyButton.h>
  33. #include <DHT.h>
  34.  
  35. /****** SYSTEM REQUIREMENTS *****/
  36. /****** SYSTEM REQUIREMENT 1 *****/
  37. /* If the temperature exceeds 35°C, turn on L1 and set A=1, */
  38. /* otherwise turn off L1 and set A=0. If the humidity exceeds */
  39. /* 30, turn on L2 and set B=1, otherwise turn off L2 and set B=0. */
  40. /* If A=1 or B=1, turn on Buzzer. If A=0 and B=0, turn off Buzzer. */
  41. /****** SYSTEM REQUIREMENT 2 *****/
  42. /* If the push button is pressed, turn off the Buzzer and wait for 5s. */
  43. /****** END SYSTEM REQUIREMENTS *****/
  44.  
  45. /****** FUNCTION PROTOTYPES *****/
  46. void setup(void);
  47. void loop(void);
  48.  
  49. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  50. const uint8_t D_DHT11_DOUT_PIN_D2 = 2;       // DHT11 sensor data pin
  51. const uint8_t P_PushButton_PIN_D3 = 3;       // Push button pin
  52.  
  53. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  54. const uint8_t B_ActiveBuzzer_output_PIN_D5 = 5;   // Buzzer output pin
  55. const uint8_t L1_LED_PIN_D4 = 4;                   // L1 LED pin
  56. const uint8_t L2_LED_PIN_D6 = 6;                   // L2 LED pin
  57.  
  58. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  59. EasyButton button(P_PushButton_PIN_D3);  // EasyButton instance for the push button
  60. DHT dht(D_DHT11_DOUT_PIN_D2, DHT11);     // DHT instance for the DHT sensor
  61.  
  62. // Variables to store the state of A and B
  63. bool A = false;
  64. bool B = false;
  65.  
  66. void setup(void)
  67. {
  68.   // put your setup code here, to run once:
  69.   pinMode(D_DHT11_DOUT_PIN_D2, INPUT_PULLUP);
  70.   pinMode(P_PushButton_PIN_D3, INPUT_PULLUP);
  71.   pinMode(B_ActiveBuzzer_output_PIN_D5, OUTPUT);
  72.   pinMode(L1_LED_PIN_D4, OUTPUT);
  73.   pinMode(L2_LED_PIN_D6, OUTPUT);
  74.  
  75.   button.begin();  // Initialize the EasyButton instance
  76.   dht.begin();     // Initialize the DHT instance
  77. }
  78.  
  79. void loop(void)
  80. {
  81.   // put your main code here, to run repeatedly:
  82.   button.read();  // Read the state of the push button
  83.  
  84.   // Read temperature and humidity from DHT sensor
  85.   float temperature = dht.readTemperature();
  86.   float humidity = dht.readHumidity();
  87.  
  88.   // Check temperature threshold
  89.   if (temperature > 35)
  90.   {
  91.     digitalWrite(L1_LED_PIN_D4, HIGH);
  92.     A = true;
  93.   }
  94.   else
  95.   {
  96.     digitalWrite(L1_LED_PIN_D4, LOW);
  97.     A = false;
  98.   }
  99.  
  100.   // Check humidity threshold
  101.   if (humidity > 30)
  102.   {
  103.     digitalWrite(L2_LED_PIN_D6, HIGH);
  104.     B = true;
  105.   }
  106.   else
  107.   {
  108.     digitalWrite(L2_LED_PIN_D6, LOW);
  109.     B = false;
  110.   }
  111.  
  112.   // Check if A or B is true and turn on/off the Buzzer accordingly
  113.   if (A || B)
  114.   {
  115.     digitalWrite(B_ActiveBuzzer_output_PIN_D5, HIGH);
  116.   }
  117.   else
  118.   {
  119.     digitalWrite(B_ActiveBuzzer_output_PIN_D5, LOW);
  120.   }
  121.  
  122.   // Check if the push button is pressed and wait for 5 seconds
  123.   if (button.isPressed())
  124.   {
  125.     digitalWrite(B_ActiveBuzzer_output_PIN_D5, LOW);  // Turn off the Buzzer
  126.     delay(5000);  // Wait for 5 seconds
  127.   }
  128. }
  129.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement