Slow reads in serial monitor when no current flowing

Hi All,

This is my first post in this forum (or any electronic forum for this matter) so please be gentle :wink:

I have setup my hardware with following components:

  • Wemos D11 mini
  • MCP3008
  • ACS712 (30A)

Now, after hooking it all up together I have calibrated the setup using:
emon1.voltage(1, 309.0, 0.6); // Voltage: input pin, calibration, phase_shift
emon1.current(0, 14.5); // Current: input pin, calibration.

BTW: (I noticed that in my case no matter what I put in phase_shift - it doesn’t make any difference)

I am testing this using a cheap, standard 60W light bulb.

When the bulb is switched ON these are the kind of readings displayed quite fast (2-3 lines per sec):
58.65 65.33 236.17 0.28 0.90
58.45 65.12 236.14 0.28 0.90
58.67 65.49 236.12 0.28 0.90
58.57 65.24 236.23 0.28 0.90

However, with the bulb switched OFF I can see that the results are much slower (1 lines per 2 secs):
0.00 0.00 0.00 0.06 0.00
0.00 0.00 0.00 0.06 0.00
-0.00 0.00 0.00 0.06 -0.00
-0.00 0.00 0.00 0.06 -0.00
0.00 0.00 0.00 0.06 0.01

One other thing is that I have to add wdt_disable(); in my loop - otherwise my wemos chip reboots exactly every 3 reads:
233.77 233.94 104.45 2.24 1.00
-0.00 0.00 0.00 0.06 -0.00
-0.00 0.00 0.00 0.06 -0.01

Soft WDT reset

ctx: cont
sp: 3ffef250 end: 3ffef4a0 offset: 01b0

stack>>>
3ffef400: 3ffee448 00000001 3ffe8461 40202b14
3ffef410: 3ffe86b8 020d67ce bf795a90 000003e8
3ffef420: 3ffee2b0 3fdd67ce ddaba800 40201f38
3ffef430: 000021cc 3ffee394 00000000 3ffee394
3ffef440: 00001d29 00000014 00000000 3dd00000
3ffef450: 00000000 3dd00000 000003ff 402010a3
3ffef460: feefeffe 3ffee2b0 3ffee448 3ffee46c
3ffef470: 3fffdad0 3ffee2ac 3ffee2b0 40201c99
3ffef480: 3fffdad0 00000000 3ffee464 40202914
3ffef490: feefeffe feefeffe 3ffee480 40100114
<<<stack<<<

ets Jan 8 2013,rst cause:2, boot mode:(3,6)

load 0x4010f000, len 1384, room 16
tail 8
chksum 0x2d
csum 0x2d
v09f0c112
~ld
233.84 234.00 104.45 2.24 1.00
0.00 0.00 0.00 0.06 0.00
-0.00 0.00 0.00 0.06 -0.01

Any pointers (I’m a newbie) are more than welcomed here!
Regards,
Papi.

Welcome, Papi.

First, I do not know what the rest of your sketch looks like, nor do I know the ESP8266, nor how you are using that and the ACS712.

The demonstration sketches, and the emonLib library, are written primarily for the Atmel 328P processor, which has only a single ADC, therefore a multiplexer is used to select between voltage and current inputs. I understand that the ADC in the ESP8266 works much faster than the Atmel, therefore there will be many more samples per mains cycle, and that is why the phase shift algorithm does not make a visible difference. It will be making a difference, but a very small one.

I see you have zero voltage when the lamp is switched off! Why? If you look at calcVI( ) in emonLib, you will see that it measures for a set number of cycles of mains. Without a voltage input, it waits forever (until it times out) for the start of a mains cycle that never comes. That is why the readings are slow. You should measure the voltage continuously, that is, before the switch.

Hi Robert, your’e right - I forgot to paste in the most important part - the sketch!

#include "EmonLib.h"             // Include Emon Library
EnergyMonitor emon1;             // Create an instance

unsigned long time;
float energy=0;
 
void setup() 
{
 Serial.begin(115200); 
 emon1.voltage(2, 237.46, 1.7);  // Voltage: input pin, calibration, phase_shift
 emon1.current(0, 15.5);         // Current: input pin, calibration.
}
 
void loop() 
{
 //wdt_disable(); //to avoid reboots !!
 time = millis();
 emon1.calcVI(20,1000);         // 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
  energy=(realPower*time)/3600/1000; //Watt-sec is again convert to Watt-Hr by dividing 1hr(3600sec)
  // energy=(watt*time)/(1000*3600); for reading in kWh
}

→ Thanks for the explanation about phase shift - it makes sense not to see much difference at higher clock speeds.

Regarding the zero V when the lamp is off - I think this is exactly the issue! If You look at the photo above there are two wires going off to the left side (gray & white).
The grey wire is my 230V AC source - and it has a switch.
The white wire is my load (60W bulb).
When I flip the switch I am in fact cutting all current to both the load and the transformer! That was obviously wrong!
After moving the switch to the white cable (meaning where my load is) everything works fine!

Silly thing really - but one has to be shown sometimes! :slight_smile:
Thanks.

The answer to your 0.9 power factor is rather more complicated. The correction is necessary because there is a time difference between reading voltage and current, and because both current and voltage transformers show a phase lead, but of different amounts. There are numbers in the test reports on these in Resources > Building Blocks. The “phase shift” is to compensate for the combination of these three things. My guess is to get the power factor to 1.0, you will need to delay one set of samples (by several samples) to give a coarse correction, and then use the PHASECAL algorithm (again explained in Building Blocks) to give a fine correction. Exactly the same idea is used in the 3-phase sketch to delay the voltage by 120° and 240° to line up with the current in the second and third phases.

Hi Robert, it took me a while to go through the above readings (with minimum level of understanding ;)) but in the end the results I’m getting for my standard 60W light are:
59.60 59.33 233.86 0.25 1.00
59.70 59.69 233.71 0.26 1.00
59.70 59.89 233.82 0.26 1.00
59.48 59.29 233.66 0.25 1.00
59.43 59.53 233.79 0.25 1.00
59.89 59.89 233.73 0.26 1.00

However, replacing the standard bulb with a Philips energy-saver light [20W] gives me completely different results regarding the phase (last number):
16.08 35.26 233.17 0.15 0.46
16.11 34.63 232.75 0.15 0.47
15.59 34.57 232.61 0.15 0.45
16.29 34.77 233.15 0.15 0.47
16.49 35.07 233.05 0.15 0.47

Is this expected? Does it mean I need to calibrate the setup for each different type of load?
I wanted to use 3 of those for my house’s power lines… and get the total kWh used to compare it with my energy provider…

Indeed it is.

Definitely not. You should calibrate (as the instructions say) with a purely resistive load. By definition, the power factor of that is 1.0. What those numbers are telling you is the power factor of the energy saving lamp is poor, which is not unusual for the type of electronics in there. They are saying is that V × I comes to 35 W, whereas the real power is actually only 16 W (and most of that will be heat). (The 20 W on the label might be accurate at 240 V.)

Hopefully, you’re getting there! Don’t worry, we all had to learn all this once upon a time.