#include <LiquidCrystal_I2C.h>
#include <Keypad.h>
#include <DHT.h>

#define dhtpin 9
#define DHTTYPE DHT22

#define light 10
#define pump 11

LiquidCrystal_I2C lcd(0x27, 16, 2);

DHT dht(dhtpin, DHTTYPE);

const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
char keys[ROWS][COLS] = {
  {'1','2','3', 'A'},
  {'4','5','6', 'B'},
  {'7','8','9', 'C'},
  {'*','0','#', 'D'}
};
byte rowPins[ROWS] = {8, 7, 6, 5}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {4, 3, 2, 1}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS);

float tmp = 0.0;
float humi = 0.0;

float maxTmp = 28.0;
float minTmp = 21.0;

float maxHumi = 70.0;
float minHumi = 30.0;


void setup() {
  lcd.init();
  lcd.backlight();
  
  dht.begin();

  pinMode(light, OUTPUT);
  pinMode(pump, OUTPUT);

  lcd.clear();
  lcd.print("Welcome");
  delay(2000);

}


void loop() {
  float tmp = dht.readTemperature();
  float humi = dht.readHumidity();
  if (isnan(humi) || isnan(tmp)) {
       lcd.clear();
       lcd.setCursor(0, 0);
       lcd.print("DHT Error!"); 
     }

     lcd.clear();
     lcd.setCursor(0, 0);
     lcd.print("Humi: ");
     lcd.print(humi);
     lcd.print(" %");
     lcd.setCursor(0, 1);
     lcd.print("Temp: ");
     lcd.print(tmp);
     lcd.print(" C");
     delay(1000);

  if(tmp >= maxTmp){
    digitalWrite(pump, HIGH);
    delay(10000);

    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Water Pump Actived!!");
  } else {
    digitalWrite(pump, LOW);
  }
  
  if(tmp <= minTmp ){
      digitalWrite(light, HIGH);
      delay(15000);

      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("Light On!!!");
     } else {
      digitalWrite(light, LOW);
     }
}
NOCOMNCVCCGNDINLED1PWRRelay Module
NOCOMNCVCCGNDINLED1PWRRelay Module