Pada kesempatan kali ini saya akan mmenjelaskan mengenai sebuah alat yang berfungsi untuk monitor KWH listrik dengan interface menggunakan Blynk secara online IOT. keuntungan menggunakan Blynk ini yaitu bisa dimonitor secara jarak jauh asalkan kedua device terkoneksi ke internet. alat ini juga menampilkan biaya yang harus diibayar oleh pengguna. untuk lebih jelasnya berikut adalah komponen dan programnya.
a. Wemos D1 Mini
b. Arduno Nano
c. Sensor PZEM-004t
d. Lcd 16x2 + I2C
e. Program Arduino IDE
#include <PZEM004Tv30.h>
#include <Wire.h> // i2C Conection Library
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);
PZEM004Tv30 pzem(11, 12);
void setup() {
lcd.begin();
lcd.noCursor();
lcd.clear();
Serial.begin(9600);
}
void loop() {
float voltage = pzem.voltage();
int tegangan = voltage * 100;
float current = pzem.current();
int arus = current * 100;
float energy = pzem.energy();
int energyx = energy * 100;
float biaya = energy * 1352;
int biayax = biaya * 100;
Serial.print("*");
Serial.print(tegangan);
Serial.print(",");
Serial.print(arus);
Serial.print(",");
Serial.print(energyx);
Serial.print(",");
Serial.print(biayax);
Serial.println("#");
lcd.setCursor(0, 0);
lcd.print(voltage,1);
lcd.print(" ");
lcd.print(current,1);
lcd.print(" ");
lcd.setCursor(0, 1);
lcd.print(energy);
lcd.print(" ");
lcd.print(biaya);
lcd.print(" ");
delay(1000);
}
f. Program Wemos D1
#define BLYNK_PRINT Serial
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
int temp;
int x = 5;
int y;
int value1;
int value2;
float tegangan = 0;
float arus = 0;
float powerx = 0;
float energyx = 0;
float datain1;
float datain2;
float datain3;
float datain4;
String dataIn;
String dt[10];
int i;
boolean parsing=false;
char auth[] = "DFDGDgfhgfhgTTUTjhgnbvmbmnvfgfghgfhdg";
char ssid[] = "my hotspotku";
char pass[] = "123456789";
SimpleTimer timer;
// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
void sendSensor()
{
Blynk.virtualWrite(V2, tegangan);
Blynk.virtualWrite(V3, arus);
Blynk.virtualWrite(V4, powerx);
Blynk.virtualWrite(V5, energyx);
delay(1000);
}
void setup()
{
dataIn="";
// Debug console
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
// You can also specify server:
//Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 8442);
//Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8442);
// Setup a function to be called every second
timer.setInterval(1000L, sendSensor);
}
void loop()
{
while(Serial.available()>0) {
// dataIn="";
char inChar = (char)Serial.read();
dataIn += inChar;
if (inChar == '\n') {
parsing = true;
}
}
if(parsing){
parsingData();
Blynk.run();
timer.run();
}
}
void parsingData(){
int j=0;
//kirim data yang telah diterima sebelumnya
//Serial.print("data masuk : ");
//Serial.print(dataIn);
//Serial.print("\n");
//inisialisasi variabel, (reset isi variabel)
dt[j]="";
//proses parsing data
for(i=1;i<dataIn.length();i++){
//pengecekan tiap karakter dengan karakter (#) dan (,)
if ((dataIn[i] == '#') || (dataIn[i] == ','))
{
//increment variabel j, digunakan untuk merubah index array penampung
j++;
dt[j]=""; //inisialisasi variabel array dt[j]
}
else
{
//proses tampung data saat pengecekan karakter selesai.
dt[j] = dt[j] + dataIn[i];
}
}
datain1 = dt[0].toInt();
datain2 = dt[1].toInt();
datain3 = dt[2].toInt();
datain4 = dt[3].toInt();
//kirim data hasil parsing
Serial.print("data 1 : ");
Serial.print(datain1);
Serial.print("\n");
Serial.print("data 2 : ");
Serial.print(datain2);
Serial.print("\n");
Serial.print("data 3 : ");
Serial.print(datain3);
Serial.print("\n");
Serial.print("data 4 : ");
Serial.print(datain4);
Serial.print("\n");
//Serial.print("data 3 : ");
//Serial.print(dt[2].toInt());
//Serial.print("\n\n");
tegangan = datain1 / 100.0;
arus = datain2 / 100.0;
powerx = datain3 / 100.0;
energyx = datain4 / 100.0;
}
g. VIDEO HASILNYA
No comments:
Post a Comment