Advertisement
pleasedontcode

Humidity Control rev_04

Feb 29th, 2024
77
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: Humidity Control
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2024-02-29 06:09:53
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* turn on  ULTRASONIOC when humiditi hit below 70% */
  21. /****** SYSTEM REQUIREMENT 2 *****/
  22.     /* stop ULTRASONIC when humidity is above 90% */
  23. /****** END SYSTEM REQUIREMENTS *****/
  24.  
  25. /****** DEFINITION OF LIBRARIES *****/
  26. #include <BME280.h> //https://github.com/Zanduino/BME280
  27. #include <DHT.h>    //https://github.com/adafruit/DHT-sensor-library
  28.  
  29. /****** FUNCTION PROTOTYPES *****/
  30. void setup(void);
  31. void loop(void);
  32. void updateOutputs(void);
  33.  
  34. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  35. const uint8_t humiditysensor_DHT22_DOUT_PIN_D2 = 2;
  36. const uint8_t humiditysensor_DHT22_DOUT_PIN_D3 = 3;
  37.  
  38. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  39. const uint8_t ULTRASONIC_PIN_D4 = 4;
  40.  
  41. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  42. /***** used to store raw data *****/
  43. bool ULTRASONIC_PIN_D4_rawData = 0;
  44.  
  45. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  46. /***** used to store data after characteristic curve transformation *****/
  47. float ULTRASONIC_PIN_D4_phyData = 0.0;
  48.  
  49. /****** DEFINITION OF LIBRARIES CLASS INSTANCES *****/
  50. DHT dht(humiditysensor_DHT22_DOUT_PIN_D2, DHT22);
  51. BME280_Class bme280;
  52.  
  53. void setup(void)
  54. {
  55.   // put your setup code here, to run once:
  56.  
  57.   pinMode(humiditysensor_DHT22_DOUT_PIN_D2, INPUT_PULLUP);
  58.   pinMode(humiditysensor_DHT22_DOUT_PIN_D3, INPUT_PULLUP);
  59.  
  60.   pinMode(ULTRASONIC_PIN_D4, OUTPUT);
  61.  
  62.   dht.begin();
  63.   bme280.begin();
  64. }
  65.  
  66. void loop(void)
  67. {
  68.   // put your main code here, to run repeatedly:
  69.  
  70.   float humidity = dht.readHumidity(); // Read humidity value
  71.  
  72.   if (humidity < 70)
  73.   {
  74.     ULTRASONIC_PIN_D4_rawData = 1; // Turn on ULTRASONIC
  75.   }
  76.   else if (humidity > 90)
  77.   {
  78.     ULTRASONIC_PIN_D4_rawData = 0; // Turn off ULTRASONIC
  79.   }
  80.  
  81.   updateOutputs(); // Refresh output data
  82. }
  83.  
  84. void updateOutputs()
  85. {
  86.   digitalWrite(ULTRASONIC_PIN_D4, ULTRASONIC_PIN_D4_rawData);
  87. }
  88.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement