Measuring Mains Voltage

actually 60hz anything, really) scares me badly.

?

60hz anything electrical I guess. 60hz humming doesn't.

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.

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.

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?

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

draythomp:
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.

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.

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.

draythomp:
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.

draythomp:
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?

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.

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

I don't know how far you've gotten since March but I thought I'd share my thoughts on a similar project I just started if anyone is interested.

I started my power measuring project with a Kill-A-Watt, measuring the total power consumed through one of my breakers. It soon became a pain to go look at the display and punch the data into my tablet by hand. Since then I have purchased the wireless Kill-A-Watt and two of the sensors.

Through a mix-up from Amazon I ended up with a spare readout for free so I immediately took it apart to see if there were any ideas lurking inside. In typical P3 International (the manufacturer) style it was a pretty compact design with few clues until I get my logic analyzer out of storage. It operates on the 915 MHz ISM band and the radio chip is one of those "bonded to the PCB with a glob of epoxy over it" types. Anyway, the reason I'm posting is because of the sensor.

I don't know if anyone has looked inside the normal Kill-A-Watt but if you have you know why they put it in a plastic box. There is no isolation from the mains AC at all so you don't want to go probing around inside with it plugged in unless you are really careful. (AWOL insert cautionary gasp here. :-P) Well, the wireless one isn't any different but it's a pretty nice design and for $30 might be worth cannibalizing for a project. P3 measure the current by measuring the voltage drop across a pretty hefty piece of wire, probably just a few millivolts, and they get the voltage by a divider across LN. Since it's all inside a sealed plastic box, it's safe for consumers. I've considered cutting out the parts of the circuit I don't need and using it because it is so efficient at plugging into the wall, sampling the current/voltage and then passing the AC out to a matching socket on the face to plug your load into.

Anyone interested in discussing this? Maybe start a new thread?

For current measurement a shunt resistor can be gotten cheaply. Here is a link from a quick search. Only $2.88

Just my quick 2 cents. Someone said you cannot measure without a neutral. Not true. All up-to-code breaker boxes now have the ground and neutral bonded. So any hot to ground will give you the same results as hot to neutral. Also, "split phase 220". All house circuits have this. If you look at your panel (breaker box) there are two buses. A 110 (closer to 120-125 now days) uses one buss and a neutral. 220 (again, closer to 240-250 now) use both buses and a ground. Some devices, such as my drier, use both hots, a neutral and a ground, to have 110 available to drive internal electronics. With the neutral and ground being bonded tho, I guess the ground is just a fail-safe if the neutral fails..

Per Grumpy Mike's note: Here is some info related to U.S.A. electrical terminology and wiring.

The Neutral wire is designed to carry current any or all the time. It is call a "grounded conductor". The ground wire is for a "fail-safe", it is supposed to take any short circuits to ground to protect the person using the item. The ground wire is called a "grounding conductor". The two terms are found in a NEC code book for anyone interested.

One important note: never assume a neutral wire or neutral bus is grounded or "safe". There are a number of reasons that can make the neutral wire "hot" and therefore just as dangerous as the hot bus in your power panel.

Mark

@cyclegadget
Please don't assume that the whole world is the U.S.A. While the physics might be the same (much to the shagrin of the U.S.) the words are not.

Grumpy_Mike:
@cyclegadget
Please don't assume that the whole world is the U.S.A. While the physics might be the same (much to the shagrin of the U.S.) the words are not.

Sorry, I wasn't thinking of the whole world picture that is the internet. I made an adjustment to the post.

Mark

cyclegadget, thanks for the link.

EmilyJane, I haven't made much progress on this yet. I decided that I would get power from a disassembled wall wart; at U$3.00 or so I couldn't beat the price or ease of use. I have a small CT I'm experimenting with that is actually working pretty well. I suddenly realized that putting it around a wire in a box was not a big deal. There were a number of problems making a hall effect current sensor work and those CTs are easily available and simple to work with. I also realized that I didn't need much power from a transformer that was only going to be feeding a voltage divider for measuring the AC voltage. So, a few milliamps would be fine, of course, that decision was AFTER I decided to use a repurposed wall wart for power.

Given the above, it's become a matter of having the time to slap it together, but it's summer and the yard is eating up my free time.

But, now you've got me intrigued with the Kill-a-watt all over again. I didn't pay much attention when the wireless ones appeared since I had one of the wired ones and I was measuring power at the main for the entire house and didn't see any need. However, I did (of course) take a kill-a-watt apart and was impressed by the fact that they simply measure the voltage across a wire to get the current level. If you check really closely, they also use a voltage divider to sample the AC voltage. With these two items the rest is just accumulation and calculation.

The problem is the $38 price tag for something that I will cut up and adapt. I think a simple short extension cord with a box in the middle holding circuitry would do the job just fine and I could use my latest love, the ardweeney, to do the processing and tie the new device into my existing XBee network.

You're right, the form factor of the wireless Kill-a-watt sensor is really nice. I could never match that cool little package.

draythomp,

You're right, the form factor of the wireless Kill-a-watt sensor is really nice. I could never match that cool little package.

Okay, I just wanted to point that out. I agree, the price is a little daunting. There are plastic enclosures available that have the plug incorporated anyway (ala DIY wall wart) that are pretty inexpensive that I'll probably end up using.

I'm going to start another thread because I want to look into hacking the protocol that the wireless sensor uses. They are priced pretty reasonably for my project budget and if I can use them, I want to.

Edit: The enclosure I settled on is from this series: PM Series AC Wall Plug-in Enclosures and Boxes | Polycase

Some have a molded in place for a receptacle.