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: **Sensor Control**
- - Source Code NOT compiled for: Arduino Uno
- - Source Code created on: 2024-12-21 07:44:32
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* Logic for dry box where pin 3 is used for dht11 to */
- /* maintain temperature between 25C-35C and humidity */
- /* between 35%-45%. The relay for bulb at pin 4, */
- /* temperature up and down switches on pin 5 and 6 */
- /* respectively and humidity up-down switches at 7 */
- /* lcd i2c */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- #include <DHT.h>
- #include <LiquidCrystal_I2C.h>
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- // Pin definitions
- #define DHTPIN 3 // DHT11 sensor pin
- #define DHTTYPE DHT11 // DHT 11
- #define RELAY_PIN 4 // Relay for bulb
- #define TEMP_UP_PIN 5 // Temperature up switch
- #define TEMP_DOWN_PIN 6 // Temperature down switch
- #define HUMIDITY_UP_PIN 7 // Humidity up switch
- // Create instances of DHT and LCD
- DHT dht(DHTPIN, DHTTYPE);
- LiquidCrystal_I2C lcd(0x27, 16, 2); // Adjust the address and size as needed
- void setup(void)
- {
- // Initialize the DHT sensor
- dht.begin();
- // Initialize the LCD
- lcd.begin(16, 2);
- lcd.backlight();
- // Set pin modes
- pinMode(RELAY_PIN, OUTPUT);
- pinMode(TEMP_UP_PIN, INPUT);
- pinMode(TEMP_DOWN_PIN, INPUT);
- pinMode(HUMIDITY_UP_PIN, INPUT);
- // Display initial message
- lcd.print("Dry Box Ready");
- }
- void loop(void)
- {
- // Read temperature and humidity
- float humidity = dht.readHumidity();
- float temperature = dht.readTemperature();
- // Check if any reads failed
- if (isnan(humidity) || isnan(temperature)) {
- lcd.print("Error reading");
- return;
- }
- // Display temperature and humidity on LCD
- lcd.setCursor(0, 1);
- lcd.print("T:");
- lcd.print(temperature);
- lcd.print(" H:");
- lcd.print(humidity);
- // Control relay based on temperature and humidity
- if (temperature < 25) {
- digitalWrite(RELAY_PIN, HIGH); // Turn on the bulb
- } else if (temperature > 35) {
- digitalWrite(RELAY_PIN, LOW); // Turn off the bulb
- }
- // Control temperature up/down switches
- if (digitalRead(TEMP_UP_PIN) == HIGH) {
- // Logic to increase temperature
- // (e.g., turn on heater)
- }
- if (digitalRead(TEMP_DOWN_PIN) == HIGH) {
- // Logic to decrease temperature
- // (e.g., turn on cooler)
- }
- // Control humidity up switch
- if (digitalRead(HUMIDITY_UP_PIN) == HIGH) {
- // Logic to increase humidity
- // (e.g., turn on humidifier)
- }
- delay(2000); // Wait before next reading
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement