Measuring AC mains energy use non-invasively with a CT sensor and power adapter

 

This is version 2.0 of the mains AC energy monitor, the current version is version 3.0, it can be found here

This method of measuring mains AC electrical energy use is quite nice, it doesn't require any direct contact work with the high voltage mains electricity, which makes it nice and safe. The method measures current and voltage and can therefore calculate useful values like real power, apparent power, power factor, RMS voltage, RMS current, frequency and cumulative kwh. 

Note: Currently works with single-phase 2 wire distribution system such as used in many homes in the UK. A 2 wire system has one live wire and one neutral wire. As far as I understand if you're in the US you are likely to have a 3-wire single phase system were you have one neutral wire and two live wires each of which carries 120V. This makes it possible to power 240V appliances (see the wikipedia article in the link and hyperphysics for a nice diagram), you may also have one life wire powering one side of the house and the other the other side..? And so if you want to measure the total energy consumption you need 2 CT sensors and 2 copies of the current sensor electronics. I will make an adapted arduino sketch for this configuration when I get a chance but the main change to do is a repetition of the current measurement real power sum code for the second CT and then:

Real Power = real power legA + real power legB.

Apparent Power = (IrmsCT1 + IrmsCT2) * Vrms;

Were Vrms is measured between Neutral and one of your live legs, see below for further discussion on this.

If you have a 3-wire single phase system and would like to help out by testing this, please get in contact.

This guide first details the current measurement using a CT sensor, then the voltage measurement using a power adapter and lastly a section on getting power as well as a voltage measurement from the power adapter.

Current measurement

Sensor

From the Efergy shop for £7.50

The current in the mains wire is measurement using a sensor called a current transformer (CT). A CT sensor works by effectively measuring the magnetic field created by the current in the mains wire. The sensor produces a small secondary current that is proportional to the magnetic field. In the case of the efergy elite sensor used here the secondary current is 1500 times smaller than the current in the mains wire.

The sensor just clips around the wire to be measured which means that it can be used to measure the electrical energy used by a whole building. It a sensor used by many commercial devices that you can buy.

Sensor Electronics

To convert the current produced by the CT sensor to a useful voltage for an arduino to read we place a small resistor in parallel with the CT to produce a voltage proportional to this current. The voltage is then biased (shifted up) by 2.5V using a voltage divider. This allows measurement of both the negative and positive component of the waveform due to 0 - 5V input requirement of the Arduino.

Here's a schematic of the current measurement circuit:

The value of RsensI determines the current range that can be measured. For example If you use a 56R resistor and a CT sensor with a current reduction factor of 1500 then the maximum current that can be measured can be calculated as follows:

Arduino has voltage input range of 0 to 5V, our voltage waveform at the input pin is centered at 2.5V and therefore it can have a max amplitude of 2.5V so as not to exeed the arduino input voltage requirements.

The current in flowing through RsensI is given by Isens = Vsens / RsensI

Vsens max = 2.5V, RsensI = 56Ohms and so Isens = 2.5 / 56 = 0.045Amps

The sensor has a current reduction factor of 1500 and so the max peak current that can be measured is 67Amps.

This corresponds to an maximum RMS current of 67 * (1/sqrt(2)) = 47Amps

Which at 230V gives a power measurement range of 0 to 10810W.

Voltage measurement

Update 24 March: I'm leaning towards using a seperate power supply for power and voltage measurement at the moment as it gets rid of the interference problem caused by trying to measure the ac voltage from the same transformer used to power the arduino using a bridge rectified power supply. I will update soon with circuit diagrams and more details, but in the mean time the main jist of it is:

- One AC-DC 9V power adapter to provide power to the arduino. 

- One AC-AC power adapter with a 10k:100k voltage divider across it to step down the voltage further and 10k:10k voltage divider to bias the ac voltage to keep it within the 0-5V range of the arduino.

Sensor


From Farnell

The voltage is measured using an AC to AC step down power adapter. The power adapter steps the voltage down from 230V AC to around 9V AC. Using the power adapter method rather than making a direct measurement on the high voltage side maximizes safety as no high voltage work is needed.

Sensor Electronics

As with the current measurement the voltage produced by the power adapter needs to be converted to a voltage that the arduino can read.The two 1M and RsensV resistors make a voltage divider that reduces the voltage waveform amplitude further and the 6.8K and 27K resistor biases the resultant waveform by about 4.0V.

When the voltage adapter is also used for powering the arduino there is some interference with the voltage measurement circuit. Biasing by 4.0V instead of 2.5V and using the two 1M resistors minimizes this interference.

Taking a voltage measurement allows us to gain more information about the energy use than a current measurement alone, real power and power factor can now be calculated and its also easier to measure the grid frequency than with current measurement only.

Here's a schematic of the voltage measurement circuit:


 

RsensV determines the amplitude of the voltage waveform. We are centering the waveform around 4.0V and so the amplitude must not be more that 1.0V. Im using an 100K resistor for RsensV which reduces the amplitude by 20times. Interference from using the same power adapter for power is minimized by making the amplitude of the measured voltage waveform as small as possible, its seems to be a matter of balancing having enough amplitude to get enough information from the voltage measurement and minimizing interference.

Powering the electronics from the same power adapter used for voltage measurement.

In addition to using the power adapter for the voltage measurement it can be used to power the electronics. This does have a slight interference effect as mentioned above but can be minimized and from what I can tell is pretty negligible, maybe a small price to pay for the elegance and cost saving of just having one power adapter (edit: I'm going to try a half wave rectifier power supply circuit for the next version to see if this can be improved - see post below)

The power adapter gives an AC output needed for the voltage measurement and so we need to convert the AC output to DC for the arduino. This is done using a simple circuit consisting of a bridge rectifier and a large capacitor.

Here's the schematic:

I have assembled the 3 parts above on one circuit board which is document below. If your interested in the current measurement alone have a look here.

Full circuit schematic

Here is the circuit schematic for all the parts above in one circuit:


 

How to build it

Step 1: Gather all the components. Here's the full list of the component for the whole house energy monitor, the measurement board components are the first block.

Download OpenOffice: partlist28Jan.ods

Download Exel: partlist28Jan.xls 

Google Docs

Step 2: Assemble the circuit board. The pictures below show both the top and bottom of the board that I made, but please feel free to assemble it anyway you like. I was intending to write up a step by step assembly guide as I did for the last current sensing board but realized about halfway through that I was not assembling it in a very sensible order and I made a couple of mistakes. Step by step pictures of that assembly can be found here but I think an easier way to assemble the board would be too build from shortest to highest components. Starting with wires, resistors that are flat to the stripboard. Then the headers. The vertical resistors, the terminal blocks, rectifier, and then finally the capacitor. Anyway here are the main pictures of the circuit board top and bottom. For more pictures of the circuit board from different angles have at the picassa album.

Top view:

Bottom view:

Its quite fiddly to position the headers vertically, the easiest way I found to position them is to put a short piece of wire in to each header and then place them upside down with the piece of wire in a breadboard, the stripboard can then be placed on top of the header legs making it easy to solder the headers in, this picture may make it a little clearer.

I also find a bit of blue tack can come in useful in holding components and wires in place while soldering.

Software side.

The Arduino sketch coverts the raw analog read values to useful power and energy information and then prints them out to serial, which can be read by the ArduinoComm program below.

Step 1 – Arduino software:

  1. Download the Arduino sketch (there are 3 sketches, open SAmeasurement.pde and the other two should be included automatically)
  2. Compile and upload the Arduino sketch to the Arduino. For a guide on compiling and uploading the sketch to the Arduino have a look here.
  3. Check that values are being sent from the Arduino in the Arduino serial monitor.

Step 2 – Computer side

  1. Download the ArduinoComm java program here.
  2. Unzip ArduinoComm.tar.gz
  3. Compile the program by typing $ javac *.java
  4. Run the program with $ java Program

For a guide on compiling and running java programs have a look here. (It also details installation of rxtx library)

For more information about ArduinoComm visit this page

If its all working you should see something like this appear in your terminal window:

416.52 426.64 0.98 245.34 1.74 49938.92 0.03971
414.92 425.4 0.98 245.6 1.73 49937.19 0.03996
414.7 424.79 0.98 245.72 1.73 49939.88 0.04021
413.23 423.43 0.98 245.56 1.72 49943.71 0.04046

From left to right we have: real power, apparent power, power factor, rms voltage, rms current, frequency, kwh.

Now clip the sensor around the live wire of a test power strip as in the picture below and connect up a load something in the 100W range. The value for apparent power and Irms should go up but you will need to calibrate as described below to get accurate values.

Calibration

The power values calculated probably wont be correct if you compare it with a commercial plug in meter even if you use the same components specified above. I have a couple of CT sensors now and each one seems to give slightly different results from the other as if they have not been coiled with the exact same amount of secondary windings and so we need to do some calibration to get more accurate measurements.

To calibrate you need to get a plug in meter like this one that can measure the RMS voltage and RMS current. (Be sure that it does measure true RMS and not just the peak/sqrt(2) as many multimeter's seem to measure)

Calibration steps

Calibration spreadsheet example: 

CalibrationExample.xls

CalibrationExample.ods

  1. Decide on the current range you want to measure, say 0 to 16A
  2. Decide how many measurements you want to take along that range, the more the better but around 10 sets of Vrms and Irms is ok. Try and make the distance between each measurement as equal as possible. Take multiple readings at each point if you like. However you should be able to see an erroneous reading when it stands out from the whole set, If a reading looks erroneous re-check the reading to see if the error disappears.
  3. Make a table of Plug monitor Vrms and Irms measurements and corresponding Arduino monitor Vrms and Irms measurements.

Repeat the steps below for the Vrms and Irms values to find factorA and factorB.

  1. Create a scatter plot with the arduino monitor measurements on the x-axis and the plug monitor measurements on the y-axis and plot a line of best fit, and get its equation. 
  2. Create a third column and apply the gradiant value from the equation of the line to the Arduino monitor measurements ( which are x) this gives you the expected arduino measurements once you have applied the calibration. For discussion on what to do about the "offset" (c in y=mx+c).
  3. Create a fourth column with the values from the 3rd column minus the plug monitor measurements this gives you the expected error of your measurements once you have applied the calibration.
  4. Calculate the standard deviation, min, max and mean of the error and if you like make another scatter graph of the expected value versus the expected error. The standard deviation indicates the precision of the measurements. The mean indicates the accuracy of the measurements.The goal is to bring both the standard deviation and the mean as close to zero as possible.
  5. Adjust the gradient value until the mean is zero this may or may not reduce the standard deviation.
  6. Use this gradient value to correct the factorA/B you used to make the above measurements which is in the Arduino sketch:

double factorA = (25.7488 * factorA_correction);

double factorB = (777.75 * factorB_correction);

Hopefully with this calibration your measurements will be significantly more accurate than they were before. Your now ready for the next stage!

Accuracy and Precision

Current

In range 0 to 16A. Circuit is configured for max 47A, but comparison is with a plug meter that has max rating of 16A.

  • Max/Min error +-0.1A
  • Standard deviation of error +-0.06A

(Plug meter precision: 3% of measured value or +-0.03A?)

Voltage

  • Max/Min error +-2V
  • Standard deviation of error +-1.0V

(Plug meter used for comparison only displays +-1V, which made it hard to make a very accurate reading)

(Plug meter precision: 3% of measured value)

I need to check these again:

PowerFactor

  • Standard deviation of error +-0.03

RealPower

  • Max/Min error +-30W
  • Standard deviation of error +-15W

(Plug meter precision: 5% of measured value)

ApparentPower

  • Max/Min error +-24VA
  • Standard deviation of error +-12VA

(Plug meter precision: 5% of measured value or +-10VA?)

Extend it

Next you may want to take it further and do useful things with it by extending it or if your following the home energy monitor build instructions click here to go back to the home energy monitor build page

Further Development questions

This project is always a work in progress, the hardware and software above is probably not a finished design. I am quite happy with the accuracy achieved so far with the above method but I'm also learning while doing this project and so some of it may well be done in an incorrect way? and could be done better.

Here are a couple of lines of inquiry that may be interesting to look at to get to the next stage. I may get time to look at some of them but probably not every line so please feel free to take any of them up and if you have any suggestions as to the best way to go, it would be great to hear them!

A few further development question: 

  • Is the voltage divider scale to voltage divider bias voltage measurement method above combined with a  bridge rectifier (floating?) power supply method a sufficiently accurate way of making the voltage measurement? Are there better or easier ways of doing this to achieve higher accuracy?
  • Maybe the secondary windings of the power supply transformer could be center tapped to achieve grounded full wave rectification...

Thanks to Danny who commented below, bringing this question up. I intend to give a half wave rectifier - grounded power supply a go when I get a chance to see if it yields an improvement. Does any one else have any thoughts on this?  

  • Capacitors? filter capacitors, ac coupling capacitors...
  • Atmel AVR 465 app note uses a programmable gain stage to increase accuracy at lower currents, should this be investigated?

  • Testing of 3-wire single phase implementation.

  • Are there any other further development questions?

Thanks to Suneil for suggesting that a further development's section may be useful.

Hi again Trystan - I managed

Hi again Trystan -

I managed to get a simple non-invasive whole-house monitor going, but it's very rough still. (The IR pulse detector doesn't work in the sunlight) :) But on the upside it was simple, and cost almost nothing for parts aside from the Arduino. And it should be very accurate since the meter is doing all the hard work for me.

As I said, I've been gearing up to do a CT monitor setup like yours, but I realized a couple things... in the US we have 2-phase power, so of course we'd need 2 CTs on the mains. But I'm wondering if, for voltage & power measurement, we would need to measure across both phases to be accurate.

Further, I wonder how much the voltage differs on different branch circuits, and whether a single point of voltage measurement is sufficient for computing power on each of the branch circuits...

I guess I have more reading/studying/researching to do. :)

Hey Eric The IR pulse

Hey Eric

The IR pulse detector method looks very neat, nice work! I like the pachube graphs you've got going too. 

That's a good question on the voltage, If one leg is heavily loaded then it should have a slightly lower voltage than the lightly loaded leg. It would be interesting to see by how much the voltage varies on each leg, and whether the difference warrants making a second voltage measurement? I imagine the drawback of making a 2nd voltage measurement as well as already measuring two leg currents is that you'd start loosing a fair bit of resolution in time for the sampled waveforms...

I made a 3 wire single phase LTspice simulation to better see what is going on here which may be useful: http://openenergymonitor.org/emon/sites/default/files/3WIRE.tar.gz

I tried to see if I could find anything on the internet on differences in voltage, but didn't come across anything, I probably haven't looked in the right place as is with these things. If you come across anything or do some measurements I and I'm sure others would be interested in hearing about it :) 

Trystan

Regarding resolution in time

Regarding resolution in time ... you just mean that you'd have to round-robin service all the measurements, so you'd get updates less often, right? I guess I don't see that as a huge problem, even if we were measuring 20 channels, we'd still get fairly frequent updates, no? If we wanted to keep updates constant int time, then we'd have to drop the resolution of each measurement, I guess.

 I was thinking more of the

 I was thinking more of the sample rate for calculating each real power, apparent power etc... if your taking 2 voltage analogRead()'s and two current analogRead()'s and doing all the extra multiplying and summing the time between each instantaneous measurement (the sample rate) will increase... but maybe its not really a big problem :)

I notice your project is

I notice your project is referenced from SeedStudion on their CT: http://www.seeedstudio.com/depot/noninvasive-ac-current-sensor-30a-max-p...

Is there a reason why you aren't using this CT? Did you ever get it to work, or are they just referencing you as a project. I am in the US and like the cost $9.95 for that CT, but I notice some differences. It references a built in Burdon Resistor but I can't find any detail on the current output ratio. It looks like it might be 1V at max current (30A) but I'm not sure.

Any info you might have on using that CT, would be greatly appreciated.

Regards,
Curtis

 Hey Curtis  The only reason

 Hey Curtis 
The only reason I'm not using the SeedStudio CT myself is that I can get a CT sensor from efergy in the uk for £7.50.  I know that Hendrik who has been building the circuit has used the seedstudio sensor and had good results with it. He found the internal burden resistor to be 62ohms I think and the turns ratio to be about 1:1900 which works out to be pretty close to 1V at 30A. 
Hope that helps
Trystan

Excellent...thanks for the

Excellent...thanks for the info! I'm actually working on a design that uses the Microchip MCP3906A chip which does the power calculations and outputs a pulse that represents the real power. Your site has been very valuable as a learning tool about the CTs and using a 9V step down transformer. My goal is to build something small and cheap enough that you can monitor every circuit in the panel to get a better idea of what parts of your house are consuming the most power. I will post some more info as I have something working.

Curtis, I'm considering the

Curtis, I'm considering the same sort of thing (CTs on branch circuits) - I had planned to just expand on what Trystan had done, but possibly with an analog multiplexer to switch between, say, 16 inputs. The chip you mention sounds interesting but I guess you need one for every branch circuit?

Have you found a good source for the branch circuit CTs? We ordered some from CR Magnetics - they seem reasonably priced and as a bonus, they have spec sheets. ;) Will let you know how it goes.

-Eric

I have looked at the CR

I have looked at the CR Magenetics CTs...they look really nice. The one thing that turned me off about using a CT without integrated burdon resistor is the safety factor. I understand that without the burdon resistor on it, there can be safety issues with opening it up while not connected to anything, or putting it on the wire not connected to anything. I have ordered a couple of the seeedstudio 30A CTs to use for testing and have a board design 80% done.

Yes, you would need one of the MCP3906A chips for each circuit. The thing that intrigues me about that is it has a 16bit ADC integrated and can give you 1W resolution. It is designed for power metering and conforms to the international standards, so accuracy is probably a lot better. My hopes is that I can build the monitoring for each circuit for less than $25. Since I have about 40 circuits, that comes out to about $500 for the whole solution.

We'll see how it works out. As I make progress, I will try to blog about it.

Curtis

Yes, this is what i would

Yes, this is what i would like to have. A monitor capable of watching all circuits.

Excellent write up! Thanks

Excellent write up! Thanks for putting it up. I ran into an article that you be interested in, http://www.waset.org/journals/waset/v56/v56-148.pdf.

Dawn

 Hey thanks! looks like a

 Hey thanks! looks like a useful and interesting article, I will have a good look at it! 

Hi Trystan I'm finding it

Hi Trystan

I'm finding it difficult to obtain an AC to AC step down power adapter that outputs 500mA. The smallest I can get is 1000mA. Can I use this or will it smoke my arduino duemilanove?

Tnx

Louis

 Hey Louis, 1000mA is fine,

 Hey Louis, 1000mA is fine, the arduino will draw the amount it need's from the ac to ac step down power adapter and will therefore not smoke the arduino :) I specified 500mA to be safe and its the same amount that a USB connection can supply but a 1000mA is completely fine.

Hi Trystan Thanx for the

Hi Trystan

Thanx for the quick reply. One more question and one suggestion.

Question: Would 1.5A 200V Bridge Rectifier work? Sorry, my knowledge of electronics is very slim, but rapidly growing ;)

Suggestion:

To bring the total cost of the monitor down, would it not make more sense to to get a GPRS shield like the one from Libelium?

That way, you would only need 1 arduino with the Gprs shield that could log data to an online web server?

OK, one more question. Are there any circuit diagrams that would show me how to make my CT wireless with RF modules like these:

http://za.rs-online.com/web/search/searchBrowseAction.html?method=getPro...

At the moment I' using my PC to send arduino data to the internet, so I need to be able to get the CT data to the arduino wirelessly from my DB board.

Hope I'm not making too much of a nuisance of myself.

Louis

Hi Sorry, forgot to specify

Hi

Sorry, forgot to specify for he rf module: I want the CT to communicate with the arduino without using another arduino.

Hope this makes sense

Louis

Hi Louis Yea, your rectifier

Hi Louis

Yea, your rectifier should work fine, what's its forward voltage? Some higher voltage rectifiers have higher forward voltages than lower voltage rectifiers and so would have larger losses. The one I'm using is 50V 1.5A and has a forward voltage of 1V.

Sure you could use a GPRS shield although the cost of the shield I think is more than an extra arduino and ethernet shield? so might not bring the cost down but would be pretty cool! I'm going to make another energy monitor for a house down the road using just one arduino doing measurement and ethernet :)

I'm not sure what your best bet is with not having an arduino on the sensor side is. Maybe you could use an Xbee wireless link, adafruit's Xbee's have ADC's in them and so could send the analog reading from the CT to the arduino for processing. But I'm not sure if it would be fast enough for accurate readings. 

Have you seen these RF modules, they would still need an arduino as they relay serial data but are pretty cheap: http://www.coolcomponents.co.uk/catalog/product_info.php?cPath=25&products_id=186

Maybe the one of the arduino's could be a cheaper small one: http://www.coolcomponents.co.uk/catalog/product_info.php?cPath=50&products_id=176

I will let you know if I come across something that does what you want and is much cheaper than using 2 arduino's and the rf link above. 

Another question: Looking at

Another question:

Looking at the schematic how can you have 5v in and gnd tied to the same leg of the ac input voltage? I am confused am I missing something.

 5V and GND and the 2

 5V and GND and the 2 resistors produces a voltage divider that outputs 2.5V - which biases the ac input voltage to "center" around 2.5V instead of 0V and therefore the voltage at the arduino stays within the range of 0 to 5V, does that make sense?

Yes I agree that is what you

Yes I agree that is what you are trying to do and I understand that part. My problem is that I believe you would need a couple things to achieve it.
1. A cap in series to ac couple the signal into the arduino.
2. GND on you divider needs to be tied to the other leg of your ac signal.

See link for pic of what I am describing. This is taken from single phase power meter appnote465 on atmels website.

Schematic

Ok Got it figured out. I see

Ok Got it figured out. I see what you are doing now I redrew the schematic. It makes sense, the only missing component would be a series cap on the adc input. Originally the way it was drawn I didnt understand how the divider and biasing worked.

Hey, sorry I

Hey, sorry I misunderstood/misread your first question, you were referring to the voltage measurement part of the circuit right?

Thanks for the link to schematic and app note I had a read through and studied a couple of other app notes as well, they all as far as I can tell seem to be using half-wave rectifier circuits for the power supply which if I''ve understood correctly allow's it to be a grounded supply.  The power supply circuit that I'm using uses a bridge rectifier which means that it is floating or ungrounded. I think maybe I'm wrong in trying to use a bridge rectifier circuit instead of a half wave power supply circuit and this is probably the source of the interference I mention above, so thanks for pointing out the app notes.

Here's the LTspice circuit for the voltage measurement and power supply circuit above,  it seems to give a near-sinusoidal voltage output: Vmeasurement.tar.gz 

and here's the LTspice circuit for the half wave rectifier circuit that you linked to with the ac coupling capacitor, it also seems to give a sinusoidal output but maybe a bit better than the bridge rectifier circuit: halfwave.tar.gz

So I think I will try the half wave power supply for the next version of this circuit with the ac coupling capacitor, although the current version does seem to work: the real power, power factor and apparent power measurements seem to compare well with the values I read off the plug meter.

In your last post you mention needing a series cap on the adc input, is that in the same way as the ac coupling capacitor with the voltage divider after it? a series cap direct to the adc input without the biasing voltage divider wouldn't work as it would remove the dc bias, right?

Thanks for raising the questions about the circuit, I think I have learnt a bit more from them, and will post up the results of the half wave power supply circuit as soon as I get a chance to build it.

Yes I meant in series with

Yes I meant in series with the divider after it, not direct to adc input.
My blog from a year ago were I was attempting to build my power meter. I have been side tracked to other projects(1-wire,power meter wheel monitor, and others), but I plan on getting back on it next.

>In your last post you mention needing a series cap on the >adc input, is that in the same way as the ac coupling >capacitor with the voltage divider after it? a series cap >direct to the adc input without the biasing voltage divider >wouldn't work as it would remove the dc bias, right?

 Hey Danny, looks like you've

 Hey Danny, looks like you've made a good start, let me know how you get on with it.

Partslist files not working.

Partslist files not working. Thanks

 Thanks for pointing that

 Thanks for pointing that out, should be working now.

Could you make partslist a

Could you make partslist a public doc on google docs. It will take a straight upload of excel or open office.

 No problem, done.

 No problem, done.

Thanks.

Thanks.

I looked at everything you

I looked at everything you have here. I am actually considering building a power logger using an AVR also. I was concerned that I would not be able to sample at a fast enough sample rate to get accurate data, while performing all the other required tasks like calculations and data logging. Do you know what your accuracy is with this setup?

 Just updated the page with

 Just updated the page with accuracy and precision information above. As for sample rate, what you do is first do the measurement of the values you need and dedicate all resources to that. I take 6000 samples for each set of measurements. 6000 samples takes about 2 seconds which is a sample rate of about 3kHz. As soon as you finish taking the measurements you then dedicate the next half second or so to usb logging, display updating etc.

Thanks for the info I will

Thanks for the info I will review the data on the page.