# Sensing presence of 220 Vac for MCU

I'd like to use an HCPL3700(M) (datasheet) to sense if a 220 Vac mains is present. In my application, the device needs to raise an alarm if the mains voltage is lost. Backup power will be provided by a battery or super cap.

I've found this (which is, at least in part, based on this), but I am not smart enough to figure out if the values in the schematic below are appropriate for 220 V mains... So, my questions are:

1. Does C1 need to be 400 V rated?
2. Are the values for R2 and R3 appropriate?
3. What rating would R2 and R3 need to have? 2 W?
4. I have seen some examples with a cap between MAINS_PRES and GND - is that necessary? If so, what values would be appropriate?
• The values of R2 & R3 are calculated from tables in the app note. What voltage threshold are you trying to detect? (is the detection of brown-outs important). Aug 6 at 7:26

A 220 V ~ relay may be used instead. The digital input would be 'high' with the relay energised and vice versa.

• Good solution if the threshold is not critical. Aug 6 at 7:24
• @Mattman944 - Thank you! Aug 6 at 7:34

Maximum threshold is about 3 mA, so the two 47k resistors on the 220V input would provide about 2.3 mA average and 3.3 mA peak. It will probably work, but 39k might be more reliable. They will see about 600 mW each at 300 VAC, so 1 watt are OK and 2 watt even better, but make sure they are rated at least 200V.

The capacitor on the DC+ and DC- will only see the LED voltage, so anything more than about 10V will be OK. The capacitor should tend to hold enough current through the LED to maintain the output on through zero crossings. A capacitor from MAINS_PRES to GND will help filter noise as well as ride through zero crossings. About 100 nF should be good with 10k pull-up, giving a TC of 1 ms.

 Answering a comment below, the input current will be approximately 220/R, so your two 47k resistors would provide about 2.3 mA, with peak current about 3.3 mA. Two 39k resistors result in 220/78 = 2.8 mA and peak current 3.99 mA. You may need to do some actual testing to see what works best for your needs. If you want to minimize power, higher values will give a pulse of a few mSec every half-cycle, so you could use software to detect a missing pulse.

• Sounds good. Can you explain the calculation behind your recommendation of 39K? Then maybe - just maybe - I might be able to figure it out in the future... Aug 6 at 8:48
• There is more than a LED on the DC terminals. The DC input of the HCPL-3700 appears as a 1000 Ω resistor in series with a one volt offset ... Aug 6 at 9:17
• @Mattman944 I don't understand what the implications of that are...? Aug 6 at 11:28
• @MichaelLarsen Ring Detection with the HCPL-3700 Optocoupler says "The Zener diode bridge at the input of the HCPL-3700 clamps the voltage across the Ac inputs at approximately 7 V" [emphasis mine]. Aug 6 at 15:11
• That app note certainly gives valuable information, although perhaps the equations are more complex than needed for this application. And the HCPL-3700 might be "overkill" here. It is more than \$5. A digikey.com/en/products/detail/onsemi/H11AA4SR2M/1054097 is a simpler device with AC input for about a dollar. And you could also use a common single LED optocoupler with an external LED to provide a visual indication of voltage. Aug 6 at 21:27