Anda di halaman 1dari 5

Reading AC Voltages with a Microcontroller

Posted on September 11, 2011 by paul This article shows an op-amp based circuit to transform a high-voltage AC waveform into something that a micro-controller can measure directly. DISCLAIMER: This article is provided as-is, with no guarantee that the circuit will work in your situation, or that it will be safe. If youre going to attempt to measure mains voltages, do so at your own risk if you dont understand the math or circuit diagram, then you probably shouldnt be working with mains anyway. I am not responsible for your mistakes. You have been warned.

Background
A few years ago, I was involved in a project that needed to measure mains voltages in New Zealand, which has a 230 V, 50 Hz supply. My circuit needed to be as cheap as possible, and didnt need to be electrically isolated from the supply. I needed to measure the voltage using a microcontroller that had an input range of 0 to 5 volts, and needed to measure voltages from -375 V to 375 V (or 265 VRMS). To convert this large, alternating voltage range to something compatible with the micro, Ive seen several approaches on the web. Most do something along the lines of rectifying the AC voltage before feeding it into the micro. While that may be fine for some, it creates ambiguity between positive and negative voltages. I needed something better. It would be great to have a circuit that multiplies the input voltage by a constant, then adds half the supply voltage of the micro. It turns out you can do that with a single op-amp, and three resistors (five if you dont have a handy half-supply reference). Heres how:

The Circuit
AC voltage measurement system with AVR microcontroller or any other microcontroller. This task can be divided into two sub tasks. 1)Attenuating Line voltage to the level that can be applied to microcontroller pin. Here is the circuit used to measure AC line voltage (230V,50 Hz) this circuit converts line voltage to the level of 0 to 5 volts. This can be understood by most of microcontroller and ADCs. Here is an op amp based circuit to do the job. This a simple adder circuit to add some offset to your signals.
2)Software to measure AC value You can directly measure DC value with ADC if you take a reading but that is not the case with AC signals.

To calculate RMS value of AC signals you should sample at least 3-4 cycles and then calculating RMS value.

If youve used op-amps before, this should look reasonably familiar it is pretty much the standard inverting amplifier. However, the key differences are that the non-inverting input is tied to half of Vcc instead of ground (so if you have a 5 V microcontroller, tie this to 2.5 V), and the extra resistor pulling the inverting input up to Vcc this resistor should be exactly the same value as the other resistor called Ri. The operation that this circuit performs is:

This is precisely what we want. Say we would like to measure mains voltage in New Zealand (remembering the disclaimer above), with a range of -375 V to 375 V, and the microcontroller can accept voltages from 0 V to 5 V. By choosing Ri to be 150 k and Rf to be 1 k, the gain from the formula is 1/150. IMPORTANT: unless something is wrong, the voltage at the inverting input will be 2.5 V (since both inputs will be the same, unless the op-amp is saturated). That means that the resistor Ri will need to be large enough that very little current flows when Vin is large. Heres a quick table for Ri = 150 k, Rf = 1 k, Vcc = 5 V.

Vin (Volts) Vout (Volts) -375 5.0 0 2.5 375 0.0 As you can see, an input waveform centred around 0 V is nicely converted to a much smaller waveform, centred around 2.5 V just right for a microcontroller.

Proof
From Kirchoffs Current Law, the current into the inverting input node is, remembering that no current flows into the op-amp:

This is simply the voltage across each resistor connected to the node, divided by that resistors resistance. Simplifying:

And we get what we expect.

Notes
Remember that an op-amp is not perfect. For best results, get a rail-to-rail one (that can output voltages near the supply rails), and make sure youre not driving too much current through Ri. Most importantly, do not connect anything to mains unless you know what youre doing! Dont blame me if you blow something up.

set the values of R1 & R2 by measuring Vx across capacitor 5(R1 + R2) = R2 Vx 0 volts means 0v main supply 5 volts means 220v main supply measure the value of vx via digital volt meter for eg if vx = 7v then select R1 = 1k , R2 = 2.5k here it has assumed that the Maximum Main AC voltage is 255v u can change the max limit according to ur requirments Main_max_volt = 255 (5/Main_max_volt) x present_main_volt = volt_to_ADC for eg::

if present_main_volt = 0v then 5/255x0 = 0.0v & ADC = 000 if present_main_volt = 160v then 5/255x160 = 3.137v & ADC = 160 if present_main_volt = 200v then 5/255x200 = 3.921v & ADC = 200 if present_main_volt = 220v then 5/255x220 = 4.313v & ADC = 220 if present_main_volt = 250v then 5/255x250 = 4.901v & ADC = 250 now u don't need any calibration just simply convert the ADC Register value to ASCII & display it on ur screen thatz it

Anda mungkin juga menyukai