کد هایی که الان دارم اینهاســـــت!
کد HTML:
#include "EmonLib.h" // Include Emon Library
EnergyMonitor emon1; // Create an instance
// include LCD the library:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup()
{
Serial.begin(9600); // set up the LCD’s number of columns and rows:
lcd.begin(20, 4);
emon1.voltage(2, 234.26, 1.7); // Voltage: input pin, calibration, phase_shift
emon1.current(1, 111.1); // Current: input pin, calibration.
}
void loop()
{
emon1.calcVI(20,2000); // Calculate all. No.of half wavelengths (crossings), time-out
emon1.serialprint(); // Print out all variables (realpower, apparent power, Vrms, Irms, power factor)
unsigned int long timemillis=millis(); //keeping the track of the time since the device is switched ON
unsigned int long time=timemillis/1000;
float realPower = emon1.realPower; //extract Real Power into variable
float apparentPower = emon1.apparentPower; //extract Apparent Power into variable
float powerFactor=emon1.powerFactor;//extract Apparent Power into variable rFactor = emon1.powerFactor; //extract Power Factor into Variable
float supplyVoltage = emon1.Vrms; //extract Irms into Variable
float Irms = emon1.Irms;
//displaying the values
lcd.setCursor(1,0);
lcd.print("Energy Monitor");
lcd.setCursor(0,1);
lcd.print("V=");
lcd.print(supplyVoltage);
lcd.setCursor(9,1);
lcd.print("I=");
lcd.print(Irms);
lcd.setCursor(-4,2);
lcd.print("PowerFactor=");
lcd.print(powerFactor);
lcd.setCursor(-4,3);
lcd.print("Units(kWh)=");
lcd.print(abs(realPower*time)/abs(1000*3600));
lcd.setCursor(-4,4);
lcd.print("(kW)=");
lcd.print(realPower/1000);
lcd.setCursor(-4,5);
lcd.print("(KVA)=");
lcd.print(apparentPower/1000);
lcd.setCursor(-4,6);
lcd.print("(KVAR)=");
lcd.print((sqrt((apparentPower*apparentPower)-(realPower*realPower)))/1000);
}