How to detect loss/presence of AC mains?

I need some help to detect loss/presence of AC mains. 24VAC runs into an input pin, through 100k resistor=1/2 wave.

I thought of missing pulse detect by having a timer overflow if AC didn't appear and clear the timer. The timer starts on a rising edge. But if AC is not (initially) present, the timer never sees an edge and just sits there?

It looks like 8-bit TMR2 is available= 16.32msec overflow (16MHz clock and prescale/1024, count of 255) so it's too fast for 60Hz 1/2 wave =(
Anyone have suggestions for an algorithm...

A while back I saved a circuit for a mains-powered LED circuit (attached) - I'm not a circuits guy, but wonder if the LED could be the input side of an opto-isolator, and if the detector side could be connected to your Arduino...

115VAC-LED.png

@Morris Dovey

Yes, it will work. But it is missing a two zener of 24 V connect in serie.

Like : Cap ---- C -Zener - A -- A - Zener - C -- to led / diode.

Telephone ringer is almost the same circuit. Except the circuit have zener diodes. ( I open a few electronics phones to find that out )

How long does it need to be missing for?
Add a diode rectifier to your transformer and a low pass filter, then watch the analog level.

This has come up a lot lately.
You don't want zero-cross == no ac.
You don't want something so slow that an actual drop out is missed or detected late.

Using XC, you don't need a resistor, just a diode across the LED (opposite polarities).

I've always liked the use of a simple 120vac relay as a drop out detector. Contacts are completely isolated from the AC power and a small lower mass relay should drop out in one or two cycles of the 16 millisec period of a 60hz cycle.

The OP needs to define how long "Off" is before coming up with a solution.

Here in the States, most utilities set the automatic reclosing circuit breakers so they reclose after an overload (or lightning strike) in 3 to 6 cycles -- 3 seems to be the most common, and probably so 3-phase power goes through enough cycles. I have to assume that wherever the OP is that they have 240 volt supply at the mains (probably 230/400 3-phase for the system power) that their utilities also reclose after 3 cycles or so. Which means ... anything more than 3 cycles is a real power outage.

@jfhaugh

I have to assume that wherever the OP is that they have 240 volt supply at the mains (probably 230/400 3-phase for the system power) that their utilities also reclose after 3 cycles or so

I notice the OP fill out the location in his/her profile... Canada. Therefore, North American system...

The OP want a code "example" of : if no pulse ( at the ouput of the opto-coupler ) for a lengh of time.... do something ....

Techone:
@jfhaugh

I have to assume that wherever the OP is that they have 240 volt supply at the mains (probably 230/400 3-phase for the system power) that their utilities also reclose after 3 cycles or so

I notice the OP fill out the location in his/her profile... Canada. Therefore, North American system...

The OP want a code "example" of : if no pulse ( at the ouput of the opto-coupler ) for a lengh of time.... do something ....

Yeah, I also see that the "240" I thought I read was a 24VAC transformer.

They should wait 3 full cycles before assuming the power is out, unless they want to see "power outage" indications all day long. My system picks up an AC line loss after two cycles, and I see a lot of "blips" that were fewer than 5 or 6 cycles in length.

With that in mind, I'd wire up an external crystal for the timer2 oscillator and use the on-chip oscillator for the uPC itself. I don't know how the clock source is determined, so someone else will have to answer that question or tell you that I'm all wet.