#include <LiquidCrystal_I2C.h>
#include "DHTesp.h"
LiquidCrystal_I2C lcd(0x27, 16, 2);
int DHT_PIN = 13;
int pot1Pin = 33;
int pot2Pin = 34;
int ledR = 5;
int ledY = 4;
int ledG = 2;
DHTesp dhtSensor;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32!");
pinMode(pot1Pin, INPUT); // pot1 - Soil Moisture
pinMode(pot2Pin, INPUT); // pot2 - Rain Sensor
pinMode(ledR, OUTPUT); // Red LED
pinMode(ledY, OUTPUT); // Yellow LED
pinMode(ledG, OUTPUT); // Yellow LED
lcd.init();
lcd.backlight();
lcd.setCursor(2,0);
lcd.print("Hello Mutiara");
lcd.setCursor(0,1);
lcd.print("Ini essay no 4");
dhtSensor.setup(DHT_PIN, DHTesp::DHT22);
}
void loop() {
//==============Pot1==========================
int pot1Value=analogRead(pot1Pin);
Serial.print("pot1Value = ");
Serial.println(pot1Value);
//=============================================
//=============================================
if(pot1Value >= 4095)
{
Serial.println("No Rain ");
digitalWrite(ledG , 1);
digitalWrite(ledR , 0);
digitalWrite(ledY , 0);
}
else if (pot1Value >= 3001 && pot1Value <= 4094)
{
Serial.println("Drizziling ");
digitalWrite(ledY , 1);
digitalWrite(ledR , 0);
digitalWrite(ledG , 0);
}
else if (pot1Value <= 3000)
{
Serial.println("Heavy Rain ");
digitalWrite(ledR , 1);
digitalWrite(ledG , 0);
digitalWrite(ledY , 0);
}
//=============================================
//==============Pot==========================
int pot2Value=analogRead(pot2Pin);
Serial.print("pot2Value = ");
Serial.println(pot2Value);
//=============================================
//==========DHT22=======================================
TempAndHumidity data = dhtSensor.getTempAndHumidity();
Serial.println("Temp: " + String(data.temperature, 2) + "°C");
Serial.println("Humidity: " + String(data.humidity, 2) + "%");
Serial.println("---");
//======================================================
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Temp: " + String(data.temperature, 2) + " C");
lcd.setCursor(0,1);
lcd.print("Humidity: " + String(data.humidity, 2) + "%");
delay(2000); // Wait for a new reading from the sensor (DHT22 has ~0.5Hz sample rate)
}//