CCCPaste

Temp_and_hum_alarm

/********* 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: Temp_and_hum_alarm
	- Source Code compiled for: Arduino Uno
	- Source Code created on: 2024-01-05 23:56:30

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

/****** SYSTEM REQUIREMENTS *****/
/****** SYSTEM REQUIREMENT 1 *****/
	/* On power up: set temp_max to 35, hum_max to 50, */
	/* normal_mode true, focus = "nothing". */
/****** SYSTEM REQUIREMENT 2 *****/
	/* If normal_mode is true then: read temperature and */
	/* humidity from DHT11 and write to LCD. If */
	/* temperature exceeds temp_max or humidity exceeds */
	/* hum_max then enable buzzer and led, otherwise */
	/* disable buzzer and Led. */
/****** SYSTEM REQUIREMENT 3 *****/
	/* If normal_mode is true and B1 is pressed then */
	/* normal_mode false, focus = "temp", write to LCD */
	/* temp_max. */
/****** SYSTEM REQUIREMENT 4 *****/
	/* If normal_mode is false and focus = "temp" then if */
	/* B1 is pressed then focus = "hum", write to LCD */
	/* hum_max. */
/****** SYSTEM REQUIREMENT 5 *****/
	/* If normal_mode is false and focus = "hum" then if */
	/* B1 is pressed then focus = "nothing", normal_mode */
	/* true. */
/****** SYSTEM REQUIREMENT 6 *****/
	/* If normal_mode is false and focus = "temp" then if */
	/* B2 is pressed, add 1 to temp_max, write in LCD */
	/* temp_max. */
/****** SYSTEM REQUIREMENT 7 *****/
	/* If normal_mode is false and focus = "temp" then if */
	/* B3 is pressed, subtract 1 from temp_max, write */
	/* temp_max on LCD. */
/****** SYSTEM REQUIREMENT 8 *****/
	/* If normal_mode is false and focus = "hum" then if */
	/* B2 is pressed add 1 to hum_max, write hum_max on */
	/* LCD. */
/****** SYSTEM REQUIREMENT 9 *****/
	/* If normal_mode is false and focus = "hum" then if */
	/* B3 is pressed, subtract 1 from hum_max, write */
	/* hum_max in LCD. */
/****** END SYSTEM REQUIREMENTS *****/

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

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

/***** DEFINITION OF DIGITAL INPUT PINS *****/
const uint8_t D_DHT11_DOUT_PIN_D2 = 2;
const uint8_t B1_PushButton_PIN_D9 = 9;
const uint8_t B2_PushButton_PIN_D10 = 10;
const uint8_t B3_PushButton_PIN_D11 = 11;

/***** DEFINITION OF DIGITAL OUTPUT PINS *****/
const uint8_t L_LCD1602_RS_PIN_D3 = 3;
const uint8_t L_LCD1602_E_PIN_D4 = 4;
const uint8_t L_LCD1602_D4_PIN_D5 = 5;
const uint8_t L_LCD1602_D5_PIN_D6 = 6;
const uint8_t L_LCD1602_D6_PIN_D7 = 7;
const uint8_t L_LCD1602_D7_PIN_D8 = 8;
const uint8_t LED_LED_PIN_D12 = 12;
const uint8_t B_ActiveBuzzer_output_PIN_D13 = 13;

/****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
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);
EasyButton b1(B1_PushButton_PIN_D9);
EasyButton b2(B2_PushButton_PIN_D10);
EasyButton b3(B3_PushButton_PIN_D11);
DHT dht(D_DHT11_DOUT_PIN_D2, DHT11);

// System variables
bool normal_mode = true;
int temp_max = 35;
int hum_max = 50;
String focus = "nothing";

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

  pinMode(D_DHT11_DOUT_PIN_D2,  INPUT_PULLUP);
  pinMode(B1_PushButton_PIN_D9,  INPUT_PULLUP);
  pinMode(B2_PushButton_PIN_D10, INPUT_PULLUP);
  pinMode(B3_PushButton_PIN_D11, INPUT_PULLUP);

  pinMode(L_LCD1602_RS_PIN_D3,         OUTPUT);
  pinMode(L_LCD1602_E_PIN_D4,          OUTPUT);
  pinMode(L_LCD1602_D4_PIN_D5,         OUTPUT);
  pinMode(L_LCD1602_D5_PIN_D6,         OUTPUT);
  pinMode(L_LCD1602_D6_PIN_D7,         OUTPUT);
  pinMode(L_LCD1602_D7_PIN_D8,         OUTPUT);
  pinMode(LED_LED_PIN_D12,             OUTPUT);
  pinMode(B_ActiveBuzzer_output_PIN_D13, OUTPUT);

  lcd.begin(16, 2);
  b1.begin();
  b2.begin();
  b3.begin();
  dht.begin();

  // Set initial values
  temp_max = 35;
  hum_max = 50;
  normal_mode = true;
  focus = "nothing";
}

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

  // SYSTEM REQUIREMENT 2
  if (normal_mode)
  {
    float temperature = dht.readTemperature();
    float humidity = dht.readHumidity();

    lcd.setCursor(0, 0);
    lcd.print("Temp: ");
    lcd.print(temperature);
    lcd.print("C");

    lcd.setCursor(0, 1);
    lcd.print("Humidity: ");
    lcd.print(humidity);
    lcd.print("%");

    // Check if temperature exceeds temp_max
    if (temperature > temp_max || humidity > hum_max)
    {
      digitalWrite(LED_LED_PIN_D12, HIGH);
      digitalWrite(B_ActiveBuzzer_output_PIN_D13, HIGH);
    }
    else
    {
      digitalWrite(LED_LED_PIN_D12, LOW);
      digitalWrite(B_ActiveBuzzer_output_PIN_D13, LOW);
    }
  }

  // Read buttons
  b1.read();
  b2.read();
  b3.read();

  // SYSTEM REQUIREMENT 3
  if (normal_mode && b1.wasPressed())
  {
    normal_mode = false;
    focus = "temp";

    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Temp Max: ");
    lcd.print(temp_max);
    lcd.print("C");
  }
  // SYSTEM REQUIREMENT 4
  else if (!normal_mode && focus == "temp" && b1.wasPressed())
  {
    focus = "hum";

    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Hum Max: ");
    lcd.print(hum_max);
    lcd.print("%");
  }
  // SYSTEM REQUIREMENT 5
  else if (!normal_mode && focus == "hum" && b1.wasPressed())
  {
    focus = "nothing";
    normal_mode = true;
    lcd.clear();
  }

  // SYSTEM REQUIREMENT 6
  if (!normal_mode && focus == "temp" && b2.wasPressed())
  {
    temp_max++;
    lcd.setCursor(10, 0);
    lcd.print(temp_max);
    lcd.print("C");
  }

  // SYSTEM REQUIREMENT 7
  if (!normal_mode && focus == "temp" && b3.wasPressed())
  {
    temp_max--;
    lcd.setCursor(10, 0);
    lcd.print(temp_max);
    lcd.print("C");
  }

  // SYSTEM REQUIREMENT 8
  if (!normal_mode && focus == "hum" && b2.wasPressed())
  {
    hum_max++;
    lcd.setCursor(9, 0);
    lcd.print(hum_max);
    lcd.print("%");
  }

  // SYSTEM REQUIREMENT 9
  if (!normal_mode && focus == "hum" && b3.wasPressed())
  {
    hum_max--;
    lcd.setCursor(9, 0);
    lcd.print(hum_max);
    lcd.print("%");
  }
  
}