Monitor Daya Tegangan dan Arus dan Pembatas Arus Maksimal via BLYNK
Pada kesempatan ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat memonitor tegangan arus dan daya secara realtime dengan menggunakan blynk dan juga alat ini memiliki fitur yang dapat membatasi arus berlebih jadi jika arus yang mengalir telah melebihi maksimal yang seperti kita inputkan melalui keypad maka relay akan off sehingga arus akan off juga. untuk lebih jelasnya berikut adalah komponen dan programnya.
a. Arduino Uno
b. Sensor Pzem 004t
c. Relay Modul 5v
d. Keypad 4x4
e. LCD 16x2 I2C
f. Wemos d1 mini
g. Interface Blynk
h. Program Arduino
#include <Wire.h>
#include <Keypad.h>
#include <LiquidCrystal_I2C.h>
#include <PZEM004Tv30.h>
PZEM004Tv30 pzem(2,3);
LiquidCrystal_I2C lcd(0x27, 16, 2);
int relay = 4;
int led = 9;
int buzzer = 10;
int arus = 0;
float arusx;
float arusflo;
char customKey;
const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte rowPins[ROWS] = {A0,A1,A2,A3}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {5,6,7,8}; //connect to the column pinouts of the keypad {5,6,7,8};
//initialize an instance of class NewKeypad
Keypad customKeypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS);
void setup()
{
pinMode(relay, OUTPUT);
digitalWrite(relay, LOW);
pinMode(led, OUTPUT);
digitalWrite(led, LOW);
pinMode(buzzer, OUTPUT);
digitalWrite(buzzer, HIGH);
lcd.begin();
lcd.noCursor();
lcd.clear();
Serial.begin(9600);
}
void loop()
{
float voltage = pzem.voltage();
float current = pzem.current();
float power = pzem.power();
lcd.setCursor(0,0);
lcd.print("I= ");
lcd.print(current,2);
lcd.print(" / ");
lcd.print(voltage,1);
lcd.print(" ");
lcd.setCursor(0,1);
lcd.print("S= ");
lcd.print(arusx,2);
lcd.print(" ");
Serial.print("*");
Serial.print(voltage * 100);
Serial.print(",");
Serial.print(current * 100);
Serial.print(",");
Serial.print(power * 100);
Serial.print(",");
Serial.print(arusx * 100);
Serial.println("#");
customKey = customKeypad.getKey();
if(customKey == 'A'){
lcd.clear();
delay(1000);
arus = 0;
arusx = 0;
setting();
}
if((current > arusx)&&(arusx > 0)){
digitalWrite(relay,HIGH);
digitalWrite(buzzer,LOW);
digitalWrite(led,HIGH);
delay(2500);
digitalWrite(relay,LOW);
digitalWrite(buzzer,HIGH);
digitalWrite(led,LOW);
}
if((current < arusx)&&(arusx > 0)){
digitalWrite(relay,LOW);
digitalWrite(buzzer,HIGH);
digitalWrite(led,LOW);
}
delay(200);
}
void setting(){
lcd.setCursor(0,0);
lcd.print("Set Max Arus");
customKey = customKeypad.getKey();
if(customKey >= '0' && customKey <= '9')
{
arus = arus * 10 + (customKey - '0');
lcd.setCursor(0,1);
lcd.print(arus);
}
if(customKey == 'A')
{
arusx = 0;
arus = 0;
lcd.clear();
delay(1000);
}
if(customKey == 'B')
{
arusx = arus / 1.0;
lcd.clear();
delay(1000);
return;
}
if(customKey == 'C')
{
arusx = arus / 10.0;
lcd.clear();
delay(1000);
return;
}
if(customKey == 'D')
{
arusx = arus / 100.0;
lcd.clear();
delay(1000);
return;
}
setting();
}
#include <Keypad.h>
#include <LiquidCrystal_I2C.h>
#include <PZEM004Tv30.h>
PZEM004Tv30 pzem(2,3);
LiquidCrystal_I2C lcd(0x27, 16, 2);
int relay = 4;
int led = 9;
int buzzer = 10;
int arus = 0;
float arusx;
float arusflo;
char customKey;
const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte rowPins[ROWS] = {A0,A1,A2,A3}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {5,6,7,8}; //connect to the column pinouts of the keypad {5,6,7,8};
//initialize an instance of class NewKeypad
Keypad customKeypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS);
void setup()
{
pinMode(relay, OUTPUT);
digitalWrite(relay, LOW);
pinMode(led, OUTPUT);
digitalWrite(led, LOW);
pinMode(buzzer, OUTPUT);
digitalWrite(buzzer, HIGH);
lcd.begin();
lcd.noCursor();
lcd.clear();
Serial.begin(9600);
}
void loop()
{
float voltage = pzem.voltage();
float current = pzem.current();
float power = pzem.power();
lcd.setCursor(0,0);
lcd.print("I= ");
lcd.print(current,2);
lcd.print(" / ");
lcd.print(voltage,1);
lcd.print(" ");
lcd.setCursor(0,1);
lcd.print("S= ");
lcd.print(arusx,2);
lcd.print(" ");
Serial.print("*");
Serial.print(voltage * 100);
Serial.print(",");
Serial.print(current * 100);
Serial.print(",");
Serial.print(power * 100);
Serial.print(",");
Serial.print(arusx * 100);
Serial.println("#");
customKey = customKeypad.getKey();
if(customKey == 'A'){
lcd.clear();
delay(1000);
arus = 0;
arusx = 0;
setting();
}
if((current > arusx)&&(arusx > 0)){
digitalWrite(relay,HIGH);
digitalWrite(buzzer,LOW);
digitalWrite(led,HIGH);
delay(2500);
digitalWrite(relay,LOW);
digitalWrite(buzzer,HIGH);
digitalWrite(led,LOW);
}
if((current < arusx)&&(arusx > 0)){
digitalWrite(relay,LOW);
digitalWrite(buzzer,HIGH);
digitalWrite(led,LOW);
}
delay(200);
}
void setting(){
lcd.setCursor(0,0);
lcd.print("Set Max Arus");
customKey = customKeypad.getKey();
if(customKey >= '0' && customKey <= '9')
{
arus = arus * 10 + (customKey - '0');
lcd.setCursor(0,1);
lcd.print(arus);
}
if(customKey == 'A')
{
arusx = 0;
arus = 0;
lcd.clear();
delay(1000);
}
if(customKey == 'B')
{
arusx = arus / 1.0;
lcd.clear();
delay(1000);
return;
}
if(customKey == 'C')
{
arusx = arus / 10.0;
lcd.clear();
delay(1000);
return;
}
if(customKey == 'D')
{
arusx = arus / 100.0;
lcd.clear();
delay(1000);
return;
}
setting();
}
i. Program Wemos D1 mini
#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 spx = 0;
float datain1;
float datain2;
float datain3;
float datain4;
String dataIn;
String dt[10];
int i;
boolean parsing=false;
char auth[] = "2_SeDKdvjeAWod1cUIKAKXL2G_Ld8Pen";
char ssid[] = "myhotspotku";
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(V5, tegangan);
Blynk.virtualWrite(V6, arus);
Blynk.virtualWrite(V7, powerx);
Blynk.virtualWrite(V8, spx);
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;
spx = datain4 / 100.0;
}
#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 spx = 0;
float datain1;
float datain2;
float datain3;
float datain4;
String dataIn;
String dt[10];
int i;
boolean parsing=false;
char auth[] = "2_SeDKdvjeAWod1cUIKAKXL2G_Ld8Pen";
char ssid[] = "myhotspotku";
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(V5, tegangan);
Blynk.virtualWrite(V6, arus);
Blynk.virtualWrite(V7, powerx);
Blynk.virtualWrite(V8, spx);
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;
spx = datain4 / 100.0;
}
j. VIDEO HASILNYA
No comments:
Post a Comment