What you have changed is correct, and it works for me.
I needed to change the pin number for the voltage input because I have loaded the sketch into an emonTx, and the voltage input on that is ā0ā.
I also added another Serial.print
to check that supplyVoltage
was filled correctly:
#include "EmonLib.h" // Include Emon Library
EnergyMonitor emon1; // Create an instance
void setup()
{
Serial.begin(9600);
// emon1.voltage(2, 10.69, 1.7); // Voltage: input pin, calibration, phase_shift
// emon1.current(1, 111.1); // Current: input pin, calibration.
emon1.voltage(0, 10.69, 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)
float realPower = emon1.realPower; //extract Real Power into variable
float apparentPower = emon1.apparentPower; //extract Apparent Power into variable
float powerFActor = emon1.powerFactor; //extract Power Factor into Variable
float supplyVoltage = emon1.Vrms; //extract Vrms into Variable
float Irms = emon1.Irms; //extract Irms into Variable
Serial.print("supplyVoltage = "); Serial.println(supplyVoltage); // Added (RW)
delay(2000);
}
and I get (but with no current flowing):
0.00 1.56 9.53 0.16 0.00
supplyVoltage = 9.53
-0.00 0.93 9.53 0.10 -0.00
supplyVoltage = 9.53
0.00 0.55 9.53 0.06 0.00
supplyVoltage = 9.53
OK, I have different value resistors, but it is close to the correct value and not 110 V.
Are you sure you have edited, saved and uploaded the correct sketch? I ask this because more than once, I have edited one sketch and uploaded a different sketch, and cannot understand why everything is different and wrong.
Do you see any errors when you compile and upload the sketch?