Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* 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: Humidity Control
- - Source Code compiled for: Arduino Uno
- - Source Code created on: 2024-02-24 06:45:56
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* turn on activebuzzer when humiditi hit below 70% */
- /****** SYSTEM REQUIREMENT 2 *****/
- /* stop activebuzzer when humidity is above 90% */
- /****** END SYSTEM REQUIREMENTS *****/
- /****** DEFINITION OF LIBRARIES *****/
- #include <DHT.h> // Library for DHT sensors
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- void updateOutputs(void); // Function to update the output pins based on system requirements
- /***** DEFINITION OF DIGITAL INPUT PINS *****/
- const uint8_t humiditysensor_DHT22_DOUT_PIN_D2 = 2;
- const uint8_t humiditysensor_DHT22_DOUT_PIN_D3 = 3;
- /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
- const uint8_t ultrasonichumid_ActiveBuzzer_output_PIN_D4 = 4;
- const uint8_t ultrasonichumid_ActiveBuzzer_output_PIN_D5 = 5;
- /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
- /***** used to store raw data *****/
- bool ultrasonichumid_ActiveBuzzer_output_PIN_D4_rawData = 0;
- bool ultrasonichumid_ActiveBuzzer_output_PIN_D5_rawData = 0;
- /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
- /***** used to store data after characteristic curve transformation *****/
- float ultrasonichumid_ActiveBuzzer_output_PIN_D4_phyData = 0.0;
- float ultrasonichumid_ActiveBuzzer_output_PIN_D5_phyData = 0.0;
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES *****/
- DHT dht(humiditysensor_DHT22_DOUT_PIN_D2, DHT22); // Create a DHT object
- void setup(void)
- {
- pinMode(humiditysensor_DHT22_DOUT_PIN_D2, INPUT_PULLUP);
- pinMode(humiditysensor_DHT22_DOUT_PIN_D3, INPUT_PULLUP);
- pinMode(ultrasonichumid_ActiveBuzzer_output_PIN_D4, OUTPUT);
- pinMode(ultrasonichumid_ActiveBuzzer_output_PIN_D5, OUTPUT);
- dht.begin(); // Initialize the DHT sensor
- Serial.begin(9600); // Start serial communication
- Serial.println(F("DHTxx test!")); // Print initialization message
- }
- void loop(void)
- {
- updateOutputs(); // Refresh output data
- delay(2000); // Wait for 2 seconds
- float h = dht.readHumidity(); // Read humidity value from DHT sensor
- float t = dht.readTemperature(); // Read temperature value from DHT sensor
- float f = dht.readTemperature(true); // Read temperature value in Fahrenheit from DHT sensor
- if (isnan(h) || isnan(t) || isnan(f))
- {
- Serial.println(F("Failed to read from DHT sensor!"));
- return;
- }
- float hif = dht.computeHeatIndex(f, h); // Calculate heat index in Fahrenheit
- float hic = dht.computeHeatIndex(t, h, false); // Calculate heat index in Celsius
- Serial.print(F("Humidity: "));
- Serial.print(h);
- Serial.print(F("% Temperature: "));
- Serial.print(t);
- Serial.print(F("°C "));
- Serial.print(f);
- Serial.print(F("°F Heat index: "));
- Serial.print(hic);
- Serial.print(F("°C "));
- Serial.print(hif);
- Serial.println(F("°F"));
- // Check system requirements and update outputs accordingly
- if (h < 70) {
- ultrasonichumid_ActiveBuzzer_output_PIN_D4_rawData = HIGH; // Turn on active buzzer
- } else if (h > 90) {
- ultrasonichumid_ActiveBuzzer_output_PIN_D4_rawData = LOW; // Turn off active buzzer
- }
- }
- void updateOutputs()
- {
- digitalWrite(ultrasonichumid_ActiveBuzzer_output_PIN_D4, ultrasonichumid_ActiveBuzzer_output_PIN_D4_rawData);
- digitalWrite(ultrasonichumid_ActiveBuzzer_output_PIN_D5, ultrasonichumid_ActiveBuzzer_output_PIN_D5_rawData);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement