CCCPaste

Temperature Control rev_05

/********* Pleasedontcode.com **********

	Pleasedontcode thanks you for automatic code generation! Enjoy your code!

	- Terms and Conditions:
	You have a non-exclusive, revocable, worldwide, royalty-free license
	for personal and commercial use. Attribution is optional; modifications
	are allowed, but you're responsible for code maintenance. We're not
	liable for any loss or damage. For full terms,
	please visit pleasedontcode.com/termsandconditions.

	- Project: Temperature Control
	- Source Code compiled for: Arduino Uno
	- Source Code created on: 2023-12-29 03:36:28

********* Pleasedontcode.com **********/

/****** SYSTEM REQUIREMENTS *****/
/****** SYSTEM REQUIREMENT 1 *****/
	/* Si se pulsa el pulsador apague el buzzer y no haga */
	/* nada durante 5s. */
/****** SYSTEM REQUIREMENT 2 *****/
	/* Si la temperatura supera los 35° entonces enciende */
	/* L1 y A=1, si no apaga L1 y A=0.   Si la humedad */
	/* supera los 30 entonces enciende L2 y B=1, si no */
	/* apaga L1 y B=0. Si A=1 o B=1 entonces encienda */
	/* Buzzer. Si A=0 y B=0 entonces apague Buzzer. */
/****** END SYSTEM REQUIREMENTS *****/

/****** DEFINITION OF LIBRARIES *****/
#include 
#include 

/****** FUNCTION PROTOTYPES *****/
void setup(void);
void loop(void);

/***** DEFINITION OF DIGITAL INPUT PINS *****/
const uint8_t DHTPIN = 2; // DHT11 data output pin

/***** DEFINITION OF DIGITAL OUTPUT PINS *****/
const uint8_t B_ActiveBuzzer_output_PIN_D5 = 5;
const uint8_t L1_LED_PIN_D4 = 4;
const uint8_t L2_LED_PIN_D6 = 6;

/****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
DHT dht(DHTPIN, DHT11); // Instance of the DHT sensor library

void setup(void)
{
  // put your setup code here, to run once:

  pinMode(DHTPIN, INPUT_PULLUP);

  pinMode(B_ActiveBuzzer_output_PIN_D5, OUTPUT);
  pinMode(L1_LED_PIN_D4, OUTPUT);
  pinMode(L2_LED_PIN_D6, OUTPUT);

  // Initialize the DHT sensor
  dht.begin();
}

void loop(void)
{
  // put your main code here, to run repeatedly:

  // Read the temperature and humidity from the DHT sensor
  float temp = dht.readTemperature();
  float humidity = dht.readHumidity();

  if (isnan(temp) || isnan(humidity))
  {
    // Failed to read from the DHT sensor
    // Handle error here
  }
  else
  {
    // Temperature and humidity values are valid, do something with them
    // Example: print the values to Serial Monitor
    Serial.print("Temperature: ");
    Serial.print(temp);
    Serial.print(" °C, Humidity: ");
    Serial.print(humidity);
    Serial.println(" %");

    // SYSTEM REQUIREMENT 1: If button is pressed, turn off the buzzer and do nothing for 5 seconds
    if (digitalRead(B_ActiveBuzzer_output_PIN_D5) == HIGH)
    {
      digitalWrite(B_ActiveBuzzer_output_PIN_D5, LOW); // Turn off the buzzer
      delay(5000);                                    // Delay for 5 seconds
      digitalWrite(B_ActiveBuzzer_output_PIN_D5, HIGH); // Turn on the buzzer
    }

    // SYSTEM REQUIREMENT 2: Control LEDs based on temperature and humidity values
    bool A = false;
    bool B = false;

    if (temp > 35)
    {
      digitalWrite(L1_LED_PIN_D4, HIGH); // Turn on L1 LED
      A = true;
    }
    else
    {
      digitalWrite(L1_LED_PIN_D4, LOW); // Turn off L1 LED
    }

    if (humidity > 30)
    {
      digitalWrite(L2_LED_PIN_D6, HIGH); // Turn on L2 LED
      B = true;
    }
    else
    {
      digitalWrite(L2_LED_PIN_D6, LOW); // Turn off L2 LED
    }

    if (A || B)
    {
      digitalWrite(B_ActiveBuzzer_output_PIN_D5, HIGH); // Turn on the buzzer
    }
    else
    {
      digitalWrite(B_ActiveBuzzer_output_PIN_D5, LOW); // Turn off the buzzer
    }
  }

  delay(2000); // Delay for 2 seconds before reading again
}