#define BLYNK_TEMPLATE_ID "TMPL6W-sJUT33"
#define BLYNK_TEMPLATE_NAME "Proyek Mela"
#define BLYNK_AUTH_TOKEN "V-hOiWZyaFvWPWT0OINED2j71tkyyMSt"
#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <HTTPClient.h>
#include <BlynkSimpleEsp32.h>
const int pot1 = 35;
const int pot2 = 34 ;
const int relayPin = 19 ;
const int saklar = 4;
int sw1 = 0;
int sw2 = 0;
int volt = 0;
int arus = 0;
int daya = 0;
char auth[] = BLYNK_AUTH_TOKEN;
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "Wokwi-GUEST"; //nama hotspot yang digunakan
char pass[] = ""; //password hotspot yang digunakan
BLYNK_WRITE(V0){
sw2 = digitalRead(saklar);
int pinvalue = param.asInt();
if (pinvalue == 1 && sw2 == LOW){
digitalWrite(relayPin, HIGH);
}else{
digitalWrite(relayPin, LOW);
}
volt=analogRead(pot1);
arus=analogRead(pot2);
sw1 = digitalRead(saklar);
if (sw1 == LOW) {
if(volt > 1800 && volt < 2300 ){
digitalWrite(relayPin, HIGH);
Serial.println("Tegangan Normal");
}else{
digitalWrite(relayPin, LOW);
Serial.println("Tegangan Tidak Normal");
pinvalue = 0;
volt =0;
arus = 0;
}
}
else{
digitalWrite(relayPin, LOW);
Serial.println("Saklar dimatikan");
volt =0;
arus = 0;
}
daya =volt/100 * arus/90;
int arus1 = arus /90;
int volt1 = volt/100;
Blynk.virtualWrite(V1, arus1);
Blynk.virtualWrite(V2, volt1);
Blynk.virtualWrite(V3, daya);
}
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32!");
pinMode(relayPin, OUTPUT);
pinMode(saklar, INPUT_PULLUP);
Blynk.begin(auth, ssid, pass);
}
void loop() {
// put your main code here, to run repeatedly:
// this speeds up the simulation
daya =volt/100 * arus/90;
Serial.print("Volt = ");
Serial.println(volt/100);
Serial.print("Arus = ");
Serial.println(arus/90);
Serial.print("Daya nya sebesar ");
Serial.println(daya);
Blynk.run();
}