Advertisement
pleasedontcode

Humidity Control rev_01

Feb 24th, 2024
78
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-24 06:45:56
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* turn on  activebuzzer when humiditi hit below 70% */
  21. /****** SYSTEM REQUIREMENT 2 *****/
  22.     /* stop activebuzzer when humidity is above 90% */
  23. /****** END SYSTEM REQUIREMENTS *****/
  24.  
  25. /****** DEFINITION OF LIBRARIES *****/
  26. #include <DHT.h>    // Library for DHT sensors
  27.  
  28. /****** FUNCTION PROTOTYPES *****/
  29. void setup(void);
  30. void loop(void);
  31. void updateOutputs(void); // Function to update the output pins based on system requirements
  32.  
  33. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  34. const uint8_t humiditysensor_DHT22_DOUT_PIN_D2 = 2;
  35. const uint8_t humiditysensor_DHT22_DOUT_PIN_D3 = 3;
  36.  
  37. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  38. const uint8_t ultrasonichumid_ActiveBuzzer_output_PIN_D4 = 4;
  39. const uint8_t ultrasonichumid_ActiveBuzzer_output_PIN_D5 = 5;
  40.  
  41. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  42. /***** used to store raw data *****/
  43. bool ultrasonichumid_ActiveBuzzer_output_PIN_D4_rawData = 0;
  44. bool ultrasonichumid_ActiveBuzzer_output_PIN_D5_rawData = 0;
  45.  
  46. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  47. /***** used to store data after characteristic curve transformation *****/
  48. float ultrasonichumid_ActiveBuzzer_output_PIN_D4_phyData = 0.0;
  49. float ultrasonichumid_ActiveBuzzer_output_PIN_D5_phyData = 0.0;
  50.  
  51. /****** DEFINITION OF LIBRARIES CLASS INSTANCES *****/
  52. DHT dht(humiditysensor_DHT22_DOUT_PIN_D2, DHT22);    // Create a DHT object
  53.  
  54. void setup(void)
  55. {
  56.     pinMode(humiditysensor_DHT22_DOUT_PIN_D2, INPUT_PULLUP);
  57.     pinMode(humiditysensor_DHT22_DOUT_PIN_D3, INPUT_PULLUP);
  58.  
  59.     pinMode(ultrasonichumid_ActiveBuzzer_output_PIN_D4, OUTPUT);
  60.     pinMode(ultrasonichumid_ActiveBuzzer_output_PIN_D5, OUTPUT);
  61.  
  62.     dht.begin();    // Initialize the DHT sensor
  63.  
  64.     Serial.begin(9600);    // Start serial communication
  65.     Serial.println(F("DHTxx test!"));    // Print initialization message
  66. }
  67.  
  68. void loop(void)
  69. {
  70.     updateOutputs();    // Refresh output data
  71.  
  72.     delay(2000);    // Wait for 2 seconds
  73.  
  74.     float h = dht.readHumidity();    // Read humidity value from DHT sensor
  75.     float t = dht.readTemperature();    // Read temperature value from DHT sensor
  76.     float f = dht.readTemperature(true);    // Read temperature value in Fahrenheit from DHT sensor
  77.  
  78.     if (isnan(h) || isnan(t) || isnan(f))
  79.     {
  80.         Serial.println(F("Failed to read from DHT sensor!"));
  81.         return;
  82.     }
  83.  
  84.     float hif = dht.computeHeatIndex(f, h);    // Calculate heat index in Fahrenheit
  85.     float hic = dht.computeHeatIndex(t, h, false);    // Calculate heat index in Celsius
  86.  
  87.     Serial.print(F("Humidity: "));
  88.     Serial.print(h);
  89.     Serial.print(F("%  Temperature: "));
  90.     Serial.print(t);
  91.     Serial.print(F("°C "));
  92.     Serial.print(f);
  93.     Serial.print(F("°F  Heat index: "));
  94.     Serial.print(hic);
  95.     Serial.print(F("°C "));
  96.     Serial.print(hif);
  97.     Serial.println(F("°F"));
  98.  
  99.     // Check system requirements and update outputs accordingly
  100.     if (h < 70) {
  101.         ultrasonichumid_ActiveBuzzer_output_PIN_D4_rawData = HIGH; // Turn on active buzzer
  102.     } else if (h > 90) {
  103.         ultrasonichumid_ActiveBuzzer_output_PIN_D4_rawData = LOW; // Turn off active buzzer
  104.     }
  105. }
  106.  
  107. void updateOutputs()
  108. {
  109.     digitalWrite(ultrasonichumid_ActiveBuzzer_output_PIN_D4, ultrasonichumid_ActiveBuzzer_output_PIN_D4_rawData);
  110.     digitalWrite(ultrasonichumid_ActiveBuzzer_output_PIN_D5, ultrasonichumid_ActiveBuzzer_output_PIN_D5_rawData);
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement