# How to measure AC voltage using non-linear opto-couplers?

I am designing a TRIAC LED dimmer circuit.

Depending on the AC voltage applied, I control the gate trigger angle for the TRIAC to reduce/limit the current at 15 amperes to the load. Gate trigger control is done using a micrcontroller & MOC3021 driver circuit. There is a zero-cross detector circuit using EL-817 optocoupler which is fed into the GPIO of thr controller.

In my application, the AC voltage is either 120V/208V/240V. I want a simple circuit to detect which of these voltages are currently connected to my board and thus use corresponding trigger angle.

I found many online reference which spoke about step-down transformer, bridge+voltage divider circuit and linear opto-coupler. All these are either unnecessarily costly or space consuming for my requirement.

Does anyone know of a simple but reliable method like using a non-linear opto itself and figuring out which AC voltage line is connected to the board?

• Is the microcontroller galvanically isolated from the mains? If not, you might not need an optocoupler at all! Oct 1 at 10:11
• @user253751 : Yes micrcontroller is galvanically isolated from mains. Oct 1 at 10:25
• May be 3 separate optocouplers, with different current limiting resistors. Oct 1 at 10:28
• Why not just have a small control circuit that monitors the current and drives the Triac accordingly to obtain 15 amps? Why use a MCU and over-complicate things? Oct 1 at 11:49

Use a capacitive dropper to convert the input voltage and frequency into a constant current source, and use that trigger an output optocoupler. Then count the pulses per second to compute the input voltage

This gives an output of about 15Hz on 120Vrms@60Hz, 24Hz on 208Vrms@60Hz and 30Hz on 240Vrms@60Hz

Note that the output can also been seen as 8 half cycles between interrupts at 120Vrms, 5 half cycles between interrupts at 208Vrms, and 4 half cycles between interrupts at 230Vrms. The circuit relies on the fact that the capacitive dropper stops supplying current in the peaks to break the latch

# Math

Every cycle, the input voltage goes from 0, to Vpeak, to 0, to -Vpeak

In these cycles, the input 22nF capacitor gets charged and discharged.

This generates pules of current though the birdge rectifier and charges the 4.7uF capacitor

Lets assume our input voltage is 240Vrms at 60Hz, this makes the reactance of the 22nF capacitor about 120.572 kOhm, we have to add our inrush resistor to this to get 120.582 kOhm of "input resistance", We have to subtract 1V from our input voltage for the bridge rectifier, to get (240V - 1V) / (120572ohm + 10ohm) = 0.001899A = 1.899mA

Using the capacitor charge formula of "dV = I dT / C", we can calculate the time it takes to reach our trigger point, which can even be low 11V as most zener diodes have a smooth curve (we an make a more perfect circuit using a more precise voltage reference).

11V = 0.001899A * dT / 0.0000047 ==> dT = 0.0272249sec (36.7310807386Hz)


This value seems to low/high for the previous measurement of 0.03333 sec (30Hz). This is caused by the fact that this is only the time for the capacitor to charge to the trigger level, and once the PNP+NPN transistor is latched, it keeps being lathed until the base voltage on the NPN drops below 0.5, which happens below 1mA input current (every vPeak crossing). This means the circuit is limited to 1 pulse every 0.0083333333 sec (120Hz)

The 240Vrms takes 4 of these "mains half cycles", which is 0.333sec, as 3 half cycles only take up 0.025sec, which is barely below the trigger treshold

One advantage of measuring the time in half cycles, is that the whole voltage measuring process becomes frequency independent, as it still takes the same amount of time in half cycles. (and you already have a zero crossing sensor)

The total formulae becomes:

X = 240, Z = 60, Y = 0.000000022, R = 10, 0.0000517 / ((X - 1) / (1 / (2PI * Z * Y) + R))= 0.026084 seconds per capacitor charge

Or in a plot form (with fixed 60 operating frequency, and fixed 10 ohm inrush resistor)

• Thanks a lot. This is really useful circuit. I made this circuit and measured using arduino. Works perfectly fine and we can detect voltage accurately using software filters. Can you please share any link that explain how to do design calculation? For others who are trying this, Here is my video : imgur.com/a/TW3rs00 I used arduino to read the frequency of pulses. Arduino code : github.com/vishweshgm/StackExchange_ACVoltageDetector Oct 7 at 14:19
• I tried to do math for calculating how much time would it take for capacitor(4.7) to reach 12V (referring to simuation) after which it discharges via current sink. But I am unable to arrive at an equation which define time taken by Capacitor (4.7uF) to reach 12V. Can you please help me understand how this circuit decides the frequency of pulses? Oct 8 at 13:17
• @VishweshGM I added a math section explaining it Oct 8 at 14:42
• You are amazing! Thanks again. Oct 14 at 11:10