Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat dengan fungsinya yaitu sebagai monitor daya arus dan tegangan secara jarak jauh melalui internet dengan aplikasi blynk, selain itu juga kendali jarak jauh relay sehingga user bisa kendali beban secara manual dengan aplikasi blynk. untuk lebih jelasnya berikut adalah program dan daftar komponennya.
a. Arduino Uno
b. NodeMCU esp8266
c. Lcd 16x2 + I2C
d. Modul Relay
e. Sensor PZEM-004t
f. Program Arduino Uno
#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 power = pzem.power();
int powerx = power * 100;
float energy = pzem.energy();
int energyx = energy * 100;
float frequency = pzem.frequency();
int frequencyx = frequency * 100;
float pf = pzem.pf();
int pfx = pf * 100;
Serial.print("*");
Serial.print(tegangan);
Serial.print(",");
Serial.print(arus);
Serial.print(",");
Serial.print(powerx);
Serial.print(",");
Serial.print(energyx);
Serial.print(",");
Serial.print(frequencyx);
Serial.print(",");
Serial.print(pfx);
Serial.println("#");
lcd.setCursor(0, 0);
lcd.print(voltage,1);
lcd.print(" ");
lcd.print(current,1);
lcd.print(" ");
lcd.print(power,1);
lcd.print(" ");
lcd.setCursor(0, 1);
lcd.print(energy,1);
lcd.print(" ");
lcd.print(frequency,1);
lcd.print(" ");
lcd.print(pf,1);
lcd.print(" ");
delay(1000);
}
g. Program NodeMCU
#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 frequencyx = 0;
float pfx = 0;
float datain1;
float datain2;
float datain3;
float datain4;
float datain5;
float datain6;
String dataIn;
String dt[10];
int i;
boolean parsing=false;
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "kjkhjgjhgDSFDSGFgfhghKHKLJHjhjkkgjfjhv";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "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);
Blynk.virtualWrite(V6, frequencyx);
Blynk.virtualWrite(V7, pfx);
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();
datain5 = dt[4].toInt();
datain6 = dt[5].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 5 : ");
Serial.print(datain5);
Serial.print("\n");
Serial.print("data 6 : ");
Serial.print(datain6);
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;
frequencyx = datain5 / 100.0;
pfx = datain6 / 100.0;
}
g. Interace Blynk
h. VIDEO HASILNYA
No comments:
Post a Comment