CCCPaste

Temperature Monitor rev_06

/********* 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 Monitor
	- Source Code compiled for: Arduino Uno
	- Source Code created on: 2023-12-29 03:41:44

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

/****** SYSTEM REQUIREMENTS *****/
/****** SYSTEM REQUIREMENT 1 *****/
	/* 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. */
/****** SYSTEM REQUIREMENT 2 *****/
	/* Si se pulsa el pulsador entonces apague el buzzer */
	/* y espere 5s. */
/****** END SYSTEM REQUIREMENTS *****/

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

/****** SYSTEM REQUIREMENTS *****/
/****** SYSTEM REQUIREMENT 1 *****/
/* If the temperature exceeds 35°C, turn on L1 and set A=1, */
/* otherwise turn off L1 and set A=0. If the humidity exceeds */
/* 30, turn on L2 and set B=1, otherwise turn off L2 and set B=0. */
/* If A=1 or B=1, turn on Buzzer. If A=0 and B=0, turn off Buzzer. */
/****** SYSTEM REQUIREMENT 2 *****/
/* If the push button is pressed, turn off the Buzzer and wait for 5s. */
/****** END SYSTEM REQUIREMENTS *****/

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

/***** DEFINITION OF DIGITAL INPUT PINS *****/
const uint8_t D_DHT11_DOUT_PIN_D2 = 2;       // DHT11 sensor data pin
const uint8_t P_PushButton_PIN_D3 = 3;       // Push button pin

/***** DEFINITION OF DIGITAL OUTPUT PINS *****/
const uint8_t B_ActiveBuzzer_output_PIN_D5 = 5;   // Buzzer output pin
const uint8_t L1_LED_PIN_D4 = 4;                   // L1 LED pin
const uint8_t L2_LED_PIN_D6 = 6;                   // L2 LED pin

/****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
EasyButton button(P_PushButton_PIN_D3);  // EasyButton instance for the push button
DHT dht(D_DHT11_DOUT_PIN_D2, DHT11);     // DHT instance for the DHT sensor

// Variables to store the state of A and B
bool A = false;
bool B = false;

void setup(void)
{
  // put your setup code here, to run once:
  pinMode(D_DHT11_DOUT_PIN_D2, INPUT_PULLUP);
  pinMode(P_PushButton_PIN_D3, INPUT_PULLUP);
  pinMode(B_ActiveBuzzer_output_PIN_D5, OUTPUT);
  pinMode(L1_LED_PIN_D4, OUTPUT);
  pinMode(L2_LED_PIN_D6, OUTPUT);

  button.begin();  // Initialize the EasyButton instance
  dht.begin();     // Initialize the DHT instance
}

void loop(void)
{
  // put your main code here, to run repeatedly:
  button.read();  // Read the state of the push button

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

  // Check temperature threshold
  if (temperature > 35)
  {
    digitalWrite(L1_LED_PIN_D4, HIGH);
    A = true;
  }
  else
  {
    digitalWrite(L1_LED_PIN_D4, LOW);
    A = false;
  }

  // Check humidity threshold
  if (humidity > 30)
  {
    digitalWrite(L2_LED_PIN_D6, HIGH);
    B = true;
  }
  else
  {
    digitalWrite(L2_LED_PIN_D6, LOW);
    B = false;
  }

  // Check if A or B is true and turn on/off the Buzzer accordingly
  if (A || B)
  {
    digitalWrite(B_ActiveBuzzer_output_PIN_D5, HIGH);
  }
  else
  {
    digitalWrite(B_ActiveBuzzer_output_PIN_D5, LOW);
  }

  // Check if the push button is pressed and wait for 5 seconds
  if (button.isPressed())
  {
    digitalWrite(B_ActiveBuzzer_output_PIN_D5, LOW);  // Turn off the Buzzer
    delay(5000);  // Wait for 5 seconds
  }
}