Advertisement
pleasedontcode

Temperature Control rev_05

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