Advertisement
pleasedontcode

Temperature Monitor rev_04

Dec 28th, 2023
85
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:33:28
  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 temperatura */
  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 apague el buzzer y no haga */
  27.     /* nada durante 5s. */
  28. /****** END SYSTEM REQUIREMENTS *****/
  29.  
  30. /****** DEFINITION OF LIBRARIES *****/
  31. #include <Arduino.h>
  32. #include <EasyButton.h>
  33. #include <DHT.h>
  34.  
  35. /****** FUNCTION PROTOTYPES *****/
  36. void setup(void);
  37. void loop(void);
  38.  
  39. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  40. const uint8_t D_DHT11_DOUT_PIN_D2 = 2;
  41. const uint8_t P_PushButton_PIN_D3 = 3;
  42.  
  43. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  44. const uint8_t B_ActiveBuzzer_output_PIN_D5 = 5;
  45. const uint8_t L1_LED_PIN_D4 = 4;
  46. const uint8_t L2_LED_PIN_D6 = 6;
  47.  
  48. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  49. EasyButton pushButton(P_PushButton_PIN_D3);
  50. DHT dht(D_DHT11_DOUT_PIN_D2, DHT11);
  51.  
  52. /****** SYSTEM REQUIREMENTS *****/
  53. bool A = false; // Variable to track requirement 1 condition A
  54. bool B = false; // Variable to track requirement 1 condition B
  55. bool buzzerEnabled = false; // Variable to track buzzer state
  56. unsigned long buttonPressTime = 0; // Variable to track button press time
  57.  
  58. void setup(void)
  59. {
  60.   // put your setup code here, to run once:
  61.  
  62.   pinMode(D_DHT11_DOUT_PIN_D2, INPUT_PULLUP);
  63.   pinMode(P_PushButton_PIN_D3, INPUT_PULLUP);
  64.  
  65.   pinMode(B_ActiveBuzzer_output_PIN_D5, OUTPUT);
  66.   pinMode(L1_LED_PIN_D4, OUTPUT);
  67.   pinMode(L2_LED_PIN_D6, OUTPUT);
  68.  
  69.   dht.begin();
  70. }
  71.  
  72. void loop(void)
  73. {
  74.   // put your main code here, to run repeatedly:
  75.  
  76.   float temperature = dht.readTemperature();
  77.  
  78.   /****** SYSTEM REQUIREMENT 1 *****/
  79.   if (temperature > 35) {
  80.     digitalWrite(L1_LED_PIN_D4, HIGH);
  81.     A = true;
  82.   } else {
  83.     digitalWrite(L1_LED_PIN_D4, LOW);
  84.     A = false;
  85.   }
  86.  
  87.   if (temperature > 30) {
  88.     digitalWrite(L2_LED_PIN_D6, HIGH);
  89.     B = true;
  90.   } else {
  91.     digitalWrite(L2_LED_PIN_D6, LOW);
  92.     B = false;
  93.   }
  94.  
  95.   if (A || B) {
  96.     digitalWrite(B_ActiveBuzzer_output_PIN_D5, HIGH);
  97.     buzzerEnabled = true;
  98.   } else {
  99.     digitalWrite(B_ActiveBuzzer_output_PIN_D5, LOW);
  100.     buzzerEnabled = false;
  101.   }
  102.  
  103.   /****** SYSTEM REQUIREMENT 2 *****/
  104.   if (pushButton.isPressed()) {
  105.     digitalWrite(B_ActiveBuzzer_output_PIN_D5, LOW);
  106.     buzzerEnabled = false;
  107.     buttonPressTime = millis();
  108.    
  109.     while (millis() - buttonPressTime < 5000) {
  110.       // Do nothing for 5 seconds
  111.     }
  112.   }
  113. }
  114.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement