#include <LiquidCrystal_I2C.h>
#include <Wire.h>
#define TRIG_PIN 12
#define ECHO_PIN 13
#define BLYNK_TEMPLATE_ID "TMPLl4AsyIBs"
#define BLYNK_DEVICE_NAME "TES LED2"
#define BLYNK_AUTH_TOKEN "R6HA67mkrj7JmYihEU7d8lInKlpTd2Lt"
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "Wokwi-GUEST";
char pass[] = "";
long duration, inches;
int set_val,percentage;
int JetPump = 14;
int ledRed = 23;
int mode;
LiquidCrystal_I2C lcd(0x27, 20, 4);
BLYNK_WRITE(V0)
{
int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
if(mode==0){digitalWrite(14,pinValue);
digitalWrite(ledRed, LOW);
lcd.setCursor(4, 1);
lcd.print(percentage);
lcd.print("% ");
}
// process received value
}
BlynkTimer timer;
void myTimerEvent()
{
duration = pulseIn(ECHO_PIN, HIGH);
lcd.print(percentage);
lcd.print("% ");
}
BLYNK_WRITE(V1)
{
int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
mode=pinValue;
// process received value
}
void setup() {
//Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(ledRed, OUTPUT);
pinMode(JetPump, OUTPUT);
pinMode(TRIG_PIN, OUTPUT);
pinMode(ECHO_PIN, INPUT);
if(set_val>150)set_val=150;
lcd.init();
lcd.backlight();
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" Water Pump ");
lcd.setCursor(0, 1);
lcd.print(" Otomatis ");
delay(2000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" Pendeteksi ");
lcd.setCursor(0, 1);
lcd.print(" Ketinggian Air ");
delay(2000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" Dirancang Oleh ");
lcd.setCursor(0, 1);
lcd.print(" Kelompok 19 ");
delay(2000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" System Ready ");
delay(500);
lcd.clear();
Serial.begin(115200);
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
}
void loop() {
timer.run();
Blynk.run();
if(digitalRead)
// put your main code here, to run repeatedly:
digitalWrite(TRIG_PIN, HIGH);
delayMicroseconds(10);
digitalWrite(TRIG_PIN, LOW);
duration = pulseIn(ECHO_PIN, HIGH);
percentage=(set_val-inches)*100/set_val;
digitalWrite(ledRed, LOW);
lcd.setCursor(0, 1);
lcd.print(percentage);
lcd.print("% ");
if(percentage<0)percentage=0;
lcd.setCursor(1, 0);
lcd.print(percentage);
lcd.print("% ");
if (percentage >99)
digitalWrite(ledRed, HIGH);
lcd.print(" AIR TERSEDIA ");
lcd.setCursor(1, 1);
lcd.print(percentage);
lcd.print("% ");
if (percentage <10)
digitalWrite(ledRed, LOW);
lcd.print(" AIR HABIS");
lcd.setCursor(1, 1);
lcd.print(percentage);
lcd.print("% ");
}