Possible Duplicate:
How can I detect a power outage with a microcontroller?

I'm doing some research with the goal of eventually creating a light dimmer controllable from a micro controller. I've figured out how to do the dimming of the light and now I need a zero cross detection circuit that I can use to determine when to phase shift the AC power.

I have a few opto-couplers which should do the trick. However (and this is my question), it appears that the AC side of the circuit takes around 1.7V (assuming I'm reading the datasheet correctly). How do I get the line voltage down from 120V to 1.7V. I assume that I could use a high value resistor, but wouldn't this generate too much heat? Seems to me like it would just fry the resistor. I'm pretty hesitant to just try this as I enjoy having all of my fingers attached.

I've seen people discuss connecting the line voltage directly to the micro controller through high value resistors here, which seems like a pretty bad idea.

To summarize my question: How can I connect AC line voltage to my opto-coupler? And if that's done with a resistor, how do I determine the correct ohms/watt rating to use?


  • \$\begingroup\$ The name on the other question may be misleading, but look at the first answer. You will see it has a detailed answer of how to do this. \$\endgroup\$ – Kortuk Mar 19 '12 at 11:59

You can get big resistors.

The datasheet specifies 1.15V - 1.5V forward voltage when the current is 10mA. To get that from 120V you would need a resistor of (120-1.5)/0.01 = 11.9kOhm, it would dissipate about 120*0.01 = 1.2W, so a 2W resistor would probably be OK (or use a 5W one if you have space, it won't get as hot).

It would be difficult to get a resistor that precise, but the LED in the optocoupler can survive a continuous current of 60mA (which would require a resistor smaller than 2k), a 10kOhm 5W resistor in series would work. The current will be somewhat above 10mA, but nowhere near the maximum.

| improve this answer | |
  • 1
    \$\begingroup\$ Perfect! I guess the thing that I didn't understand was how to setup the ohms law formula (i.e. subtract 1.5 from 120 to get the value for V). Thank you! \$\endgroup\$ – Matt Ruwe Mar 19 '12 at 0:49
  • 1
    \$\begingroup\$ When we say that the mains AC is 120 volt we are talking about the RMS (mean) voltage. To get the peak-to-peak (actual) voltage you need to multiply by the square root of 2, that is 120*sqrt(2)) = 170V. So for If=10mA and Vf=1.2V (specs), you would want a resistor of value (170-1.2)/0.01 = 17kOhm. \$\endgroup\$ – GummiV Mar 19 '12 at 9:29
  • 1
    \$\begingroup\$ @GummiV, since there are no smoothing caps, the diode will experience the RMS current, that is, the light produced will be equal to that if the LED was fed the RMS current, but DC. Also, the peak current will be 17mA (with a 10k resistor), so that is still way below the maximum rated continuous current. \$\endgroup\$ – Pentium100 Mar 20 '12 at 9:27
  • \$\begingroup\$ @Pentium100 Hmm, now I'm confused :P At some point there will be an instantaneous voltage of 170V between the two wires and, since both a resistor and a diode are non-time-dependant, the instantaneous current will be completely determined by that 170V number, right? Sure, the emitted light will be equivalent in-the-mean to a (approx.) 120V DC signal (if we integrate over time) but if we had a high-speed camera wouldn't we observe the 50/60Hz flicker? Is there some sort of smoothing behaviour involved that I'm not getting? \$\endgroup\$ – GummiV Mar 20 '12 at 23:07
  • 1
    \$\begingroup\$ @GummiV Yes, the instantaneous peak voltage will be 170V and current will be 17mA (170V/10kOhm), which is below the maximum continuous rating of 60mA, so the diode will survive. The diode could probably survive even higher than 60mA peak current (the datasheet only specifies a very short pulse of 1A though). The power dissipated in the resistor will be equivalent to the RMS power (because the resistor will cool down when the instantaneous voltage is <120V). On the other hand, using a 17k resistor will make the peak current 10mA and the output pulse will be shorter. \$\endgroup\$ – Pentium100 Mar 21 '12 at 1:09

Not the answer you're looking for? Browse other questions tagged or ask your own question.