Attached is the filter I've got on the bread board now and it isn't working and I can't come up with where I've went wrong.
The voltage divider gets the voltage to 120*(680/68680) ~ 1.188 volts (plus or minus of course)
Then I pass it through the filter and DC offset. (The measured offset is a little more than 2.5 v due to 5% resistors)
and I would expect something between 3.68v and 1.312 volts.
Converting that to the steps the arduino sees I would expect 3.68/(5v/1023steps) ~754 and 1.312/(5/1023)~268
So if I read the analog volts and then print them to the screen I'd expect the AC signal to oscillate between 754 and 268 with a center of roughly 500.
The problem is I'm seeing roughly 500 to 520.
I think its the filter taking out the 60hz signal but according to the design it should be passing the signal with minimal phase offset.
Can you spot where I've gone wrong? Thanks again for the help!
Ah, firstly let me say something about safety and high-voltages. Be very careful...
More specifically that 68k resistor should be two 33k resistors in series, well spaced out (not on a breadboard for instance), and in an insulated box. Two resistors in series means that if one of them fails (flashes over, shorts, gets an insect crawling over it) then the other will prevent a direct mains input to your low-voltage circuit.
OK, now the problem - your have a high-pass filter not a low-pass filter!
You need to place the capacitor between the mid-point of the voltage divider and ground. Also the 100 ohm resistors of the divider between 0V and 5V are too low - they need to be about 680 ohms too I think.
Does the 680 ohm resistor go to neutral or earth BTW? Is mains earth connected to Arduino ground or not?
And finally back to the safety thing - there is another way to measure mains voltage without directly connecting - use a small mains transformer and measure the (low voltage) secondary voltage instead - this way you can be fully isolated from the mains.
Thanks for pointing out that I indeed had designed a high pass after looking at the low pass filter pictured I saw the mistake.
I've updated my my drawing a bit here to reflect the grounds/neutrals. I was planning on fusing the high voltage link (not in the drawing) but separating the resistors is a great ideas as well.
I had lowered the values of all my resistors to be pretty much as low as possible because I was thinking that they were influencing my flawed low pass filter. I've got it designed closer to the parameters you've described at home so I'll have to take a look into that now.
If you wish to measure Mains power use a transformer, a mains to 6 or 12V AC output Wall Wart would make your device intrinsically safe and reduce your voltage divider to reasonable and safe values. as it is now you have a connection that includes the mains as ground, therefore anything else connected to the Arduino is a part of the mains circuit. There is one more error and that is if the 680 ohm resistor opens up you have a 2 ma fault current that can flow from any pin of the Arduino to ground and finally you have NO Transient protection. Line or mains transient voltages occur typically when large inductive loads are connected/disconnected from the mains/110Vac line. The "line transients" can and Frequently ARE as much as 50 times the AC line voltage. What this means is that a surge or transient of up to 50 X the voltage seen normally at your measurement point and this means that the worst case voltage can for as much as a millicsecond be in the range of 60-100V. If you would make a safe measurement use an ac output "Wall Wart" to supply the measurement sample and use a pair of series back to back Zeners rated at ~ 2 X the Wall Wart output voltage. The Zeners are fast enough to accurately "Clamp" a transient to whatever Vz is (Vz = Zener breakdown voltage) A tranzorb is ideal for this situation and are manufacturerd in both single ended and back to back devices for a 1The transformer will further prevent the accompanying common mode line noise from affecting your measurements (common mode noise is the voltage differences between "common" wires) and in this case is the slight 1/2 to 2 - 3 volt difference in Ground potential caused by individual device load currents flowing in each return or ground lead, since various devices draw different currents there will be a voltage developed on each return or ground lead
I have to agree...THIS IS VERY DANGEROUS! You probably wouldn't be allowed to sell such a product in the U.S. or Europe unless it was entierly encased in plastic with no "low voltage" connections to the outside world. (For exmaple, you could have an LED display showing through the sealed enclosure, but no USB connection, etc.) If you plug into a mis-wired power outlet (with reversed hot & neutral), or otherwise got hot & neutral get reversed by connecting an extension cord, etc., you'll have 120V on your "low voltage" circuits relative to earth ground.
And, there's just a lot of potential for something going wrong and blowing-out your arduino, or you accidently "touching something" during design/development. If you use a transformer, you can heat-shrink all of you AC connections and everything will be a lot safer (for you and your Arduino).
In general, you need to isolate the low-voltage electronics with a transformer, relay, or optics (depending on your needs and what you are doing).
P.S.
If you use a transformer, they are rated at full-load. So, if you get a 12V transformer with connect a light load (such as an R/C filter or voltage divider) you'll get a bit more voltage... You might get 16 or 18V, and you'd have to calibrate your circuit with resistors (or a pot), or you could calibrate it in software.
Just to clarify here. I'm a Distribution engineer for an electric utility and am used to being around high voltages. While working on this project I've utilized the proper protective gear including gloves rated to 1000v, eye glasses, and proper clothing.and at the minimum a fused source in case of failure. (As i mentioned above I do intend to fuse the main side in the device)
This is intended for a medium to high voltage environment. The user of such device would have protective gear on while attaching leads and the case of the device would be completely enclosed (no lcd screen even) and I plan to incorporate wireless comms to avoid having to connect to the device directly.
I've avoided using an isolation transformer for now because cost is a huge concern. A "wall wart" will not work because in most circumstances a outlet is not available.
I sat down some tonight and re-designed what I had to take into account some of your guys comments to try to make it safer and used new resistor/cap values for the filter.
I feel like I'm getting pretty close but I'm still not there.
R5, R1, R2, and R4 are providing VAC voltage division.
R3, R2 and R4 are providing the DC voltage division for the offset. (2.5V)
R5, R1 and C1 are providing the filtering.
After all this my analogreads are oscillating between 3.28 and 1.83 and I was expecting 3.68 and 1.312
If you manually remove the DC offset from these voltages they are off by a factor of about 151.2%. Could this just be coming from my filter cutting off a a portion of the 60Hz frequency? (It doesn't look like its quite -3db but there is some loss at 60hz on the magnitude response) If i moved my cutoff frequency out a ways would there be a worry of the high frequencies entering the circuit? How tight does the cutoff need to be to the max frequency?
At this point I would be satisfied to use software to account for the inaccuracies but I'm curious where someone thinks this is coming from?
in rough approximations, and ignoring the capacitor, your 120V voltage divider has an open-circuit output voltage of nearly 1V RMS, or 2.8V peak-to-peak. The effective impedance of the divider is about 1K. That's connected through R3, at 1K, to 5VDC. If you draw the effective AC circuit - treating the 5V rail as 0V AC - you'll see that the input signal is cut in half.
You're getting a swing of about 1.35V centered around midscale. That's what the theory predicts for this circuit.
To get better performance, here's what I'd recommend:
Use the configuration of the circuit you posted first, with the capacitor in series with the analog input. That'll give you DC isolation between the 120V hot and the analog input.
Use a couple of 100K resistors, rather than 100 ohm, to bias the analog input at 2.5V. That will avoid loading the output of the 120V divider too much. It'll also form an impedance that's considerably bigger than the impedance of the capacitor at 60Hz, reducing its impact on the readings.
Review your expected results. You seem to be basing your expectations on the RMS voltage that you expected from your original circuit, rather than on the instantaneous voltage that you'd get from this one.
Finally: I'm thinking that your capacitor is an electrolytic. In the circuit you just posted, it's seeing a strict AC voltage. If it really is electrolytic, it shouldn't be operating with its "+" input negative with regard to its "-" input. I'm betting your voltmeter will show about 1V AC across it, and 0V DC. It'll work like that for a while, but sooner or later, it'll pop.
Thanks for that. I hadn't even thought that the DC source was really 0V AC which makes sense when you then calculate where things are going to see 1/2.
I think i should stick with the current configuration because as Mark T pointed out the first configuration was a high pass filter. Sure you could design 60hz to pass and isolate DC you wouldn't filter any noise which was the intent.
To solve essentially parallel circuit problem I doubled the resistor values on the AC voltage divider and 5V bias circuit. This gives twice the voltage at the divider then when split across the two connections your back down to the intended voltage.
I do now concur about the results and after calculating RMS based on the values read in through analogread and the value on the DMM they match!! Silly I didn't see that in the first place.
I actually am using a ceramic disk so polarity isn't a problem however had I used the electrolytic your right having a (-) potential on the (+) terminal is asking for problems.
Here is the finished and working circuit!! Thanks to everyone for your help. If you still see changes I should make let me know!
My values are within 10% when I make my final circuit I'll probably use 1% resistors and add a small factor to correct but I'm satisfied with the results.
I did go ahead and measure the values of all the resistors last night and that got me significantly closer sadly I don't have those numbers with me at work to present.
OK, I misread your "R3" as 3.2K, made clever calculations on that basis, and got it wrong. I need to get some new glasses, or abandon this thread.
You might want to think about protecting the analog input. I think it's only a matter of time before a transient does something bad to it. My first thought is to put a big resistor in series with the analog input to limit the current to less than 1mA, but I see that the data sheet frowns on using a series impedance of more than 10K. A UL 1449 330V surge suppressor on the 120V circuit might be just the ticket.
I still don't see an isolation transformer... for 2 purposes... 1 is filtering and 2 is isolation. I've done what you are doing... my first "voltmeter" was a pot and a neon bulb (NE2H). it worked well enough to find an intermittent pole pig supplying a 50 horsepower pump cost me $5.00 for 3 NE2H lights 3 LDRs 3 SCR's and 3 led's. Had 2 new pumps burn out because the owner didn't want to install a protector to drop out the pump on line failure... The Electrical company (was in Kansas)... Paid for the pumps.
A Wise Man once told me... "When You are a Hammer... Everything Looks like a Nail"
Doc you and the rest have me convinced. I'm going to steer away from an transformer because they are big, heavy and expensive. Instead can you help with below?
First transient suppression. I looked into those TVS diodes you were referring too and I found this.
Voltage breakdown at 10V. I'd place this Between R1 and R2 to the left of the node correct?
After that I started exploring opto-isolators and I came across this.
I have never used these before so I have no understanding how they work all I know is they provide isolation (and possibly transient protection up to 5300Vrms?)
Based on the spec sheet my 120V would get wired into pins 1 and 2 and I would get my isolated AC out of pins 4 and 5. This is where I get confused how do I know what is output?
It looks like there is a max output of 30V does this correspond to the max input of 600V? Can you help me understand the specs here and if it does provide the transient protection?
They're usually used to connect digital signals between systems that don't have a galvanic connection. You can check this link - http://www.vishay.com/docs/83708/appn50.pdf - for a description of how to use a special-purpose dual-output opto-isolator for sending accurate analog signals. It takes more hardware - two op amps, and a separate isolated power supply on the 120V side - and more effort, since it appears that the ICs have enough variance to force you to calibrate for each individual chip. If you just want to detect that AC is present, then an opto-isolator is a great solution. But, it seems that you want to measure it, and that'll be difficult with an opto-isolator.
That's how I see it, but I wouldn't say my knowledge is up-to-date. If there's a good, simple way to get an analog signal across an opto-isolator, I'd welcome that information. If you manage to do it, be sure to post.
When I read these bits -
cowboypride84:
... intended for a medium to high voltage environment.
... in most circumstances an outlet is not available.
it makes me think that you probably won't be powering this circuit from the USB port on your laptop. I'll be that you'll power it from the AC that you're measuring. If you do that with a transformer/rectifier/regulator circuit, you'll already have a transformer on your board. Intuitively, though, I question whether that transformer will be accurate enough for measurement. I can't point to an accurate, little transformer with enough oomph to give a precise waveform while driving a rectifier circuit. And, you may prefer a different power arrangement.
Your transient suppression diode seems to be available in a bidirectional version with a nominal 5V clamping level, with a maximum clamp level of 9.2V at 55A. For your circuit, the worst case is a negative-going transient that could result in -9.2V at the analog input, and it might last however long it takes to vaporize one of your 60K resistors. Atmel's app note AVR182 says the internal clamping diodes can manage a milliamp, so you might want to put an 8K resistor in series with the analog pin. That'll keep the effective impedance down to 10K, which the datasheet recommends for accurate analog readings, and keep the worst-case pin current around a milliamp. I think the TVS goes across C1, between the analog input and ground.
In the attached picture I added a bidirectional TVS diode. (Pardon the incorrect symbol it was the best I could do) Even though in the picture my source is only at 120 if I over drive it it limits the potential at the analog pin to 10 volts. Pretty awesome.
I couldn't find a spice model of a optocoupler but I found a high linearity analog one that is intended for what I'm going. "precision high voltage measurements in a low voltage environment" I'm planning on isolating the entire circuit using the optocoupler for the analog input and an additional optocoupler for the 5v rail. I think this will be much easier then finding a coupler and/or transformer that will isolate 120v. (A have intentions of going higher voltage)
When I get these 3 pieces added in I will come back and share with everyone.
Good luck, That didn't work for me when I tried it in 2004... Just a simple opto with TVS diodes, Zeners and hefty clamps Opto's still blew up on average line transients... I had 6 as sensors on pumps and I lost the first 3 I sent out in the field, with transformers I lost 1 of the next 10 I sent out... This was a center pivot controller used in Nebraska corn fields to control the irrigation machines and it was a "Rural Power Grid" VERY VERY Noisy. under better circumstances a transformer might work for you... I had to make my own optoisolators... with NE2H's and CDS photocells... it was I found later the fact that I wasn't totally isolated from ground that was my real issue. That donnybrook nearly cost me my job and taught me a great deal about isolation and surge protection. My best advice now would be to build it and learn.
I'd still add an 8K resistor at the analog input. 10V is way better than no protection at all, but the analog input pin is rated for -0.5V to 5.5V, and the bypass diodes are rated fro 1mA.
cowboypride84:
optocoupler ... I found a high linearity analog one that is intended for what I'm doing.
Good luck, That didn't work for me when I tried it in 2004...
Nothing like a big old vote of confidence. I hope it works but I'll let you know either way.
it was a "Rural Power Grid"
Welp I'm an electrical engineer for a Rural Coop sounds like I have the optimum testing grounds.
I found later the fact that I wasn't totally isolated from ground that was my real issue.
My 5v rail is going to be isolated and my analog input is going to be isolated. At this point the only that that will blow up is the "high voltage" board and if I keep em separate it should be easy to replace/fix. Based on your previous suggestions it seems silly for me to get to the end and not be completely isolated so hopefully that will be my saving grace.
I'd still add an 8K resistor at the analog input.
I don't exactly understand where this should go? Are you thinking between A0 and the circuit above? or A0 to ground? I'm confused. Either way screws up the input analog voltage quite a bit. Can you better explain where you think this should go so maybe I can redesign my circuit Assuming I had 10k resistance into the input and I did have a 10V fault that puts 1ma exactly on the internal TVS so I might get saved!!
I'd put that resistor between the analog input pin, and R3, where R3 connects to C1, The analog input pin is a high-impedance input - the datasheet lists its input resistance as 100 megaohms - so almost no current flows into it. Consequently, almost no current flows through a resistor that's in series with it. A resistor with no current through it has the same voltage at both ends. So, adding a series resistor won't change the way the circuit operates under normal conditions. See the section, "ADC Characteristics" in the chapter, "Electrical Characteristics," in the ATmega328P datasheet.
The analog input pins have clamping diodes to Vcc and ground. See "I/O Ports," "Overview" in the datasheet. They don't conduct unless they input voltage is out of range. The current needs to be limited to about 1mA - I don't find that in the datasheet, but I did run across it in application note "AVR182: Zero Cross Detector," which describes how to connect a digital pin to the AC power line. Regrettably, that appnote leaves TVS as an exercise for the reader.
And, I find a limit of 10K for the series equivalent series resistance for an analog input pin, in the section "ADC Noise Canceller," in chapter "Analog to Digital Converter." The intent of that limit is to allow the sample capacitor to fully charge during the sample period, which is the first tick of the ADC clock in the conversion cycle. That keeps you from going with, say, 100K at the analog input pin.
Something in the 8K-10K range, in series with the analog input pin, seems to meet all the requirements: no inpact on normal operation, and current limiting under transient conditions.