Advertisement
pleasedontcode

**Sensor Control** rev_01

Dec 21st, 2024
24
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: **Sensor Control**
  13.     - Source Code NOT compiled for: Arduino Uno
  14.     - Source Code created on: 2024-12-21 07:44:32
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Logic for dry box where pin 3 is used for dht11 to */
  21.     /* maintain temperature between 25C-35C and humidity */
  22.     /* between 35%-45%. The relay for bulb at pin 4, */
  23.     /* temperature up and down switches on pin 5 and 6 */
  24.     /* respectively and humidity up-down switches at 7 */
  25.     /* lcd i2c */
  26. /****** END SYSTEM REQUIREMENTS *****/
  27.  
  28. /* START CODE */
  29.  
  30. /****** DEFINITION OF LIBRARIES *****/
  31. #include <DHT.h>
  32. #include <LiquidCrystal_I2C.h>
  33.  
  34. /****** FUNCTION PROTOTYPES *****/
  35. void setup(void);
  36. void loop(void);
  37.  
  38. // Pin definitions
  39. #define DHTPIN 3          // DHT11 sensor pin
  40. #define DHTTYPE DHT11     // DHT 11
  41. #define RELAY_PIN 4       // Relay for bulb
  42. #define TEMP_UP_PIN 5     // Temperature up switch
  43. #define TEMP_DOWN_PIN 6   // Temperature down switch
  44. #define HUMIDITY_UP_PIN 7 // Humidity up switch
  45.  
  46. // Create instances of DHT and LCD
  47. DHT dht(DHTPIN, DHTTYPE);
  48. LiquidCrystal_I2C lcd(0x27, 16, 2); // Adjust the address and size as needed
  49.  
  50. void setup(void)
  51. {
  52.     // Initialize the DHT sensor
  53.     dht.begin();
  54.    
  55.     // Initialize the LCD
  56.     lcd.begin(16, 2);
  57.     lcd.backlight();
  58.    
  59.     // Set pin modes
  60.     pinMode(RELAY_PIN, OUTPUT);
  61.     pinMode(TEMP_UP_PIN, INPUT);
  62.     pinMode(TEMP_DOWN_PIN, INPUT);
  63.     pinMode(HUMIDITY_UP_PIN, INPUT);
  64.    
  65.     // Display initial message
  66.     lcd.print("Dry Box Ready");
  67. }
  68.  
  69. void loop(void)
  70. {
  71.     // Read temperature and humidity
  72.     float humidity = dht.readHumidity();
  73.     float temperature = dht.readTemperature();
  74.  
  75.     // Check if any reads failed
  76.     if (isnan(humidity) || isnan(temperature)) {
  77.         lcd.print("Error reading");
  78.         return;
  79.     }
  80.  
  81.     // Display temperature and humidity on LCD
  82.     lcd.setCursor(0, 1);
  83.     lcd.print("T:");
  84.     lcd.print(temperature);
  85.     lcd.print(" H:");
  86.     lcd.print(humidity);
  87.  
  88.     // Control relay based on temperature and humidity
  89.     if (temperature < 25) {
  90.         digitalWrite(RELAY_PIN, HIGH); // Turn on the bulb
  91.     } else if (temperature > 35) {
  92.         digitalWrite(RELAY_PIN, LOW); // Turn off the bulb
  93.     }
  94.  
  95.     // Control temperature up/down switches
  96.     if (digitalRead(TEMP_UP_PIN) == HIGH) {
  97.         // Logic to increase temperature
  98.         // (e.g., turn on heater)
  99.     }
  100.     if (digitalRead(TEMP_DOWN_PIN) == HIGH) {
  101.         // Logic to decrease temperature
  102.         // (e.g., turn on cooler)
  103.     }
  104.  
  105.     // Control humidity up switch
  106.     if (digitalRead(HUMIDITY_UP_PIN) == HIGH) {
  107.         // Logic to increase humidity
  108.         // (e.g., turn on humidifier)
  109.     }
  110.  
  111.     delay(2000); // Wait before next reading
  112. }
  113.  
  114. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement