#include <DHT.h>
#include <LiquidCrystal_I2C.h>
#define DHTPIN 2 // Pin where the DHT sensor is connected
#define DHTTYPE DHT22 // DHT 22 (AM2302)
#define RELAY_PIN 3 // Pin for the relay module
DHT dht(DHTPIN, DHTTYPE);
LiquidCrystal_I2C lcd(0x27, 16, 2); // Adjust the I2C address if necessary
void setup() {
pinMode(RELAY_PIN, OUTPUT); // Set the relay pin as an output
lcd.begin(16, 2); // Initialize the LCD with columns and rows
dht.begin(); // Initialize the DHT sensor
// Display project title
displayTitle("Greenhouse Climate Control ");
// Scroll names
scrollNames("Emmanuel & Benjamin");
}
void loop() {
float h = dht.readHumidity(); // Read humidity
float t = dht.readTemperature(); // Read temperature
lcd.setCursor(0, 0);
lcd.print("Temp: ");
lcd.print(t);
lcd.print(" C");
lcd.setCursor(0, 1);
lcd.print("Humidity: ");
lcd.print(h);
lcd.print(" %");
// Control relay based on temperature
if (t > 30) { // If temperature exceeds 30°C
digitalWrite(RELAY_PIN, HIGH); // Turn on the fan or heater
} else {
digitalWrite(RELAY_PIN, LOW); // Turn off the fan or heater
}
delay(2000); // Wait for 2 seconds before the next reading
}
void displayTitle(String title) {
lcd.clear(); // Clear the LCD
lcd.setCursor(0, 0); // Set cursor to the first row
lcd.print(title); // Display the title
delay(2000); // Display the title for 2 seconds
}
void scrollNames(String names) {
int length = names.length();
for (int position = 0; position < length + 16; position++) {
lcd.clear(); // Clear the LCD
lcd.setCursor(0, 0); // Set cursor to the first row
// Display scrolling text
if (position < length) {
lcd.print(names.substring(position)); // Show part of the string
} else {
lcd.print(" "); // Fill empty space with spaces
lcd.print(names.substring(position - 16)); // Show the rest of the string
}
delay(300); // Adjust delay for scrolling speed
}
}