Go Down

### Topic: Measuring Mains Voltage (Read 5953 times)previous topic - next topic

#### draythomp

##### May 24, 2011, 08:50 pm
As some of you know, I'm on a continuing quest monitoring and controlling my power usages....successfully.  Now, I'm seeking input on a new phase of the project.  I want to measure the power to my freezer.  Yes, I could use a tweet a watt, but that's been done and I would like to create another solution.  My first problem is measuring mains voltage.  I have split phase 220 which means I have 110 at the plug for the freezer.  Why the heck can't I use a voltage divider?

Something like:  Hot wire -> 1M resistor -> some other value resistor ->1M resistor -> neutral wire.  I would measure the voltage across the middle resistor at the arduino and tailor the value to keep it in the 1-2 volt range.

There's a ton of posts on the web telling everyone not to do this because it will kill you.  Huh?  Sure the resistors could cook and short out putting the mains voltage at the arduino pins, but aren't there resistors designed not to do that?  I could put a 1 or 2 milliamp fuse in line as well.

What really are the dangers?  There are so darn many devices out there that connect direct and don't have a transformer that the danger must be overstated.  Doesn't it?

#### retrolefty

#1
##### May 24, 2011, 09:07 pm
Quote
My first problem is measuring mains voltage.  I have split phase 220 which means I have 110 at the plug for the freezer.

First it's important to understand what you really have avalible at your dryer outlet. Most dryers are 220vac and have a three wire plug, two hots (L1 & L2) and a safety ground, no neutral wire. You can only get (or measure) a 120vac circuit if you have the neutral wire along with either or both hot wires (L1 or L2). So only if you have a four wire dryer plug would you have the neutral wire avalible. The ground wire should never be used to allow continuous current to flow. It's designed, by code, to pass only fault currents and should not be part of a permanent measurement circuit.

So tell us what kind of circuit (3 wire or 4 wire) you actually working with and what you wish to measure. As far as voltage monitoring of any AC circuit, I would favor a transformer coupling to a lower safer voltage.

Lefty

#### draythomp

#2
##### May 24, 2011, 09:36 pmLast Edit: May 24, 2011, 09:38 pm by draythomp Reason: 1
Dryer?  Did I mess up?  This particular project is for the freezer.  The dryer will come, but not right now.  See, the dryer must be turned on by a human, and I can put a contactor in to stop a human from turning it on.  The freezer cycles on its own and goes into the defrost mode based on some timer inside it somewhere.  The idea is to eventually control it such that the fans in it can run, the compressor and defrost modes would be suppressed during peak charge periods and maybe an LED somewhere telling people to keep the darn door shut.

It plugs directly into one of those regular three prong plugs common on our walls in the US.

There are two problems with the transformers 1. cost and size  2. phase angle change that affects the power factor measurement.  The phase angle changes are not a big deal and I can only hope for a close approximation of the actual power usage, so I maybe could ignore that after I understand what the difference is.

See, I plan on building two of these, one for the freezer and one for the refrigerator.  By letting them talk to each other or setting aside time slices I can keep them from turning on their separate compressors at the same time.  Each one only uses a few hundred watts, but when they both come on, it can add up.  I can also keep the defroster off until off-peak billing periods, then let it run it's little heater to its hearts content.  But first I want to study the power profile of the devices; that means measuring and recording the power over some period of time.  And Yes, I realize that this project will probably expand to replacing most of the control circuitry in these devices.  But one has to start somewhere.

Heck, by controlling them properly I may be able to actually turn on an air conditioner occasionally, summer's coming.

#### Bobnova

#3
##### May 24, 2011, 10:13 pm
Ok here are my thoughts.  I'm not an expert, I have never done this, and quite honestly I wouldn't do this, mains voltage (actually 60hz anything, really) scares me badly.

At your 120v outlet you have a wire that is going from 170v to -170v.  Measuring the peak is going to be easier than anything else, so I'm looking at that.

A standard voltage divider that steps down to say, 4v at peak would work, but you'd get -4v as well.  You'll need a diode in there somewhere (after the resistor, and probably after the divider too unless your diode's breakdown point is >200v) to get rid of that negative voltage.

After that you need to check the voltage often enough that you catch the peak of the 60hz signal, it goes from high peak to low peak in around 8ms (and from zero crossing to zero crossing in the same.  This assumes it goes from +170 to +170 60 times per second), I figure the peak is probably a bit over 1ms long, you'll be checking that voltage mighty often!  Every ms if you want to be sure to get the peak.  Every time you check the voltage compare it to the previous voltage, if the new one is higher that becomes the previous voltage, if it's lower it gets dumped and the previous voltage is your peak for this cycle.

Beyond the danger factor, I don't see any serious defects in the above plan, but like I said I'm hardly an expert here.

Please do me a favor and don't kill yourself, remember that 60hz is a large part of what makes wall power so dangerous, if your fingers are damp even a much lower voltage at 60hz can still do you in.

All the above said, why not just shut down the fridge during peak cost hours and turn the "DO NOT ENTER" LED on?  That saves the power you want to save, and doesn't put you at as much of a risk of frying yourself.
Much simpler and safer, though I suspect the fridge might not like starting from "warm" every evening.

#### AWOL

#4
##### May 24, 2011, 10:16 pm
Quote
actually 60hz anything, really) scares me badly.

?
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

#### Bobnova

#5
##### May 24, 2011, 10:44 pm
60hz anything electrical I guess.  60hz humming doesn't.

#### draythomp

#6
##### May 25, 2011, 01:11 am
Thanks for the description.  I've worked with 120 @ 60 a lot, take a look at the power monitor I built  draythomp.blogspot.com it's behind the tab about how I monitor power.  What I'm looking for is why there is so much bad press about messing with the mains.  If you open an X10 device, it is hooked directly to the wall plug and these things don't seem to kill anybody.

See, a voltage divider would directly follow the power levels and I could sample it around 3K times a second to get the instantaneous levels.  There's no reactance from a transformer or capacitor to deal with so no phase delays to worry about in the calculations.  It just seems like the perfect solution, but there is post after post on the web telling people not to do this.  I just can't see why not.

The solution of turning the thing off is actually a darn good one, but I've got an arduino.....I just have to get it involved somehow.  The idea of monitoring the freezer to be sure the temp is low enough, controlling when it uses power, maybe tracking the door to see if someone is trying to steal a steak is pretty darn appealing.

#### draythomp

#7
##### May 25, 2011, 03:04 am
Quote
It is intrinsically unsafe connect direct to the power mains.  Anyone who comes here asking how to do it is assumed to be not experienced enough to recommend the practice to (at the risk of encouraging dangerous behavior.)

I've seen this over and over, the question is:  why?  I just don't accept that anything is intrinsically unsafe that is done by device after device that you can get in the marketplace.  Every single extension cord is connected to the mains.  Every X10 or insteon device is hooked to the mains.  Every wall wart is connected to the mains.  We mess with mains voltage every time we replace a socket on a table lamp.  Or, for that matter every time we change a light bulb.  The much touted kill a watt is connected to the mains.  This kind of thing just doesn't hold water if you actually examine the statement.  As for encouraging dangerous behaviour, don't encourage me, just tell me why it's dangerous to use a voltage divider.

Also, don't make assumptions about my experience level or the experience level of anyone else that posts. Assumptions about people's experience is not nice, ask if you wonder about it.

Quote
The safest way to measure power mains voltage is to simply use an inexpensive (perhaps even free) AC wall wart and simply rectify and filter the voltage. The DC voltage out of the circuit will be directly proportional to the RMS power mains voltage. And there are various ways of measuring current also. There are Hall-effect devices for measuring DC (or isolated AC), and there are clip-on current transformers, etc.

I don't want the rectified and filtered voltage stepped down by a transformer to what people assume is a 'safe' voltage.  I want the instantaneous voltage taken at many points in the cycle both above and below the zero reference; a filter would destroy that data.  I would rather not have the phase offset caused by the inductive load of a transformer, this can be calibrated away, but avoiding it entirely would be better.  I know about the hall effect devices and plan on using something like http://www.allegromicro.com/en/Products/Part_Numbers/0758/index.asp to get the instantaneous current.  That device will hook directly in line with wall power.

I'm not at all afraid of 110, 220, 440 etc.  I have a healthy respect for the current capability and the possibility of higher voltages causing problems that are somewhat unexpected, but I just don't buy that it's intrinsically unsafe.  It might be less safe, but one must take care with anything that one does.  Heck I've had 12V blow a hole in a 440 stainless adjustable wrench when I didn't pay enough attention an shorted a car battery; that's a voltage everyone on this forum has used.

So, now that we've both got that off our chests, what's wrong with a voltage divider?

#### retrolefty

#8
##### May 25, 2011, 03:26 am
Quote
what's wrong with a voltage divider?

One part I don't like about using a voltage divider for directly measurement with an Arduino is that one then must have a common ground connection from the arduino to the AC neutral. Also be aware that if you want to read an analyze the AC waveform directly with an arduino, you are going to need some op-amp conditioning to offset the voltage so that it is all within a 0 to +5vdc range, the arduino cannot handle the negative portion of a AC signal.

As far as if it's intrinsicly safe to deal with direct connections to household AC power or not, it's all about the knowledge and experience level of the person asking the question. The typical snarky response around here is that if you (not aimed at you personally, just posters at random) have to ask, you most likely shouldn't be fooling with it.

You should understand that there are a awful lot of very young user that post such kinds of questions or seek help dealing with AC power. We normally have no idea what their actual age or experience level is, so it's pretty understandable that many of us discourage practices like direct wiring to AC power circuits. It's not a reflection on you, but rather a general feeling of responsibility to encourage safe practices for posters new to the world of electronics.

Lefty

#### Jack Christensen

#9
##### May 25, 2011, 04:00 amLast Edit: May 25, 2011, 04:26 am by Jack Christensen Reason: 1

What I'm looking for is why there is so much bad press about messing with the mains.

IMHO it's the lawyers talking (present company excepted). But not without some good reason. Kind of like those car commercials (do not attempt, closed course, professional driver). How does a Kill-A-Watt do its thing? Back in the day, most all of my projects were powered via step-down transformers. And certainly there is a lot of safety and peace of mind there. Now I use these wall warts that have switching supplies in them, I don't think there's an transformer involved to provide isolation from the mains.

Certainly there are folks out there that might try something that they don't completely understand, and therein lies much of the danger. So first it's a matter of understanding very well what one is dealing with. From there, I can think of a couple major concerns. There may be more.

(1) Coming into contact with a mains-connected circuit always has the possibility of delivering a dangerous, potentially lethal shock. I sometimes have the bad habit of removing or adding components on a breadboard without cutting the power. With a 5V supply, there's not much danger to my person. Of course there is danger to my project. I could short something out and destroy some component. Depending on the component, it might just not be a good idea. But I usually think I know what I'm doing, so if I just want to change a red LED to yellow, I'll go ahead and do it. I wouldn't do it with an MCU. And I'd never think of doing such a thing if there was any mains connection whatsoever.

(2) The less isolation from the mains, the higher risk there is of some transient (lightning strike perhaps being a worst-case scenario) affecting the circuit, destroying it, or even starting a fire. I have heard it said that there may be insurance liabilities with homebrew mains-connected devices. So some thought to failure modes and proper design to either prevent a problem or to fail in a safe way is in order. This is a big part of what UL ratings, etc., are about.

So of course it can be done, and in fact it is done regularly, because all of those gadgets and appliances we all have plugged in are examples. But they are all designed in part by engineers who specialize in this very area. And yes, like a lot of things these days, the warnings are somewhat over-zealous, in a (perhaps futile) attempt to protect those that don't know that they don't know from themselves. (Lawrence Bullis had some interesting ideas on that score.) Personally, I wouldn't hesitate to experiment at bit, but at the same time I couldn't recommend it to anyone if I didn't know that they understood what they were doing. The risks (above, and probably others) need to be given some thought and mitigated appropriately.

I'm dating myself (I barely remember these), but consider the "All-American Five" radio.

#### draythomp

#10
##### May 25, 2011, 04:37 am
That's it Jack, you nailed it.  If I hook directly to the mains for my circuit, it will be fine until I turn the plug over.  Now, the hot side is in a different place and can cause some real problems.

That's exactly what I was looking for and no one ever mentions.  Sure I could put a polarized plug with a ground pin on it to keep myself out of trouble, but if someone copied my circuit and didn't.....boom.  It isn't that its unsafe to do this, it's like you said, someone else won't take the care that I (hopefully) did in setting it up or modifying it.  There are ways of avoiding the problems you pointed out (excepting lawyers), but it's hard to make something foolproof; fools are too resourceful.

Thank you.  I guess I'll go look for a really small power transformer that I can use to sample voltage and leverage it as a power supply for the rest of the circuitry.  The hall effect device will still be in the mains circuit, but it's optoisolated, doesn't care which leg it's in and UL rated to 3KV.

#### Jack Christensen

#11
##### May 25, 2011, 05:08 amLast Edit: May 25, 2011, 05:14 am by Jack Christensen Reason: 1
Good deal! No mysteries, just basic EE stuff. Interesting project you have there BTW. I'm curious, once all the proper sensing circuitry is in place, what's the technique for actually calculating the power consumption? You mentioned sampling at 3KHz, I assume not only voltage but current as well? Then just basically integrate over time? Can power factor be calculated as well? Not an area I've delved into, but I might be interested in trying it sometime.

The Atmel application note (link from KE7GKP) is interesting and is at least somewhat similar to your original thoughts in that it simply uses 1M? resistors for mains isolation. Also note in the text that while it allows for voltages up to 1000V, it also says it is not a sufficient design to handle larger surges. So the circuit in the AN is probably fine for experimentation, but more protection is needed in a permanent installation. Finally there was a comment on the input pin capacitance introducing a small phase shift, not sure if this would even be significant for your application.

#### ElectricWater

#12
##### May 25, 2011, 05:14 am

I have split phase 220 which means I have 110 at the plug for the freezer.  Why the heck can't I use a voltage divider?

Something like:  Hot wire -> 1M resistor -> some other value resistor ->1M resistor -> neutral wire.  I would measure the voltage across the middle resistor at the arduino and tailor the value to keep it in the 1-2 volt range.

I must add one thing to this conversation: If you connected the Arduino in this fashion the voltage seen by the Arduino may indeed be in the 1-2 volt range, but the voltage on the Arduino measured against the neutral wire and earth ground would be at about 55 VAC. Not exactly a safe scenario unless the Arduino were contained within an enclosure that completely insulated from its surroundings.

#### justjed

#13
##### May 25, 2011, 05:22 am

Something like:  Hot wire -> 1M resistor -> some other value resistor ->1M resistor -> neutral wire.  I would measure the voltage across the middle resistor at the arduino and tailor the value to keep it in the 1-2 volt range.

Maybe I'm missing something, but that sounds like: (obviously, I should have put a load on the far right line)

So the voltage is always going to be nominally 110VAC. So that doesn't tell you anything about how much current your freezer is drawing when it's running. Don't you need something more like a clamp-on ammeter?
... it is poor civic hygiene to install technologies that could someday
facilitate a police state. -- Bruce Schneier

#### draythomp

#14
##### May 25, 2011, 06:10 am
Just a quick (hopefully) note on the other things that came out of this discussion:

Lefty you're right (pun totally intended) I have seen young people on this forum and others that I wouldn't recommend messing around with a 5V supply, much less something that can overcome skin resistance.  My problem was only with preaching that it was unsafe without an example or instance or anything.  That's what I ran into when I was reading a thousand or so posts on this kind of thing around the web.  Just, "Don't do it, it'll put your eye out" kind of statements.  I guess the "kid with the BB gun" in me can't accept that.

Your example of having to share a ground with the AC neutral is a good one as was Jack's of a hot chassis.  These are both problems that can be overcome relatively simply, but if one is going to ever share such a thing....beware of the uninformed.  The floating (voltage wise) arduino is another concern because someone will probably grab the arduino and the faucet at the same time; especially in a stainless steel, grounded refrigerator.  Sigh.

So, as I mentioned before, I'll bite the bullet and get a transformer, darn it.

In answer to some of the other questions.  Yes, you sample the instantaneous voltages over a power cycle as well as the current (going to use a hall device this time) and then integrate to get the various values.  You can measure the power factor and frequency of the incoming power to see what happens when you turn on the plasma cutter to cut a kink out of the tractor's fender.  I already do this for both phases of my home power using 200A current transformers wrapped around the mains input inside the circuit box (see, I'm not afraid of the voltage).  The calculations sound complex, but actually aren't bad at all.  My reading on an instantaneous basis rival the power company's expensive meters.  Yes, they've been out here explaining how they measure the power and comparing their results to mine.    Over time, their temperature compensation is better and my sums (of the readings) drifts from the KWH they record and I pay for, but not by enough to worry about.

I've had county inspectors looking at it, people from the power company looking at how I did it and even energy conservation experts from a swimming pool company comment on it.  It was a really fun project that is ongoing (forever) and now I want to start applying it to smaller appliances.  For example, I have separate refrigerator and freezer.  Individually, they don't use much power and represent a minor expense, however with demand metering, if they both kick on at the same time, it drives demand usage up and I pay a ton for the small fraction of time that they operate together.  Hence, this project.  I describe this in horrifying detail on my web site at draythomp.blogspot.com.  I also have the various schematics and code that is running most of the devices I've incorporated into this project.  So, if you want to do something similar, grab anything you want and go for it.  Around my house, the current power usage is as easy to find as the time of day.

Go Up