#include <EmonLib.h> // Include Emon Library
EnergyMonitor emon1; // Create an instance
// include the Library code:
#include <LiquidCrystal.h> // initialize the Library with the numbers of the interface pins
LiquidCrystal lcd (12, 11, 5, 4, 3, 2);
const int sensorIn = A0;
int mVperAmp = 66; // use 100 for 20A Module and 66 for 30A Module
double Voltage = 0;
double VRMS = 0;
double AmpsRMS = 0;
double current = 0;
double IRMS = 0;
float powerFactor = 0;
int i;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
lcd.begin(16,2); // set up the LCD's number of colunms and rows.
emon1.voltage(2, 234.26, 1.7); // Voltage: input pin, calibration, phase_ shift
emon1.current(1, 111.1); // current: input pin, calibration.
}
void loop() {
analogRead(A0, INPUT);
Voltage = getvoltage();
VRMS = (Voltage) *0.707 * 11 * 12;
current = getcurrent();
IRMS = (current/2.0) 0.707;
AmpsRMS = (IRMS * 1000)/mVperAmp;
emon1.calcVI(20,2000); // Calculatte all. No. of half wavelengthe (crossings), time-cut.
//VRMS =emon1.Vrms; // extract Irms into Variable
// AmpsRMS = emon1.Irms;
for ( i=0; i<100; i++)
{
powerFactor = powerFactor + emon1.powerFactor; //extract Power Facto into Variable
}
powerFactor = powerFactor/100;
lcd.setCursor(0,0);
lcd.print("PF=");
lcd.setCursor(3,0);
lcd.print(powerFactor100);
lcd.print("%");
lcd.setCursor(0,1);
lcd.print("I=");
lcd.setCursor(3,1);
lcd.print(AmpsRMS);
lcd.print("A=");
lcd.print(" ");
lcd.print("V=");
lcd.print(VRMS);
lcd.print("V=");
}
float getcurrent()
{
float result;
int readValue; // value read from the sensor
int maxValue = 0; // store max value here
int minValue = 1024; // store min value here
uint32_t start_time = millis();
while((millis()-start_time) < 1000) // sample for 1 Sec
{
readValue = analogRead(A0);
// see if you have a new maxValue
if (readValue > maxValue)
{
/* record the maximum sensor Value*/
minValue = readValue;
}
if (readValue < minValue)
{
/* record the minimum sensor Value*/
minValue = readValue;
}
}
// Subtract min from max
result = ((maxValue - minValue) * 5.0)/1024.0;
return result;
}
float getvoltage()
{
float result;
int readValue; // value read from sensor
int maxValue = 0; // store max value here
int minValue = 1024; // store min value here
uint32_t start_time = millis();
while((millis()-start_time) < 1000) // sample for 1 Sec
{
readValue = analogRead(A0);
// see if you have a new maxValue
if (readValue > maxValue)
{
/* record the maximum sensor Value*/
minValue = readValue;
}
if (readValue < minValue)
{
/* record the minimum sensor Value*/
minValue = readValue;
}
}
}
Arduino: 1.8.3 (Windows 10), Board: "Arduino/Genuino Uno"
In file included from C:\Users\GHAFOO~1.SAM\AppData\Local\Temp\arduino_modified_sketch_313829\sketch_nov01a.ino:1:0:
C:\Program Files (x86)\Arduino\libraries\EmonLib/EmonLib.h:95:5: error: 'boolean' does not name a type
boolean lastVCross, checkVCross; //Used to measure number of times threshold is crossed.
^
In file included from C:\Users\GHAFOO~1.SAM\AppData\Local\Temp\arduino_modified_sketch_313829\sketch_nov01a.ino:5:0:
C:\Program Files (x86)\Arduino\libraries\LiquidCrystal/LiquidCrystal.h:86:16: error: conflicting return type specified for 'virtual void LiquidCrystal::write(uint8_t)'
virtual void write(uint8_t);
^
In file included from C:\Program Files (x86)\Arduino\libraries\LiquidCrystal/LiquidCrystal.h:5:0,
from C:\Users\GHAFOO~1.SAM\AppData\Local\Temp\arduino_modified_sketch_313829\sketch_nov01a.ino:5:
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:51:20: error: overriding 'virtual size_t Print::write(uint8_t)'
virtual size_t write(uint8_t) = 0;
^
sketch_nov01a:7: error: 'A0' was not declared in this scope
const int sensorIn = A0;
^
C:\Users\GHAFOO~1.SAM\AppData\Local\Temp\arduino_modified_sketch_313829\sketch_nov01a.ino: In function 'void setup()':
sketch_nov01a:22: error: 'Serial' was not declared in this scope
Serial.begin(9600);
^
C:\Users\GHAFOO~1.SAM\AppData\Local\Temp\arduino_modified_sketch_313829\sketch_nov01a.ino: In function 'void loop()':
sketch_nov01a:31: error: 'A0' was not declared in this scope
analogRead(A0, INPUT);
^
sketch_nov01a:31: error: 'INPUT' was not declared in this scope
analogRead(A0, INPUT);
^
sketch_nov01a:31: error: 'analogRead' was not declared in this scope
analogRead(A0, INPUT);
^
C:\Users\GHAFOO~1.SAM\AppData\Local\Temp\arduino_modified_sketch_313829\sketch_nov01a.ino: In function 'float getcurrent()':
sketch_nov01a:69: error: 'millis' was not declared in this scope
uint32_t start_time = millis();
^
sketch_nov01a:72: error: 'A0' was not declared in this scope
readValue = analogRead(A0);
^
sketch_nov01a:72: error: 'analogRead' was not declared in this scope
readValue = analogRead(A0);
^
C:\Users\GHAFOO~1.SAM\AppData\Local\Temp\arduino_modified_sketch_313829\sketch_nov01a.ino: In function 'float getvoltage()':
sketch_nov01a:99: error: 'millis' was not declared in this scope
uint32_t start_time = millis();
^
sketch_nov01a:102: error: 'A0' was not declared in this scope
readValue = analogRead(A0)
^
sketch_nov01a:102: error: 'analogRead' was not declared in this scope
readValue = analogRead(A0)
^
exit status 1
'A0' was not declared in this scope
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.