#define BLYNK_TEMPLATE_ID "TMPL661DrY7LZ"
#define BLYNK_TEMPLATE_NAME "Penyiraman Tanaman Otomatis"
#define BLYNK_AUTH_TOKEN "qjeS76YO1684Cx2nEcklqnm2I3W5x9yU"
#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <BlynkSimpleEsp32.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "HAN";
char pass[] = "Pranandipt4";
BlynkTimer timer;
const int AirValue = 2650;
const int WaterValue = 980;
int soilMoistureValue = 0;
int soilmoist = 0;
void read_SoilMoist() {
soilMoistureValue = analogRead(A6);
soilmoist= map(soilMoistureValue, AirValue, WaterValue, 0, 100);
if(soilmoist >= 100)
{
soilmoist=100;
}
else if(soilmoist <=0)
{
soilmoist=0;
}
lcd.setCursor(0,0);
lcd.print("Soil Humid =");
lcd.setCursor(13,0);
lcd.print(soilmoist);
lcd.print("% ");
}
void setup() {
// put your setup code here, to run once:
//Serial.begin(115200);
//Serial.println("Hello, ESP32!");
Serial.begin(9600);
Blynk.begin(auth, ssid, pass, "blynk.cloud", 80);
lcd.begin();
lcd.backlight();
}
void loop() {
// put your main code here, to run repeatedly:
//delay(10); // this speeds up the simulation
Blynk.run();
timer.run();
read_SoilMoist();
Blynk.virtualWrite(V0, soilmoist);
delay(1000);
}