CCCPaste

Climate Control rev_01

/********* 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: Climate Control
	- Source Code compiled for: Arduino Uno
	- Source Code created on: 2023-12-25 08:20:12

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

/****** SYSTEM REQUIREMENTS *****/
/****** SYSTEM REQUIREMENT 1 *****/
	/* Mobile phone application for:  “Control the */
	/* operation of home ventilation system ( using motor */
	/* + fan)” */
/****** END SYSTEM REQUIREMENTS *****/

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

// Definition of digital input pins
const uint8_t Button1_PushButton_PIN_D2 = 2;

// Definition of digital output pins for motor and fan
const uint8_t Motor_PIN_D3 = 3;
const uint8_t Fan_PIN_D4 = 4;

// Instance of the button
EasyButton button(Button1_PushButton_PIN_D2);

// Instance of climate sensor
ForcedBME280Float climateSensor;

void setup()
{
  // Initialize Serial for debugging purposes.
  Serial.begin(115200);

  // Set motor and fan pins as output
  pinMode(Motor_PIN_D3, OUTPUT);
  pinMode(Fan_PIN_D4, OUTPUT);

  // Initialize the button
  button.begin();

  // Initialize the climate sensor
  Wire.begin();
  while (climateSensor.begin())
  {
    delay(1000);
  }
}

void loop()
{
  // Read the button state
  button.read();

  // Toggle the motor and fan based on button state
  if (button.isPressed())
  {
    digitalWrite(Motor_PIN_D3, HIGH);
    digitalWrite(Fan_PIN_D4, HIGH);
  }
  else
  {
    digitalWrite(Motor_PIN_D3, LOW);
    digitalWrite(Fan_PIN_D4, LOW);
  }

  // Climate sensor measurements
  climateSensor.takeForcedMeasurement();
  float temperature = climateSensor.getTemperatureCelsius();
  float humidity = climateSensor.getRelativeHumidityAsFloat();
  float pressure = climateSensor.getPressure();

  // Print climate sensor measurements
  Serial.print("Temperature: ");
  Serial.print(temperature);
  Serial.println(" °C");

  Serial.print("Humidity: ");
  Serial.print(humidity);
  Serial.println(" %");

  Serial.print("Pressure: ");
  Serial.print(pressure);
  Serial.println(" hPa");

  delay(1000);
}