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

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.
The invasive method is however more accurate than the non-invasive method since it measures the voltage directly rather than estimating the voltage waveform. It is the method used in most plug-type power meters.
I also found this method really useful for initially learning and getting my head around how electrical energy monitoring works, most of this is down to the great work by Cliff Jao and Xi Guo on the PowerBox project. The device detailed here is an Arduino adaption of their design.
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 havent as yet established why this is. 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 of any use to anyone.
How it works
Brief introduction
Theory
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
Once you have the electronics built the next step is to load a sketch to the Arduino. This sketch on the Ardunio does a whole load of processing on the measurements detailed in the electronics section before sending to the computer useful values for real power, apparent power, frequency, rms voltage, rms current, peak voltage and peak current.
Steps
- Download the Arduino sketch: New version 16/10/09, Old version
- Compile and upload the Arduino sketch to the Arduino. For a 'How to' 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. You should see a continuous output of numbers broken by characters, something like this: 120.00A245.06B543.34C234.23D446.78E... and so on
Now that we are receiving values in the arduino serial monitor lets turn them into something a little more comprehensible and get the values in a form that they can be used for useful things like graphing.
The ArduinoComm java program does this job, it reads the values sent from the Arduino and then outputs the values to the terminal window.
To do this:
- 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 'How to' 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:
128.43 153.25 0.84 242.62 0.63
126.76 151.31 0.84 243.17 0.62
128.24 153.42 0.84 242.9 0.63
....
From left to right we have: real power, apparent power, power factor, rms voltage, rms current.
If you know you have say a 100W light bulb connected and the output reads something along the lines of:
105.34 107.65 0.98 242.2 0.44
Then great! you know its working, well done!
Now that the basic setup is working we can extend it so that the data becomes a bit more useful!