Arduino - Notepad PDF
Arduino - Notepad PDF
Arduino - Notepad PDF
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <SoftwareSerial.h> // Arduino IDE <1.6.6
#include <PZEM004T.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include "RTClib.h"
#define pin_relay 12
#define ONE_WIRE_BUS A0
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
byte second = 0;
byte minute = 0;
byte hour = 0;
byte weekday = 0;
byte monthday = 0;
byte month = 0;
int year = 0;
const int DS1307 = 0x68; // Alamat pin RTC pada arduino
void setup()
{
pinMode(pin_relay,OUTPUT);
Wire.begin();
Serial.begin(9600);
pzem.setAddress(ip);
sensors.begin();
lcd.begin();
lcd.print("POWER MONITOR");
relay_off;
}
float v,i,p,c;
int suhu;
long last_millis = millis(),HM,HMmenit;
int index,lastminute;
void loop(){
Page 1
arduino
if (Serial.available()){
String data = Serial.readStringUntil('\n');
int a = data.indexOf("A");
int b =data.indexOf("B");
if (b>0){
data=data.substring(a+1,b);
int dat= data.length();
if(dat==1){
if (data=="1"){
relay_on;
}else if (data=="2"){
relay_off;
}
}else{
cek(data);
}
}
}
float v = pzem.voltage(ip);
if (v < 0.0) v = 0.0;
float i = pzem.current(ip);
if(i <= 0.0){ i=0;}
time_read();
if (v>200){
if (lastminute!=minute){
lastminute=minute;
HMmenit++;
if (HMmenit>=60){HM++;HMmenit=0;}
}
}
lcd.setCursor(0,0);
lcd.print(karakter(hour));
lcd.print(":");
lcd.print(karakter(minute));
lcd.print(":");
lcd.print(karakter(second));
lcd.print(" ");
lcd.print(karakter(HM));
lcd.print(":");
lcd.print(karakter(HMmenit));
lcd.print(" ");
lcd.setCursor(0,1);
lcd.print("V");
lcd.print((int)v);
lcd.print(" I");
Page 2
arduino
lcd.print(i);
lcd.print(" T");
lcd.print(suhu);
lcd.print(" ");
Page 3