Measuring AC mains energy use the invasive current sensing resistor and voltage divider method

This design is an adaptation of the great work by Cliff Jao and Xi Guo on the PowerBox project.

In comparison with the non-invasive current transformer method this method requires more care due to components being inserted directly into the high voltage mains wiring. It is suited to smaller power applications. For whole house energy use the non-invasive method is a safer and simpler way to go, especially if your new to electronics.

Note: There are a couple of issues with this design at present, the main one being that the hcpl-7520 optoisolator chips started blowing, and I haven't as yet established why this is, it may be that the supplies were not stable enough. Im not sure if or when I will have another look at this since Im now quite happy with the non-invasive CT method and will myself be using that method for the forseable future. I will however leave this guide on the invasive method up here in case it is useful.

How it works

These pages detail how power is measured and calculated, info on real power, apparent power and power factor, AC power theory 2 goes into discrete time equations and how the arduino sketch works.

 

Electronics side

To measure energy use or power that a device is using, the voltage and the current needs to be measured.

The voltage is measured using a voltage divider to scale down the mains voltage from 240V to 0.17V a voltage that is then isolated through the HCPL-7520 optoisolators and finally read by the Arduino.

Current is measured using a current sensing resistor. A current sensing resistor is a very small valued resistor, the resistor produces a voltage drop across it that is again isolated by a HCPL-7520 optoisolator and then read by the Arduino. 

For schematics and design considerations check out the electronics page:

Electronics

Arduino sketch and basic computer output

Update 10 April 2010: This part is now the same as the arduino sketch part for the non invasive method for mains AC measurement.

Once you have the electronics built the next step is to load a sketch to the Arduino. The Arduino sketch is the piece of software that runs on the Arduino. The Arduino converts the raw data from its analog inputs into a nice useful values like real power etc and then outputs them to serial.

Download the sketch here: basicmonitor.tar.gz

and then upload it onto the Arduino. Then go to the Arduino serial monitor and you should see values being printed to the screen, looking something like this:

From left to right: Real Power, Apparent Power, Power Factor, Vrms, Irms.

Calibration

If you compare the output from the serial monitor with the output from a reference energy monitor (like a kill-a-watt plug in meter) they probably wont be the same. To get accurate measurements the energy monitor needs to be calibrated, as follows:

Step one – calibrating power factor

Power factor needs to be calibrated due to phase displacements from the CT sensor, Power adapter and multiplexed ADC readings. To calibrate choose a load that is reactive like a fridge or a grinder and a load that's resistive like a heater. Compare the value for power factor on your energy monitor and your reference meter. Look in the Arduino sketch for the line:

double PHASECAL = 1.0;

Try different values until the power factor's agree for when you have the reactive load connected and when you have the resistive load connected. I found 2.3 worked well.

Step two – calibrating voltage and current

For best results choose a load that's within but close to the maximum range of your energy monitor and your reference meter minus a couple of hundred watts, most domestic plug in meters go up to about 3120W so around 2000-2800W would be fine (as long as this is also within the range of the energy monitor)

If your using non-halogen heaters beware that the power that they consume decreases for sometimes up to 10mins as they heat up. To take an accurate calibration point wait until the power consumption is stable.

Note down the Voltage and Current value off your reference meter and from the Arduino serial monitor and then calculate the calibration coefficients:

Look in the Arduino sketch for the lines:

double VCAL = 1.0; double ICAL = 1.0;

Multiply the old VCAL by the new VCAL and replace the old value with the result.

Upload the sketch and now hopefully your values should be a lot closer to what they should be.

kWh and Frequency

Add kWh and Frequency calculation with this sketch:

basicMonitorPlusKwhFreq.tar.gz

Now that the basic setup is working we can extend it so that the data becomes a bit more useful!

Extend it

 

Anna's picture

Hi, somehow the moment i

Hi,

somehow the moment i connect one side of my mains or device onto my breadboard, the line trips. but i dont see any short circuit.. any advice?

thanks
anna

TrystanLea's picture

 Hey Anna, not sure what's

 Hey Anna, not sure what's going wrong here, is this the same for the current sensing and the voltage sensing circuit?

Anna's picture

Hi Trystan, I found out the

Hi Trystan,

I found out the problem, i was accidentally supplying 5V and GND to the High voltage side from my Arduino. I am now powering it up using a 2 separate DC supplies.

The code still however doesnt run, but i will try viewing the waveform like you suggested. Thanks so much for the help. =)

Anna

TrystanLea's picture

Hey Anna, Good to hear you

Hey Anna, Good to hear you sorted the line tripping issue. A couple of thought/questions on the code problem, do you have the voltage analog input going to pin 2 and the current analog input going to pin 1? If you switch them does the 40 you used to have for voltage now display for current? Have you measured the outputs of the hcpl's with a multimeter or oscilloscope? Do they center at 2.5V? If you have a multimeter what is the rms voltage value it gives for both outputs? 

Trystan