Advertisement
pleasedontcode

Climate Control rev_01

Dec 25th, 2023
99
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: Climate Control
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2023-12-25 08:20:12
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Mobile phone application for:  “Control the */
  21.     /* operation of home ventilation system ( using motor */
  22.     /* + fan)” */
  23. /****** END SYSTEM REQUIREMENTS *****/
  24.  
  25. /****** DEFINITION OF LIBRARIES *****/
  26. #include <Arduino.h>
  27. #include <EasyButton.h>
  28. #include <Wire.h>
  29. #include <forcedBMX280.h>
  30.  
  31. // Definition of digital input pins
  32. const uint8_t Button1_PushButton_PIN_D2 = 2;
  33.  
  34. // Definition of digital output pins for motor and fan
  35. const uint8_t Motor_PIN_D3 = 3;
  36. const uint8_t Fan_PIN_D4 = 4;
  37.  
  38. // Instance of the button
  39. EasyButton button(Button1_PushButton_PIN_D2);
  40.  
  41. // Instance of climate sensor
  42. ForcedBME280Float climateSensor;
  43.  
  44. void setup()
  45. {
  46.   // Initialize Serial for debugging purposes.
  47.   Serial.begin(115200);
  48.  
  49.   // Set motor and fan pins as output
  50.   pinMode(Motor_PIN_D3, OUTPUT);
  51.   pinMode(Fan_PIN_D4, OUTPUT);
  52.  
  53.   // Initialize the button
  54.   button.begin();
  55.  
  56.   // Initialize the climate sensor
  57.   Wire.begin();
  58.   while (climateSensor.begin())
  59.   {
  60.     delay(1000);
  61.   }
  62. }
  63.  
  64. void loop()
  65. {
  66.   // Read the button state
  67.   button.read();
  68.  
  69.   // Toggle the motor and fan based on button state
  70.   if (button.isPressed())
  71.   {
  72.     digitalWrite(Motor_PIN_D3, HIGH);
  73.     digitalWrite(Fan_PIN_D4, HIGH);
  74.   }
  75.   else
  76.   {
  77.     digitalWrite(Motor_PIN_D3, LOW);
  78.     digitalWrite(Fan_PIN_D4, LOW);
  79.   }
  80.  
  81.   // Climate sensor measurements
  82.   climateSensor.takeForcedMeasurement();
  83.   float temperature = climateSensor.getTemperatureCelsius();
  84.   float humidity = climateSensor.getRelativeHumidityAsFloat();
  85.   float pressure = climateSensor.getPressure();
  86.  
  87.   // Print climate sensor measurements
  88.   Serial.print("Temperature: ");
  89.   Serial.print(temperature);
  90.   Serial.println(" °C");
  91.  
  92.   Serial.print("Humidity: ");
  93.   Serial.print(humidity);
  94.   Serial.println(" %");
  95.  
  96.   Serial.print("Pressure: ");
  97.   Serial.print(pressure);
  98.   Serial.println(" hPa");
  99.  
  100.   delay(1000);
  101. }
  102.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement