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
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
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:
- Download the Arduino sketch (there are 3 sketches, open SAmeasurement.pde and the other two should be included automatically)
- 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.
- Check that values are being sent from the Arduino in the Arduino serial monitor.
Step 2 – Computer side
- Download the ArduinoComm java program here.
- Unzip ArduinoComm.tar.gz
- Compile the program by typing $ javac *.java
- 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:
- Decide on the current range you want to measure, say 0 to 16A
- 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.
- 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.
- 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.
- 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).
- 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.
- 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.
- Adjust the gradient value until the mean is zero this may or may not reduce the standard deviation.
- 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.

