# How to measure mains AC voltage with an ADC from a microcontroller?

I want to measure the Mains voltage (230V/50Hz) using an ADC channel from a microcontroller.

This is my current approach ...

Below I have two schematics that add two voltages (one direct, one alternating).

Added to that, the both the AC and DC signals are going through voltage divider, but that isn't important.

I'm guessing that the output voltage on the second schematic is lower because of the impedance of the capacitor? • Is that wire from R2 connected to R4 base? – MaMba Jul 6 '16 at 15:53
• What are you trying to do? Bias an AC signal to +5V/2 for an A/D converter? What frequency and what voltage? – Transistor Jul 6 '16 at 16:06
• Basically, I want to measure the Mains voltage (230V/50Hz) using an ADC channel from a microcontroller. – C Cezar Jul 7 '16 at 11:40

If you only want to monitor the MAINS VOLTAGE, then you don't need to convert the entire sinusoidal waveform, add offset, etc. etc. You seem to be asking the wrong question.

The common way of monitoring mains voltage is to FIRST ISOLATE the voltage with a transformer. This could be a very small transformer as found in a discarded wall-wart power supply, etc. Then rectify and integrate (filter) the voltage so that you have a DC voltage that is faithfully proportional to the mains voltage. This DC voltage can be simply scaled with a voltage divider, perhaps a potentiometer, and fed directly into the ADC input.

Here is a typical circuit which is very good for monitoring mains voltage... The usual way to do this depends on the frequency of the AC signal.

At low frequencies you might be able to use a summing op-amp circuit. This may limit the current that can be delivered at DC.

At RF frequencies you can use a bias tee. This is similar to your right side circuit, but removes unnecessary resistors and adds an inductor in the dc input path: simulate this circuit – Schematic created using CircuitLab

• Basically, I want to measure the Mains voltage (230V/50Hz) using an ADC channel from a microcontroller. I think the frequency is low enough. – C Cezar Jul 7 '16 at 11:40

What is the correct way to add a direct voltage and an alternating voltage?

Added to that, the both the AC and DC signals are going through voltage divider, but that isn't important.

Basically, I want to measure the Mains voltage (230V/50Hz) using an ADC channel from a microcontroller.

I think your question is really, "How can I (safely) add a half $V_{REF}$ offset to a signal potentially divided from the mains voltage?"

What you seem to be proposing is simulate this circuit – Schematic created using CircuitLab

Figure 1. OP's proposal. Note that there is no mains isolation.

If you are proposing the circuit of Figure 1 then I suggest that you redesign. There is no isolation between the mains and micro. At best you will have neutral voltage appear on your micro ground. Do not assume that this will be zero as any current flowing from other circuits through the neutral wiring back to the mains source will cause a voltage drop along the resistance of the cable.) A far more serious situation will arise if the live and neutral connections were swapped. In this case the micro GND will become live.

Also, since you seem to be in 50 Hz land it is likely that your mains voltage will be 220 to 240 V. In this case a single resistor may not have adequate voltage rating for the high voltage supply. Two series resistors would be required for the high-side resistor. simulate this circuit

Figure 2. A small mains transformer of a few VA will provide isolation, a signal to work with and an easy means of adding a DC bias to the AC signal.

• A 6 or 9 V transformer would be adequate for this circuit and provide a safe working voltage with no isolation or safety issues.
• Size R1 and R2 to pull a few tens of mA from the transformer and reduce the peak voltage to the operating limits of the micro.
• In my original post I did not mention anything about mains. The AC voltage that you see on the input side is actually the secondary of a transformer.(With an amplitude of 10V, which is a random value to easily check the divider is working). I did not include this information because I only wanted my question answered. Thank you for your answer, very thorough. I'm not that stupid to work with mains without isolation, maybe my question was. – C Cezar Aug 6 '16 at 21:25