Go Down

Topic: Measuring phase angle and power (Read 11308 times) previous topic - next topic


Hello, It's been a while since my last Arduino project so about time I did  another.
I've had a set of Solar PV panels installed on my roof that is grid tied so that any energy I don't use gets sent out to the national grid. I want to ensure I don't export anything that I will later need to do when the sun goes down.
My plan is to measure how much energy I'm exporting and power control a water heater so that it mops up the exporting power and results in zero export.
As I'm in UK I'll be fiddling with 240V 50hz.
This is how I think I can achieve it but will welcome any other ideas.
As far as I know the only way I can detect if I'm importing or exporting is by measuring the phase angle between the voltage and current of the supply. To do this I'm thinking of using a current transformer and a voltage transformer to give me 0 to 5 v inputs on the Arduino analogue pins. I would then need to detect the zero crossing of each wave form and work out the phase difference. Once I have the phase difference I can then easily calculate the actual power flow and in which direction it's going. This data would go via Ethernet to the power controller to do its thing. I'll leave the Power controller for now until I get the first stage done.
Has anyone done anything like this before? Is the Arduino quick enough to calculate the zero crossing of both and compare them with any sort of accuracy? I don't need to calculate the angle and power every cycle (2ms) every second or even 5,10 seconds would do. Thanks.


You may want to search the old forum as I think there have been similar discussions in the past.
Google forum search: Use Google Advanced Search and use Http://forum.arduino.cc/index in the "site or domain:" box.


Thanks, I have had a scan through the old one but couldn't find it. The problem is (I suppose) is there are many different ways of describing the project. I'm actually thinking it would be an easy and cheap job to spot the zero crossings with a couple of comparator chips, two for the current and two for the voltage then either feed this in to the Arduino or into an edge triggered flip flop and feed the resulting pulse in to the Arduino for analysis.


You may want to look at the below for info.


Google forum search: Use Google Advanced Search and use Http://forum.arduino.cc/index in the "site or domain:" box.


Some interesting posts I should have searched for power factor. Thanks.
There are some folk on here that obviously know their stuff on this subject.
Could I ask the experts?
1, Am I right that I will be able to spot if I'm importing or exporting by calculating the phase angle?
2, Is it likely that if I use a voltage transformer for the volts  and current trans for the current that the phase change in the relative transformers will be somewhere near the same and thus cancel?
3, Can I tune out the phase angle distortion with capacitors or will this be so load dependant that getting it spot on for a 5Amp import it would be still way out for a 50A load?
I've ordered a few components like a CT and some discrete so I'll start knocking up a circuit next week. I have an oscilloscope so I should be able to measure the phase distortion and maybe even compensate for it in the code.


Take a look at this site http://openenergymonitor.org/emon/  Trystan has been working on this a while now and you should be able to get some good ideas.
Trying to keep my house under control http://www.desert-home.com/


You don't want the phase angle, its the product of I and V you want, summed across the cycle - the angle is affected by reactive loads and is  ill-defined if the waveform isn't sinusoidal.   In fact in a well behaved non-reactive system the phase would switch from 0 to 180 degrees as net power flow reversed, but you want more than just the sign of the power flow, you want the actual value...

I think the hard part is getting the voltage value safely - you want the voltage difference between live and neutral ideally without connecting to either(!) - In practice a low-power mains-rated transformer can be used to convert this and step it down for sampling - overkill compared to a few resistors but direct connection to the mains is a definite no-no.
[ I won't respond to messages, use the forum please ]


I had intended to use a small mains transformer and hoped that the phase angle change caused by the transformer would be something similar to the change caused by the CT. I have all the components now including some dainty CT's. I'm not sure why you say I don't need the phase angle? I want to be able to measure the power but also detect if I'm importing or exporting so I thought analysing the phase angle would be the only way. If indeed it approached anywhere near 180 degrees then this is great for spotting import/ export even with a pretty crappy phase distorting cct. This wouldn't help me actually measuring the power though.  As my intention is to maximise on the usage of my generated power maybe I don't actually need to calculate the power just simply look at the phase angles and keep incrementing the load until it swings around the other way then back off a bit to ensure I'm exporting, but only a small amount.  This has given me further food for thought I'm now warming to the idea of not bothering to calculate the power at all.
Another thing I considered is I've got a gadget called a power meter made by a company called workzone. You plug a device in to it and then plug it into the wall outlet. This thing purports to calculate power factor power and measure volts/amps. I'm thinking I could possibly hack this to get the data I need in to the Arduino.


Although it's been too long since I listened to the drone of an EE instructor on this, I can't remember the phase angle being the important item.  Tell me if I'm getting this wrong, but the two things you need to know most are the zero crossover point and direction of the voltage curve at that point.  This is to make sure that you match the utility both in timing and direction of voltage.  The power companies around me have a 1% tolerance on zero crossover and don't mention the voltage except for maximums.  I think that's because as long as the timing and direction are ok, and you don't exceed the maximums it'll work.  Your inverter should take care of that stuff for you.  Unfortunately, since they are tied together and the inverter is working hard to make them the same with a tiny increase in voltage to transfer your production to the power company, it will be hard to tell if you're pushing power out or taking power in except for the metering provided by the inverter company or power company.

By no means does any of this make what you want to do impossible.  I suggest that you build a basic power meter based on Trystan Lea's work with the current transformer around the power input to the grid from your supply.  If it shows power coming from you to the grid, that's exactly what you want to know.  Another CT around the grid input to your place will tell you net usage and a little algebra would get you all the info you want.  In the US I can do the same thing, but I have to double the number of CTs.

As for the arduino being able to handle the load.  I think yes.  I'm sampling power many times a second and averaging the readings with CPU cycles to spare.  You should be able to measure more than one thing at a time and do the necessary calcs as well.  There is the caveat that you have to use floating point math and that really eats the time, but with two inputs I don't think there will be a problem, or if there is, another arduino is not too bad a thing.

Feel free to snag the code for my power monitor at http://draythomp.blogspot.com/ but remember that I have two CTs and you'll have to change the code to adapt.

As for noise, that can be a real nuisance.  I recently installed a permanent magnet motor and it creates a ton of noise.  My power factor dropped from almost unity to as low as 80% at times (high load) and the power line noise permeates the house and makes power line communication systems fail.  Working on that problem right now, I am.  However, the power savings are really going to make it worthwhile.  I don't think trying to eliminate this factor in software will work due to the mess noise makes of the power waveform.  However, if your measured power factor is high enough, it won't matter anyway.

However, your work on measuring the power and your systems reactance will tell you a whole lot.  So, have fun with the current transformers and don't worry too much about the dangers people love to scare you with.  Just turn the power off, do it, turn the power on.  I'm sure you have enough common sense to handle it just fine.  I'm basically an uncoordinated idiot and I managed it just fine.
Trying to keep my house under control http://www.desert-home.com/


Hmmm, I've tried to post a piccy of my set up without much luck. Anyway it wasn't a master piece.
The elecktrickery comes in to my house through a fuse then through the meter (which only measures import energy) in to the main fuse/distribution box.The solar panels go through a generation meter then an isolator then connect up to the same main fuse board along with all the other domestic circuits. I could measure the current on each of the circuits and do some simple algebra but it would involve some 10 to 12 CT's. Thanks for the offer of a bit of code that may save me a fair bit of time come the day. I work in a power station so don't have any problems fiddling with domestic voltages. You would think working in a PS I would be surrounded by people that know all the inns and outs of import/export but alas their solution is to buy a device for x0000£ that will do it all for you.
Just detecting if I am importing or not is my main problem, measuring what the actual power is , is a secondary thing. Unfortunately my electricity suppliers don't put a meter in for export they know how much the PV panels generate and assume you will export 50% of it and pay you accordingly.


Now I totally understand why you want to measure your export!!  It wasn't clear to me because solar folks in my area have 'net' metering.  In your case, what I would do is CT around the mains coming in and look for it to drop way down due to your solar taking the load.  As long as your drawing a few watts off the company, you can store the rest in batteries or something for later.  If you manage to drop the mains to zero, you're giving power to them.  You could also measure the output of the solar panels in DC before the inverter and extrapolate the lose through the inverter for an estimate.  A piece of stainless steel can be a nice shunt resistor in cases like this.

Did I get that right??  Heck, I'd divert my solar panel to heating or A/C or anything else before I just gave it away.  Maybe an ice maker for late afternoon margaritas or something.
Trying to keep my house under control http://www.desert-home.com/


Yep you got it. The elecktrickery people know they are on to a good thing for most folk as they are out for most of the day and go on hols etc when the most generation days are prevalent done. So the total point of this project is to make sure I don't export anything or very little IE put the excess in to a water heater or ice maker as you say. Wherever the power goes it's got to be able to be power controlled IE will run from 100watts up to near 4 Kws.


If you expect the power company to pay you for supplying reactive power, you will probably need commercial grade metering on which to base your billing. If you work in a power station then you probably have heard of reverse power relaying and metering schemes, which could be a source of info. Directional power metering has been around since the implimentation of large power grids, so research on the subject may provide some DIY solutions.
Google forum search: Use Google Advanced Search and use Http://forum.arduino.cc/index in the "site or domain:" box.


My supply company doesn't know if or how much I export. They simply ask me for a reading from the generation meter fitted near the solar panels they then pay me for every KW I generate they then pay me a further much smaller amount for 50% of what I've generated as they assume I will export 50% of what I generate. I don't particualrly care about the actual power, reactive or otherwise r I simply  want to make sure I don't export anything (or very little) as I can't see the point exporting during the day then importing during the night to do the same job IE heating water.
Yep reverse power meters/ switches are prevalent but didn't uncover any real DIY versions.
I have a plan now and have just finished knocking up the conditioning board out of a few discrete. I'll be in the testing stage when I get around to it next.
Thanks for your interest chaps.


I can't see the point exporting during the day then importing during the night to do the same job IE heating water.

Double insulate your water heater, set its thermostat as high as it will go, and put a timer on its power supply such that it won't start heating until the solar panels are usually out putting sufficient to provide the heating power.
Google forum search: Use Google Advanced Search and use Http://forum.arduino.cc/index in the "site or domain:" box.

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131