Advertisement
pleasedontcode

Temp_and_hum_alarm

Jan 8th, 2024
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Arduino 6.54 KB | Source Code | 0 0
  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: Temp_and_hum_alarm
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2024-01-05 23:56:30
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* On power up: set temp_max to 35, hum_max to 50, */
  21.     /* normal_mode true, focus = "nothing". */
  22. /****** SYSTEM REQUIREMENT 2 *****/
  23.     /* If normal_mode is true then: read temperature and */
  24.     /* humidity from DHT11 and write to LCD. If */
  25.     /* temperature exceeds temp_max or humidity exceeds */
  26.     /* hum_max then enable buzzer and led, otherwise */
  27.     /* disable buzzer and Led. */
  28. /****** SYSTEM REQUIREMENT 3 *****/
  29.     /* If normal_mode is true and B1 is pressed then */
  30.     /* normal_mode false, focus = "temp", write to LCD */
  31.     /* temp_max. */
  32. /****** SYSTEM REQUIREMENT 4 *****/
  33.     /* If normal_mode is false and focus = "temp" then if */
  34.     /* B1 is pressed then focus = "hum", write to LCD */
  35.     /* hum_max. */
  36. /****** SYSTEM REQUIREMENT 5 *****/
  37.     /* If normal_mode is false and focus = "hum" then if */
  38.     /* B1 is pressed then focus = "nothing", normal_mode */
  39.     /* true. */
  40. /****** SYSTEM REQUIREMENT 6 *****/
  41.     /* If normal_mode is false and focus = "temp" then if */
  42.     /* B2 is pressed, add 1 to temp_max, write in LCD */
  43.     /* temp_max. */
  44. /****** SYSTEM REQUIREMENT 7 *****/
  45.     /* If normal_mode is false and focus = "temp" then if */
  46.     /* B3 is pressed, subtract 1 from temp_max, write */
  47.     /* temp_max on LCD. */
  48. /****** SYSTEM REQUIREMENT 8 *****/
  49.     /* If normal_mode is false and focus = "hum" then if */
  50.     /* B2 is pressed add 1 to hum_max, write hum_max on */
  51.     /* LCD. */
  52. /****** SYSTEM REQUIREMENT 9 *****/
  53.     /* If normal_mode is false and focus = "hum" then if */
  54.     /* B3 is pressed, subtract 1 from hum_max, write */
  55.     /* hum_max in LCD. */
  56. /****** END SYSTEM REQUIREMENTS *****/
  57.  
  58. /****** DEFINITION OF LIBRARIES *****/
  59. #include <Arduino.h>
  60. #include <LiquidCrystal.h>
  61. #include <EasyButton.h>
  62. #include <DHT.h>
  63.  
  64. /****** FUNCTION PROTOTYPES *****/
  65. void setup(void);
  66. void loop(void);
  67.  
  68. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  69. const uint8_t D_DHT11_DOUT_PIN_D2 = 2;
  70. const uint8_t B1_PushButton_PIN_D9 = 9;
  71. const uint8_t B2_PushButton_PIN_D10 = 10;
  72. const uint8_t B3_PushButton_PIN_D11 = 11;
  73.  
  74. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  75. const uint8_t L_LCD1602_RS_PIN_D3 = 3;
  76. const uint8_t L_LCD1602_E_PIN_D4 = 4;
  77. const uint8_t L_LCD1602_D4_PIN_D5 = 5;
  78. const uint8_t L_LCD1602_D5_PIN_D6 = 6;
  79. const uint8_t L_LCD1602_D6_PIN_D7 = 7;
  80. const uint8_t L_LCD1602_D7_PIN_D8 = 8;
  81. const uint8_t LED_LED_PIN_D12 = 12;
  82. const uint8_t B_ActiveBuzzer_output_PIN_D13 = 13;
  83.  
  84. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  85. LiquidCrystal lcd(L_LCD1602_RS_PIN_D3, L_LCD1602_E_PIN_D4, L_LCD1602_D4_PIN_D5, L_LCD1602_D5_PIN_D6, L_LCD1602_D6_PIN_D7, L_LCD1602_D7_PIN_D8);
  86. EasyButton b1(B1_PushButton_PIN_D9);
  87. EasyButton b2(B2_PushButton_PIN_D10);
  88. EasyButton b3(B3_PushButton_PIN_D11);
  89. DHT dht(D_DHT11_DOUT_PIN_D2, DHT11);
  90.  
  91. // System variables
  92. bool normal_mode = true;
  93. int temp_max = 35;
  94. int hum_max = 50;
  95. String focus = "nothing";
  96.  
  97. void setup(void)
  98. {
  99.   // put your setup code here, to run once:
  100.  
  101.   pinMode(D_DHT11_DOUT_PIN_D2,  INPUT_PULLUP);
  102.   pinMode(B1_PushButton_PIN_D9,  INPUT_PULLUP);
  103.   pinMode(B2_PushButton_PIN_D10, INPUT_PULLUP);
  104.   pinMode(B3_PushButton_PIN_D11, INPUT_PULLUP);
  105.  
  106.   pinMode(L_LCD1602_RS_PIN_D3,         OUTPUT);
  107.   pinMode(L_LCD1602_E_PIN_D4,          OUTPUT);
  108.   pinMode(L_LCD1602_D4_PIN_D5,         OUTPUT);
  109.   pinMode(L_LCD1602_D5_PIN_D6,         OUTPUT);
  110.   pinMode(L_LCD1602_D6_PIN_D7,         OUTPUT);
  111.   pinMode(L_LCD1602_D7_PIN_D8,         OUTPUT);
  112.   pinMode(LED_LED_PIN_D12,             OUTPUT);
  113.   pinMode(B_ActiveBuzzer_output_PIN_D13, OUTPUT);
  114.  
  115.   lcd.begin(16, 2);
  116.   b1.begin();
  117.   b2.begin();
  118.   b3.begin();
  119.   dht.begin();
  120.  
  121.   // Set initial values
  122.   temp_max = 35;
  123.   hum_max = 50;
  124.   normal_mode = true;
  125.   focus = "nothing";
  126. }
  127.  
  128. void loop(void)
  129. {
  130.   // put your main code here, to run repeatedly:
  131.  
  132.   // SYSTEM REQUIREMENT 2
  133.   if (normal_mode)
  134.   {
  135.     float temperature = dht.readTemperature();
  136.     float humidity = dht.readHumidity();
  137.  
  138.     lcd.setCursor(0, 0);
  139.     lcd.print("Temp: ");
  140.     lcd.print(temperature);
  141.     lcd.print("C");
  142.  
  143.     lcd.setCursor(0, 1);
  144.     lcd.print("Humidity: ");
  145.     lcd.print(humidity);
  146.     lcd.print("%");
  147.  
  148.     // Check if temperature exceeds temp_max
  149.     if (temperature > temp_max || humidity > hum_max)
  150.     {
  151.       digitalWrite(LED_LED_PIN_D12, HIGH);
  152.       digitalWrite(B_ActiveBuzzer_output_PIN_D13, HIGH);
  153.     }
  154.     else
  155.     {
  156.       digitalWrite(LED_LED_PIN_D12, LOW);
  157.       digitalWrite(B_ActiveBuzzer_output_PIN_D13, LOW);
  158.     }
  159.   }
  160.  
  161.   // Read buttons
  162.   b1.read();
  163.   b2.read();
  164.   b3.read();
  165.  
  166.   // SYSTEM REQUIREMENT 3
  167.   if (normal_mode && b1.wasPressed())
  168.   {
  169.     normal_mode = false;
  170.     focus = "temp";
  171.  
  172.     lcd.clear();
  173.     lcd.setCursor(0, 0);
  174.     lcd.print("Temp Max: ");
  175.     lcd.print(temp_max);
  176.     lcd.print("C");
  177.   }
  178.   // SYSTEM REQUIREMENT 4
  179.   else if (!normal_mode && focus == "temp" && b1.wasPressed())
  180.   {
  181.     focus = "hum";
  182.  
  183.     lcd.clear();
  184.     lcd.setCursor(0, 0);
  185.     lcd.print("Hum Max: ");
  186.     lcd.print(hum_max);
  187.     lcd.print("%");
  188.   }
  189.   // SYSTEM REQUIREMENT 5
  190.   else if (!normal_mode && focus == "hum" && b1.wasPressed())
  191.   {
  192.     focus = "nothing";
  193.     normal_mode = true;
  194.     lcd.clear();
  195.   }
  196.  
  197.   // SYSTEM REQUIREMENT 6
  198.   if (!normal_mode && focus == "temp" && b2.wasPressed())
  199.   {
  200.     temp_max++;
  201.     lcd.setCursor(10, 0);
  202.     lcd.print(temp_max);
  203.     lcd.print("C");
  204.   }
  205.  
  206.   // SYSTEM REQUIREMENT 7
  207.   if (!normal_mode && focus == "temp" && b3.wasPressed())
  208.   {
  209.     temp_max--;
  210.     lcd.setCursor(10, 0);
  211.     lcd.print(temp_max);
  212.     lcd.print("C");
  213.   }
  214.  
  215.   // SYSTEM REQUIREMENT 8
  216.   if (!normal_mode && focus == "hum" && b2.wasPressed())
  217.   {
  218.     hum_max++;
  219.     lcd.setCursor(9, 0);
  220.     lcd.print(hum_max);
  221.     lcd.print("%");
  222.   }
  223.  
  224.   // SYSTEM REQUIREMENT 9
  225.   if (!normal_mode && focus == "hum" && b3.wasPressed())
  226.   {
  227.     hum_max--;
  228.     lcd.setCursor(9, 0);
  229.     lcd.print(hum_max);
  230.     lcd.print("%");
  231.   }
  232.  
  233. }
  234.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement