#include <LiquidCrystal_I2C.h>
#include <DHT.h>
#define DHTPIN 2 // Pin where the DHT sensor is connected
#define DHTTYPE DHT22
int relayPin=8; // DHT 22 (AM2302) sensor type
DHT dht(DHTPIN, DHTTYPE);
LiquidCrystal_I2C lcd(0x27, 16, 2); // I2C address 0x27, 16 column and 2 rows
void setup() {
lcd.begin(16, 2);
dht.begin();
pinMode(relayPin, OUTPUT);
digitalWrite(relayPin, LOW);
Serial.begin(9600);
dht.begin();
}
void loop() {
// Wait a few seconds between measurements
delay(2000);
// Reading temperature or humidity takes about 250 milliseconds!
float humidity = dht.readHumidity();
// Check if any reads failed and exit early (to try again).
if (isnan(humidity)) {
lcd.print("Failed to read");
return;
}
// Print humidity on the LCD
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Humidity: ");
lcd.print(humidity);
lcd.print("%");
if(humidity<10){
digitalWrite(relayPin,HIGH);
Serial.print("Need water \n");
}
else{
digitalWrite(relayPin,LOW);
Serial.print("Good condition \n");
}
}