I have more than one AC power source and I want to detect which one of them is ON which one is OFF using a Microcontroller. So my question here is what is the cheapest and smallest in size method to detect whether an AC power line is there or not?

From 100~240 VAC to 3.3V Steady DC


I'd use an AC input opto coupler like this: -

enter image description here

Or maybe the IL755 because it is available with two in one package but beware of the voltage breakdown rating between two supplies conected on the diode side: -

enter image description here

Of course you don't need to use an AC input opto, you could use a circuit like this: -

enter image description here

Here, D1 protects the photodiode from reverse voltages but you only get half wave pulses passed through to the microcontroller. In the ones above you get full-wave pulses (twice as many per second). That might be a big deal or it might not.

|improve this answer|||||
  • \$\begingroup\$ Comments are not for extended discussion; this conversation has been moved to chat. \$\endgroup\$ – Dave Tweed Nov 3 '16 at 21:45

Many people often make the mistake of think they just need some voltage margin above Vsine-pk and forget about ESD and Lightning transients and IEC standards for flashover and hope their Opto will protect them.

  • the best method is an LC common mode choke on Line-Neutral with ED protection. then add opto Isolation if the system requires isolation as opposed to offline AMR meters which do not. Cost $0.20/(1k)
    • When I was in the AMR ( Automated Meter Reading ) R&D mfg biz we used special ceramic hybrids to reduce 240Vac to 22Vdc with large SMT resistors and zener bridge and storage cap to also power the unit and ISM 928MHz transmitter receiver.
  • But you may also consider line chokes with Y caps. and then use low voltage R's (500V) enter image description here


simulate this circuit – Schematic created using CircuitLab

  • R1,R3 must be impulse V rated or line transient pre-filtered
  • adjust C1*R4 to 10/f = 100ms if you dont want to see each cycle pulse and have a software timeout.
  • R4 for additional current limit protection.

  • BOM Cost 10 Rupees in volume ( how cheap are you? )

  • my advice $500 USD (joking of course)

    • what you need isolation too?

enter image description here

|improve this answer|||||
  • \$\begingroup\$ Please note the IEC surge withstanding test requirements above and test method. As well as Hipot std test methods limited to 500uA. \$\endgroup\$ – Tony Stewart Sunnyskyguy EE75 Oct 31 '16 at 15:16
  • \$\begingroup\$ pls support your opinions with evidence -1 \$\endgroup\$ – Tony Stewart Sunnyskyguy EE75 Oct 31 '16 at 18:02
  • 2
    \$\begingroup\$ You response literally has nothing to do with the question. The question is "how do I detect the presence of the AC mains". Your answer is a bunch of off-topic rambling about ESD protection. "Here is how (side note about requiring ESD protection)" would be a reasonable response, but not even answering the question at all is completely off-topic. \$\endgroup\$ – Connor Wolf Nov 1 '16 at 3:59
  • \$\begingroup\$ @Conner Wolf, I respectfully disagree strongly. When detecting ACLine voltage, you must be compliant to International standards for safety and functional requirements for noise immunity. none of the other comments or answers addressed this. \$\endgroup\$ – Tony Stewart Sunnyskyguy EE75 Nov 3 '16 at 15:39
  • \$\begingroup\$ This answer is a bit outdated, but I think it's important to notice that such circuit is referenced to the main AC voltage (typically unsafe to deal with without some external protection). The ground on such circuit can be 300V above your own body voltage, so don't use this kind of circuit unless you know what you are doing. Also the microcontroller power must be referenced from the same line or you'll have a ground loop. I'm not downvoting because except for this, it's a very useful addition. \$\endgroup\$ – xryl669 Feb 1 at 17:59

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