EmonLib Problem on energy monitor

Hi, I am trying to do like this project - http://openenergymonitor.org/emon/buildingblocks/how-to-build-an-arduino-energy-monitor

for the 2x 470kOhm for both current and voltage i used 10Kohm resistors as it says in the brackets or am I wrong ?

Is it because of the above resistors that arduino is displaying like below

 

205.95 371.65 1.59 233.22 0.55
246.01 561.49 2.88 195.03 0.44
144.10 374.21 2.27 164.52 0.39
51.57 286.41 2.05 139.39 0.18
94.71 269.44 2.32 116.34 0.35
58.18 237.18 2.51 94.63 0.25
40.82 201.50 2.75 73.17 0.20
-5.99 83.30 1.45 57.36 -0.07
12.74 98.79 2.35 42.05 0.13
-4.25 58.44 1.90 30.75 -0.07
-11.78 31.83 1.30 24.57 -0.37
6.38 46.03 2.28 20.20 0.14
6.11 37.70 2.21 17.08 0.16
3.79 30.10 2.08 14.46 0.13
0.06 8.81 2.03 4.33 0.01
0.12 1.81 1.88 0.96 0.07
0.07 0.68 1.91 0.36 0.11
0.26 1.87 1.92 0.97 0.14
0.07 3.18 2.58 1.23 0.02
-0.30 1.88 2.17 0.87 -0.16
-0.28 2.48 1.80 1.38 -0.11

....

 

I am using everything the same as the diagram apart from those 471Kohm resistors and I am using Mega 2560

Robert Wall's picture

Re: EmonLib Problem on energy monitor

Are those the first readings displayed after you start/restart the sketch?  If so, what you are looking at is the output of the high pass filter in the library as it finds the quiescent level of the input (which should be 512, but probably won't be exactly). When the filter has had time to settle, I would expect you to see small random variations in current values, and a small residual power value. This is because the ADC converter seems - especially with Arduino boards - to pick up a small amount of digital noise from the processor itself.

It should be nothing to do with those resistors, which are perfectly OK if you're mains powered, but will add unnecessary current drain if you're running on batteries.

calypso_rae's picture

Re: EmonLib Problem on energy monitor

For the sketch that you are using, the AC voltage needs to be sent to the processor via Analog input No 2.  The  corresponding Vrms should then appear as the 3rd value in each set of results, but this does not appear to be happening. 

Are you sure that your voltage signal is being fed to the correct pin of the processor?

drinu16's picture

Re: EmonLib Problem on energy monitor

@Robert Wall, Yes they are the first readings and running on mains.

 

@calypso_rae, yes the AC voltage is being sent to A2.

 

I have quickly re done the current "circuit" and it sort of was showing something but what i was running was 18W and it was showing about 8W (as the second reading). Then it started "refreshing" at about 5 times a second instead of following those 2 sec delay.

 

I will re wire everything from scratch tomorrow in case I made a mistake, lest hope this fix it :/

 

Thanks for your replies, will keep you posted.

calypso_rae's picture

Re: EmonLib Problem on energy monitor

Then it started "refreshing" at about 5 times a second ...

If the code that you're using is as below, that behaviour sounds correct.  Each measurement process will run for 20 half-cycles which takes 200 ms.  With no additional delay, loop() will be executed at about 5 times a second

void loop()
{
  emon1.calcVI(20,2000);         // Calculate all. No.of wavelengths, time-out
  emon1.serialprint();           // Print out all variables
}

The 2-second time-out is only used to terminate the measurement process if the normal mechanism fails to work.  This would presumably happen if the AC voltage signal were not  available. 

drinu16's picture

Re: EmonLib Problem on energy monitor

I have made some progress but not quite sure if it working as it should. I ended up re wiring everything from scratch which might have fixed a mistake Ive made. 

 

Anyway, I hooked up a 15" TFT on stand by (No signal mode) to a wall socket meter (below pic) and as you can see it displays 18W, a constant 18W.

This is the output from the arduino while the TFT is switched on

36.08 178.29 134.34 1.33 0.20
-1.08 237.42 134.42 1.77 -0.00
23.45 114.38 132.27 0.86 0.21
24.37 80.28 133.43 0.60 0.30
-2.08 110.30 133.94 0.82 -0.02
27.76 106.46 133.84 0.80 0.26
21.00 69.12 133.85 0.52 0.30
23.71 114.36 134.32 0.85 0.21
38.20 129.76 134.18 0.97 0.29
36.93 95.94 134.34 0.71 0.38
17.77 132.56 134.76 0.98 0.13
27.84 131.05 134.68 0.97 0.21
3.44 112.42 135.31 0.83 0.03
24.53 70.27 135.12 0.52 0.35

 

And this is a few secs after it is switched off

8.74 56.31 134.95 0.42 0.16
13.31 114.21 134.29 0.85 0.12
4.73 40.29 133.98 0.30 0.12
1.45 94.06 134.29 0.70 0.02
-1.70 98.00 134.18 0.73 -0.02
-6.48 185.53 134.96 1.37 -0.03
6.24 194.18 134.26 1.45 0.03
-8.21 157.65 134.53 1.17 -0.05
-2.14 150.33 131.01 1.15 -0.01
-2.04 204.84 134.33 1.52 -0.01
-10.37 228.85 134.33 1.70 -0.05
5.72 87.61 134.29 0.65 0.07
11.76 113.15 134.61 0.84 0.10

 

My question : Is it what it should display as Ive seen someone elses output and when switched off it shows zeros 

 

Could it be a calibration issue (second number from the below voltage parameters ?

 

emon1.voltage(2, 234.26, 1.7);  // Voltage: input pin, calibration, phase_shift
calypso_rae's picture

Re: EmonLib Problem on energy monitor

On your first set of results, the third value did not appear to be showing any voltage signal.  But now there is a sensible looking value which is nice and stable, whether or not any current is flowing. 

The first two columns should be showing power, but it's not obvious what's going on.  Have you tried with a larger load, say a kW or two?  Then you should see much more effect.  When only 18 Watts is flowing, very little of the ADC's range will be in use, maybe only a step or two depending on the value of your burden resistor.

 

Robert Wall's picture

Re: EmonLib Problem on energy monitor

As calypso_rae says, you are trying to read next to nothing. Your input is designed (unless you've changed things) to read up to 100 A, or about 24 kW. 18 W is only 0.075% of maximum reading, and as I wrote above, I think you're seeing mainly noise and your wanted measurement is buried in the noise.

drinu16's picture

Re: EmonLib Problem on energy monitor

Some progress :) I did put a larger load and it gave me a more stable readings

I have noticed that the wall monitor is giving me an average because that is what the arduino gave me when I made an average of the readings.

Anyway, I am a little confused on how to calculate the units just like the electricity provider caculates them.

Do i add up all the watts for 1 hour and get an average of those readings (1 reading every second) and then divide by 1000 which should result in units or is there a much more precise formula than that ?

Thanks

Robert Wall's picture

Re: EmonLib Problem on energy monitor

I do not understand what a wall monitor is.

The output from SerialPrint is (in order) real power (W), apparent power (VA), rms voltage (V), rms current (A) and power factor.

Your supplier's meter registers kWh, which is real power integrated over time. If you want to do that sum inside your Arduino, the theory is this: you must take the real power samples at whatever time interval you want (normally we use 10 s in the "discrete samples" sketch), multiply it by the interval between readings in seconds - this gives you the energy in Ws (watt seconds, or Joules) and continuously add these resulting values to an accumulator. To convert to kWh, you divide that by 3600000.

It is harder in practice because you cannot have an infinitely long number in the maths, so it is usually best to do the maths in two stages. You accumulate the readings as before in a long integer, then each time before you add the next reading, you test for the accumulated value is greater than 3600000. When it is, you subtract 3600000 from your first accumulator and add 1 to a second accumulator (probably also a long integer). Therefore the second accumulator increments in steps of 1 kWh and is exactly the same as your supplier's meter.

 

dBC's picture

Re: EmonLib Problem on energy monitor

Your revenue meter measures energy, and you're measuring power.   Energy is power x time.  So if you use a 2kW heater for 3 hours, it will cost you 6kWH,  as will a 3kW heater for 2 hours.

If you've arranged things such that your monitor gives you one power reading every second, a steady 18W say, and we assume that was the power reading for the entire second (or an average power reading throughout the second) then you've used 18W x 1sec = 18WattSeconds of energy in that second.  A WattSecond is also known as a Joule.  There are 3600 WattSeconds in a WattHr, and 3,600,000 WattSeconds in a kWH.

Do i add up all the watts for 1 hour

If you want to mimic your revenue meter, you add up the WattSeconds forever, not just for an hour.  The number should always get bigger.  Then simply divide it by 3,600,000 if you want to display your accumulated WattSeconds in kWH (which is what most revenue meters display).

dBC's picture

Re: EmonLib Problem on energy monitor

I'll bet good money that the 18W being displayed by your plug-through monitor is completely bogus.  That particular monitor should go in the bin.  In the attached photo you'll see two monitors both monitoring my microwave oven while it's in standby (i.e. just being a clock).   The good meter claims it's using 2.5W(*) with a PF of 0.1, the bad meter (which looks identical to yours) claims it's using 98W with a PF of 1 (displayed as a %-age so 100).

I've confirmed the good meter's results with my precision front-end.  Further analysis reveals the power supply in the microwave (while in standby) looks like one massive capacitor.  It draws a lot of amps (about 98 "watts" worth) with a nice clean sine wave on I, but that sine wave is almost exactly 90 degrees shifted compared to V.  So the PF is indeed close to 0, as is the real power being used.

There's something about that signal that completely confuses that make of meter into thinking the PF is 1, so it counts all that apparent power as real power.  It's very unlikely that your TFT in standby would have a PF of 1, so I'm guessing the meter is showing the same bug.

(*) some of which will be the power being consumed by the bad meter, given the way I've piggybacked them.

maglo18's picture

Re: EmonLib Problem on energy monitor

I prepare energy monitor on arduino  and i have problem. Without any load i have value :

-37.41 74.64 238.59 0.31 -0.50 

-38.75 75.23 237.49 0.32 -0.52 

-37.15 74.25 237.58 0.31 -0.50 

Load 100W

-143.56 157.94 237.53 0.66 -0.91 

-142.66 157.37 237.54 0.66 -0.91 

My calibration: 

  emon1.voltage(A3, 116.8, 1.7);  // Voltage: input pin, calibration, phase_shift
  emon1.current(A0, 30);       // Current: input pin, calibration.

CT sensor:

30A SCT-013-030

Where i should to look for bug?

 

 

Robert Wall's picture

Re: EmonLib Problem on energy monitor

Which circuit diagram have you used?
Which sketch are you using - what do those numbers represent?

We cannot help you when we do not know what you have.

maglo18's picture

Re: EmonLib Problem on energy monitor

Circuit diagram

 and 

Arduino sketch - voltage and current:

 

// EmonLibrary examples openenergymonitor.org, Licence GNU GPL V3

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

void setup()
{  
  Serial.begin(9600);
  
  emon1.voltage(A3, 116.8, 1.7);  // Voltage: input pin, calibration, phase_shift
  emon1.current(A0, 30);       // Current: input pin, calibration.
}

void loop()
{
  float sensorValue = analogRead(A0);  

  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
}

pb66's picture

Re: EmonLib Problem on energy monitor

Do you have just the 1 burden resistor per CT channel ? the SCT-013-030 has an internal burden resistor where as the usual SCT-013-000 CT does not.

maglo18's picture

Re: EmonLib Problem on energy monitor

I use only internal burden resistor. Maybe is it problem in my power supply because of on my supply i have 5,22V and middle point have 2.61V?

Robert Wall's picture

Re: EmonLib Problem on energy monitor

The power supply being high should not cause the problem you have.

The numbers you are seeing are Real power, Apparent power, Vrms, Irms and Power factor. The negative power means that you must reverse your CT on its cable.

However, you are reading a current when there should be none. That is almost certainly due to noise being picked up by the analogue to digital converter, which sees it as a current. This is likely to be digital noise from the digital part of your Arduino being transferred via the 5 V supply, but it could also be from your power supply itself. As far as I know, the Arduino PCB has no filtering to reduce this problem, whereas with our emonTx V3, great care was taken with the PCB layout and filtering to reduce this interference. You might be able to reduce the noise a little by putting additional capacitors (say 0.22 μF plastic film) across your 5 V supply to ground, positioned as close to the microprocessor as possible.

maglo18's picture

Re: EmonLib Problem on energy monitor

I turned wires and values are correct. If the noise is constant whether it can be calibrated in software? If i good understand i should improve power 5v or get new better power supply on 5v?

Robert Wall's picture

Re: EmonLib Problem on energy monitor

Unfortunately, although the noise is not true random (white) noise, I cannot say exactly where it comes from and so I cannot guarantee that the noise will be constant. As you can see from the numbers you read, it appears to have a power factor of 0.5, which means that there is both a real part and a reactive part. These two things together mean that it will be difficult to remove it completely in the software. It will be best to try first to remove as much as possible in hardware, then, if it is still a problem, look to subtracting the average value in your sketch.

maglo18's picture

Re: EmonLib Problem on energy monitor

I exchange power supply and effect is the same:

-36.17 77.07 235.93 0.33 -0.47 

-35.16 77.18 236.02 0.33 -0.46 

-35.00 73.67 235.87 0.31 -0.48 

-37.42 75.87 236.04 0.32 -0.49 

-35.83 75.33 235.98 0.32 -0.48 

Maybe I'm connect incorrect?

Robert Wall's picture

Re: EmonLib Problem on energy monitor

"I exchange power supply and effect is the same:"

Then I think the problem is digital noise from the microprocessor finding a route in to the analogue to digital converter.

maglo18's picture

Re: EmonLib Problem on energy monitor

What arduino is the best for emoncms? Now I have Pro Mini 5V and probably analog digital converter have a lot of noise.

Robert Wall's picture

Re: EmonLib Problem on energy monitor

I know very little about the Arduino range, so I cannot advise you.

But I can tell you two things:
(1) Most of the people who report that they have a noise problem are using the Arduino and not the emonTx.
(2) When I looked at the PCB layout of an Arduino, there was no power supply filtering between the supply pin to the analogue side and the supply pin for the digital side. When Glyn Hudson was laying out the PCB for the emonTx V3, he was very careful to run the analogue circuits as far as possible away from the digital circuits, and screened them with a ground plane. The analogue ground is also separated from the digital ground to prevent 'ground noise' from getting into the ADC.

dBC's picture

Re: EmonLib Problem on energy monitor

Some Arduinos do have the AVR recommended inductor between AVCC and VCC.  From memory I think the Leonardo might have it.  A quick check of your ProMini reveals it doesn't, and nor do my Mega2560s.  Here's a very simple check you could start off with.  When I try this on my Mega2560 (powered from my desktop's USB port) I see:

Min: 510, Max: 511

Very occasionally Min drops down to 509, and that seems to happen more often on A1 (with the 150K divider) than on A0 (10K divider).  You might need to reduce the size of the array depending on how much RAM your Arduino has. The array is only there so you can look at the signal should your rmin/max show something more exciting than 510/511, in which case you can paste the values into a spreadsheet and plot them.  

Assuming yours also shows just 510/511 then you could start adding back in the components of your energy monitoring schematic, and see if/when that changes.

[EDIT-1] P.S.  I used 1% resistors which would explain why both dividers have nailed the mid-point so well.  If you don't have 1%'ers you might see a different value from 510/511, which doesn't matter.  You're looking for stability rather than accuracy.

[EDIT-2] P.P.S. If I stick my finger on the mid-point of the divider, the readings go to 505/515 for the low impedance source (A0) and 490/531 for the high impedance source (A1).

maglo18's picture

Re: EmonLib Problem on energy monitor

Power from USB:

Min: 512, Max: 512

Min: 511, Max: 513

Power from supply:

Min: 508, Max: 514

Do I need better power supply?

PS. I exchanged resistor on middle point and now is better:

load = 0

1.89 25.21 237.43 0.11 0.07 

4.43 26.12 237.41 0.11 0.17 

4.27 25.63 237.52 0.11 0.17 

2.73 26.89 237.57 0.11 0.10 

2.40 24.60 237.39 0.10 0.10 

4.68 26.69 237.42 0.11 0.18 

3.11 26.58 237.72 0.11 0.12 

 

Robert Wall's picture

Re: EmonLib Problem on energy monitor

Those values are much more like the numbers we expect to see with an Arduino module project. You might not be able to improve much more than that.

maglo18's picture

Re: EmonLib Problem on energy monitor

I hope last question. Is it correct code for 3 phases?

 

// EmonLibrary examples openenergymonitor.org, Licence GNU GPL V3

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

void setup()
{  
  Serial.begin(115200);
  
  emon1.voltage(A3, 115.8, 1.7);  // Voltage: input pin, calibration, phase_shift
  emon1.current(A0, 29);       // Current: input pin, calibration.
  emon2.voltage(A4, 115.8, 1.7);  // Voltage: input pin, calibration, phase_shift
  emon2.current(A1, 29);       // Current: input pin, calibration.
  emon3.voltage(A5, 115.8, 1.7);  // Voltage: input pin, calibration, phase_shift
  emon3.current(A2, 29);       // 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)
  emon2.calcVI(20,2000);         // Calculate all. No.of half wavelengths (crossings), time-out
  emon2.serialprint();       // Print out all variables (realpower, apparent power, Vrms, Irms, power factor)
  emon3.calcVI(20,2000);         // Calculate all. No.of half wavelengths (crossings), time-out
  emon3.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
  float realPower2       = emon2.realPower;        //extract Real Power into variable
  float apparentPower2   = emon2.apparentPower;    //extract Apparent Power into variable
  float powerFActor2     = emon2.powerFactor;      //extract Power Factor into Variable
  float supplyVoltage2   = emon2.Vrms;             //extract Vrms into Variable
  float Irms2            = emon2.Irms;             //extract Irms into Variable
  float realPower3       = emon3.realPower;        //extract Real Power into variable
  float apparentPower3   = emon3.apparentPower;    //extract Apparent Power into variable
  float powerFActor3     = emon3.powerFactor;      //extract Power Factor into Variable
  float supplyVoltage3   = emon3.Vrms;             //extract Vrms into Variable
  float Irms3            = emon3.Irms;             //extract Irms into Variable
}

dBC's picture

Re: EmonLib Problem on energy monitor

[Discussion about grounding has been moved to a new thread - RW]

Robert Wall's picture

Re: EmonLib Problem on energy monitor

maglo:

That code looks OK, you have created an instance of EnergyMonitor for each phase, and I think you have set each one up with the correct input pins and calibration. You will probably find that, because of component tolerances, you might need different calibration values on each phase. That is perfectly OK.

But there is no need to copy all the values from the instances of EnergyMonitor, and the values will remain in the class members until they are overwritten when you next call calcVI(..).

dBC's picture

Re: EmonLib Problem on energy monitor

I think 'double' and 'float' are identical in the AVR gcc implementation.  If you've got an ARM based Due, then a it makes a difference.

pb66's picture

Re: EmonLib Problem on energy monitor

PS. I exchanged resistor on middle point and now is better:

It would be interesting to know what changes you made, maglo. What values were you using before and after ?

maglo18's picture

Re: EmonLib Problem on energy monitor

Now is 10k before was 330.

pb66's picture

Re: EmonLib Problem on energy monitor

I assume you mean they were 330K before (not ohms),

Power from USB:

Min: 512, Max: 512

Min: 511, Max: 513

Power from supply:

Min: 508, Max: 514

and these readings were using the 10K dividers, is that correct ?

also were they just average resistors or did you use higher precision ones ?

hope you don't mind me asking.

 

maglo18's picture

Re: EmonLib Problem on energy monitor

No. I didn't  use  yours sketch before for measure. 

330 ohm resistor:

-36.17 77.07 235.93 0.33 -0.47 

-35.16 77.18 236.02 0.33 -0.46 

-35.00 73.67 235.87 0.31 -0.48 

-37.42 75.87 236.04 0.32 -0.49 

10k resistor :

1.89 25.21 237.43 0.11 0.07 

4.43 26.12 237.41 0.11 0.17 

4.27 25.63 237.52 0.11 0.17 

 

calypso_rae's picture

Re: EmonLib Problem on energy monitor

Maglo18,

In the image that you posted (copy below), you have only one passive Vref supply and it is being shared between all of your sensors.  That system will not work at all well, there will a lot of crosstalk between your analogue channels.  You should either have a separate Vref circuit for each analog channel, or add an op amp to buffer the single Vref rail so that it remains constant.

maglo18's picture

Re: EmonLib Problem on energy monitor

If i good understand i should add 6 x different middle point for 3 x voltage meter and 3 x ampere meter?

maglo18's picture

Re: EmonLib Problem on energy monitor

Maybe better way will be use Micropower Voltage Reference Diodes ex. LM385-2.5 for each analog input?

Robert Wall's picture

Re: EmonLib Problem on energy monitor

I do not recommend Zener diodes / voltage reference diodes. To get the best range from your meaurements, you want the midpoint to be exactly the midpoint, whatever the supply voltage happens to be, and not exactly 2.5 V (except of course when the supply happens to be exactly 5.0 V).

As calypso_rae says, if you do not want 6 sets of resistors & capacitor, then use an op. amp. as a voltage follower, as he did in his Mk2 Diverter http://openenergymonitor.org/emon/sites/default/files/Mk2_CircuitSchematic.pdf

maglo18's picture

Re: EmonLib Problem on energy monitor

Thank you for help. I used 6 sets resistor (24k) and capacitor 100 µF. I hope it is fine because on schematic capacitor doesn't have value

Robert Wall's picture

Re: EmonLib Problem on energy monitor

"Building Blocks", where you found the diagram you posted, are not fully engineered circuits. They are examples to explain the theory of how the circuit works. If you want working fully engineered circuits, you should be looking at the schematic diagrams for, in this case, the emonTx. On the Wiki, you will find a link to the diagrams, which are on Solderpad.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.