#include "DHTesp.h"
#include <LiquidCrystal_I2C.h>
#define I2C_ADDR 0x27
#define LCD_COLUMNS 20
#define LCD_LINES 4
const int DHT_PIN = A0;
const int analogInPin = A0;
const int Relay = 2;
int sensorValue = 0;
int outputValue = 0;
DHTesp dhtSensor;
LiquidCrystal_I2C lcd(I2C_ADDR,LCD_COLUMNS, LCD_LINES);
void setup() {
Serial.begin(115200);
dhtSensor.setup(DHT_PIN,DHTesp::DHT22);
pinMode(Relay, OUTPUT);
lcd.init();
lcd.backlight();
}
void loop() {
sensorValue = analogRead(analogInPin);
TempAndHumidity data = dhtSensor.getTempAndHumidity();
outputValue = map(sensorValue, 0, 1023, 100, 0);
Serial.println("Temp: " + String(data.temperature,2) + "C");
Serial.println("Humidity: "+String(data.humidity,1) + "%");
Serial.print(outputValue);
Serial.println("%");
lcd.setCursor(0,0);
lcd.print("Temp : ");
lcd.print(String(data.temperature,2));
lcd.setCursor(0,1);
lcd.print("Humidity : ");
lcd.print(String(data.humidity,1));
lcd.setCursor(0,2);
lcd.print("Pump On :");
if (outputValue <= 70){
digitalWrite(Relay, HIGH);
}
else {
digitalWrite(Relay, LOW);
}
delay(1000);
}