/**
Arduino Electronic Safe
Copyright (C) 2020, Uri Shaked.
Released under the MIT License.
*/
#include <math.h>
#include <LiquidCrystal.h>
/* Display */
LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
float randomNum;
void setup() {
randomSeed(analogRead(0));
lcd.begin(20, 4);
lcd.setCursor(5, 0);
lcd.print("PZEM-004T");
lcd.setCursor(2, 1);
lcd.print("3-PHASE AC METER");
lcd.setCursor(2, 2);
lcd.println("CONNECTING BLYNK");
// showWaitScreen(400);
delay(1000);
lcd.clear();
}
void loop() {
lcd.setCursor(4,0);
lcd.print ("PHASE-1 (R)");
float tegangan1 = random(2000, 2201)/10.0;
lcd.setCursor(0,1); lcd.print (tegangan1,1);
lcd.setCursor(7,1); lcd.print ("V");
float arus1 = random(0, 20)/10.0;
lcd.setCursor(9,1); lcd.print (arus1);
lcd.setCursor(14,1); lcd.print ("A");
float power1 = tegangan1 * arus1;
float S1 = tegangan1 * arus1;
float pf1 = power1 / S1;
float pf1Angle = acos(pf1)*(180.0 / PI);
float var1 = tegangan1 * arus1 * sin(pf1Angle *(PI / 180.0));
lcd.setCursor(0,2); lcd.print (power1,1); lcd.print(" ");
lcd.setCursor(7,2); lcd.print ("W");
lcd.setCursor(9,2); lcd.print (pf1);
lcd.setCursor(14,2); lcd.print ("Pf");
lcd.setCursor(0,3); lcd.print (var1,1); lcd.print(" ");
lcd.setCursor(7,3); lcd.print ("VAR");
delay(1000);
}
void showWaitScreen(int delayMillis) {
lcd.setCursor(4, 3);
lcd.print("[..........]");
lcd.setCursor(5, 3);
for (byte i = 0; i < 10; i++) {
delay(delayMillis);
lcd.print("=");
}
}