Alat Pendeteksi Arus Bocor (Deteksi Arus Bocor) ESP32 Sensor PZEM-004t dan IOT Thingspeak
Pada kesempatan kali ini saya akan menjelaskan mengenai bagimana cara membuat sebuah alat yang dapat digunakan untuk mendeteksi kebocoran arus, dikarenakan kebocoran arus sangat berbahaya dan merugikan, salah satunya yaitu dapat mengakibatkan biaya jadi besar dan jika arus bocornya lumayan besar maka akan mengakibatkan kesetrum jika terkena aliran arus tersebut, untuk itu perlu dipakaikan alat untuk memonitornya. untuk lebih jelasnya berikut adalah koding dan skemanya.
a. Komponen dan Skema
1. ESP32
2. PZEM-004t
3. LCD 2x4 I2C
4. Buzzer
5. Led
6. SSR DC AC
7. Push Button
b. Program Arduino IDE
#include <Wire.h>
#include <HardwareSerial.h>
#include <WiFi.h>
#include <WiFiClient.h>
#include <PZEM004Tv30.h>
#include <LiquidCrystal_I2C.h>
#define RXD2 16
#define TXD2 17
LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27 for a 20 chars and 4 line display
PZEM004Tv30 pzem(&Serial); //(RX,TX) connect to TX,RX of PZEM
PZEM004Tv30 pzem2(&Serial2); //(RX,TX) connect to TX,RX of PZEM
float voltage;
float current1;
float power;
float energy;
float biaya;
float voltage2;
float current2;
float energy2;
int buzzer = 19;
int btreset = 35;
int ledmerah = 26;
int ledhijau = 25;
int ssr = 27;
float selisih;
int btresetx;
WiFiClient client;
// ThingSpeak Settings
String apiKey = "GHJ754DGHBN87GJ7";
const char *ssid = "hotspothpku";
const char *pass = "123456789";
const char* server = "api.thingspeak.com";
const char* resource = "/update?api_key=";
void setup() {
//setting ke online
Serial.println("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED){\
delay(200);
Serial.println(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.begin(9600);
Serial2.begin(9600);
lcd.begin();
lcd.clear();
lcd.noCursor();
pinMode(buzzer,OUTPUT);
pinMode(btreset,INPUT);
pinMode(ledmerah,OUTPUT);
pinMode(ledhijau,OUTPUT);
pinMode(ssr,OUTPUT);
digitalWrite(ssr,HIGH); //LITRIK AC NYALA
}
void loop() {
btresetx = digitalRead(btreset);
if(btresetx == 0){
digitalWrite(ssr,HIGH); //LITRIK AC NYALA
delay(1000);
}
voltage = pzem.voltage();
current1 = pzem.current();
energy = pzem.energy();
power = pzem.power();
biaya = energy * 1350;
current2 = pzem2.current();
if(current1 == current2){
digitalWrite(buzzer,HIGH);
digitalWrite(ledmerah,LOW);
digitalWrite(ledhijau,HIGH);
digitalWrite(ssr,HIGH);
}
if(current1 > current2){
selisih = current1 - current2;
/*
if((selisih > 0.00)&&(selisih < 0.01 )){
digitalWrite(buzzer,HIGH);
digitalWrite(ledmerah,HIGH);
digitalWrite(ledhijau,LOW);
digitalWrite(ssr,HIGH);
}
*/
if(selisih >= 0){
digitalWrite(buzzer,LOW);
digitalWrite(ledmerah,HIGH);
digitalWrite(ledhijau,LOW);
digitalWrite(ssr,LOW);
lcd.clear();
padam();
}
}
if(current1 < current2){
selisih = current2 - current1;
/*
if((selisih > 0.00)&&(selisih < 0.01 )){
digitalWrite(buzzer,HIGH);
digitalWrite(ledmerah,HIGH);
digitalWrite(ledhijau,LOW);
digitalWrite(ssr,HIGH);
}
*/
if(selisih >= 0){
digitalWrite(buzzer,LOW);
digitalWrite(ledmerah,HIGH);
digitalWrite(ledhijau,LOW);
digitalWrite(ssr,LOW);
lcd.clear();
padam();
}
}
lcd.setCursor(0,0);
lcd.print("V:");
lcd.print(voltage);
lcd.print(" ");
lcd.setCursor(0,1);
lcd.print("I1:");
lcd.print(current1);
lcd.print(" I2:");
lcd.print(current2);
lcd.print(" ");
lcd.setCursor(0,2);
lcd.print("Kwh:");
lcd.print(energy);
lcd.print(" Rp.");
lcd.print(biaya);
lcd.print(" ");
lcd.setCursor(0,3);
lcd.print("B:");
lcd.print(selisih);
lcd.print(" ");
lcd.print("P: ");
lcd.print(power);
lcd.print(" ");
kirim();
delay(1000);
}
void kirim(){
if (client.connect(server,80)) // "184.106.153.149" or api.thingspeak.com
{
String postStr = apiKey;
postStr +="&field1=";
postStr += String(voltage);
postStr += "\r\n\r\n";
client.print(String("GET ") + resource + apiKey + "&field1=" + voltage + "&field2=" + current1 + "&field3=" + current2 + "&field4=" + energy + "&field5=" + biaya + "&field6=" + selisih + "&field7=" + power +" HTTP/1.1\r\n" + "Host: " + server + "\r\n" + "Connection: close\r\n\r\n");
client.print("Host: api.thingspeak.com\n");
client.print("Connection: close\n");
client.print("X-THINGSPEAKAPIKEY: "+apiKey+"\n");
client.print("Content-Type: application/x-www-form-urlencoded\n");
client.print("Content-Length: ");
client.print(postStr.length());
client.print("\n\n");
client.print(postStr);
Serial.println(". Send to Thingspeak.");
}
client.stop();
Serial.println("Waiting...");
// thingspeak needs minimum 15 sec delay between updates, i've set it to 30 seconds
delay(10000);
}
void padam(){
lcd.setCursor(0,1);
lcd.print("TERJADI ARUS BOCOR");
digitalWrite(buzzer,LOW);
digitalWrite(buzzer,LOW);
digitalWrite(ledmerah,HIGH);
digitalWrite(ledhijau,LOW);
digitalWrite(ssr,LOW);
btresetx = digitalRead(btreset);
if(btresetx == 0){
lcd.clear();
delay(1000);
digitalWrite(ssr,HIGH); //LITRIK AC NYALA
digitalWrite(buzzer,HIGH);
delay(1000);
return;
}
padam();
}
c. VIDEO HASILNYA
No comments:
Post a Comment