How to detect power failure?

The optocoupler's LED could even be run direct from the mains with appropriate Rs and Cs.

PLEASE not DIRECTELY from the main ( You know Murphy's Law - I anythings can go bad ) . Just use a CHEAP AC transformer... it more safer. That what I have in my design.

Techone:

The optocoupler's LED could even be run direct from the mains with appropriate Rs and Cs.

PLEASE not DIRECTELY from the main ( You know Murphy's Law - I anythings can go bad ) . Just use a CHEAP AC transformer... it more safer. That what I have in my design.

LOL, yeah I know, there have been other threads about that. Don't worry, I'm appropriately trained/educated. Seriously, that's what the opto isolator is for (I may be crazy but I'm not stupid). I'm thinking a simple circuit like these LED night lights that you can get now. Except it'd be the LED on the input side of the opto isolator.

But I'm all for keeping the Legal Dept. happy, so like they say on the commercials:
CLOSED COURSE, TRAINED PROFESSIONAL, DO NOT ATTEMPT.

the nightlight idea is proberbly the best way to monitor utility power, get a cheap LED one, rip it open as much as you need to get access to the LED, replace that with an Opto Coupler and a few other bits to get it working and your prettymuch done, just rig the nightlight to think its dark all the time (proberbly by replacing the LDR with a variable resistor, so you can adjust it until it thinks its night).

hope this helps, also as normal its mains electric so i dont suggest messing with it unless you know what your doing.

@Kris, the circuit is so simple, I wouldn't bother tearing anything apart. I've seen several circuits that are variations on the attached. In my case the LED would be the input side of an opto-coupler. I might want some filtering as this example will flash the LED at the line frequency.

Actually I think I'm favoring the second wall wart approach for the prototype, but the mains-driven LED could be just as safe if done properly, in a proper enclosure with an opto-coupler, etc.

LED_120VAC.png

Jameco sells an opto isolated coupler p/n PS2505-2 that is AC tolerant. Connect the transformer through a properly sized resistor directly to the chip.

Jim

@ Jack

I was a bit worried...I look at your schematic, it a bit similar of a telephone circuit ...ringer detector. The parts... let see...

C is 0k has long it is well above 200 V
D1 - 1N914... Wrong...<--- Too weak !! Use a 1N4004 or above rated of 200 V. <--- Check datasheets. Use this site. http://www.datasheetcatalog.com/ It one of my favorite site to check datasheets.

R1 - 1 K ----> check calculations : 120 V AC rms --> 170 V peak so let use 200 V for V. LED operating current of 10 mA. Vled = 2.2 V ----> ( V - Vled ) / I led = R limiting ( 200 - 2.2 ) / 10 mA = 19 780 ohm ---> 20 K NOT 1 K. Let check the power rating of R1. Power = R1 * ( I led * I led ) 20 K * ( 10 mA * 10 mA ) = 2 Watt resistor

Re-list of part: C1 - 0.1 uF @ 250 V D1 - 1N4004 R1 - 2 Watt 20 K

Now that it will work. Except the LED will flash @ 60 Hz in that circuit.

@Techone, thanks, that was actually just a circuit I'd found on the web, hadn't tried it or analyzed it. I may try it yet, as it is an interesting approach, but for now, for several reasons, I think I'll go with the second-wall-wart approach. If I do try it, I'll report back with my findings.

Regarding your analysis, not sure what you mean by "C is 0k has long it is well above 200 V" ... If I calculate the reactance of a 0.22?F capacitor at 60Hz, I get a touch over 12K?. I didn't look up the PRV for a 1N914, but if memory serves it's 75V or so, which is probably way more than that of the LED. But neither diode will ever have a reverse voltage across it that's more than the forward voltage of the other diode, so I don't know why a 1N914 wouldn't work. It could also be a second LED.

@ Jack

Technicaly, the C - capacitor is not needed in that design, ( you don't have a DC component to block - a telephone line is yes ) Here a site about telephone interface Telephone ringing circuits ( I know it is unrelated, but in a way they are )

About "wall-wart", get some "free" from the garbage or a cheapy , took apart with a metal saw ( do it carefully ) Extract the transformer. I forgot that a 1N914 is OK, has long is connect in serie with a power resistor. ( Just my last posting ) The V drop should be the same has V led. Just my calculation for the LED ( positive swing of the AC wave ) and 1N914 ( negatiev swing of the AC wave )

And for more protection, add a fuse of 200 V @ 250 mA in serie ( in-line ) with the circuit.

So it should be -- Fuse - power resistor -- Diode // LED .. That it ! According to calculation, it should work.

@Techone,

Beg to differ, the capacitor is by far the main component responsible for limiting the current, it's not about blocking DC, or telephones for that matter. Build it without the capacitor and see, but I'd include a 1/4-to-1 amp fuse on the incoming line just for extra safety. I also might Google up some AC circuit theory.

Anyway, old habits die hard. I guess I can't analyze a circuit even partially and then not go into the lab and build it. Since I had the parts available...

Turns out this circuit is just about perfect for powering the average garden-variety LED. My standard LED dropping resistor when working with 5V is 330?, which results in 9mA or 10mA current through the LEDs I use.

I’ve had this circuit happily glowing here on my desk for a couple hours now without incident, nothing seems to be getting warm, etc. I’d think the 1/6W 1K resistor might heat up a bit, as my calculation says it should be dissapating ~100mW or about 60% of its rating, but if it is, I can’t tell. Still, I might prefer a 1/4W resistor just to be extra conservative.

I took the following measurements, all are AC RMS:
Vin = 119.9V (wow, the utility company is right on the money today)
Vcap = 119.0V
Vdiodes = 1.318V
Vr = 9.91V
Iin = 10.1mA

Attached is a picture of the circuit, along with an identical LED powered from a 5V regulated supply with a 330? dropping resistor (on the right). The AC-powered LED is not quite as bright, which stands to reason since it’s only on half the time.

Well..Well ..Well .. I am surprise... You design using a cap to take the biggest voltage drop work. My design use a power resistor. Your is a good one. No power resitor to buy. So you use this :

Reactance of Capacitor = 1 / ( 2 * PI * 60 Hz * 0.1 uF ) = 26 525.823 ohms <--- Interesting

I will never taught of this idea. I am still learning ... You surprise me.

Bear in mind, the LED still "flashing" @ 60 Hz. You just need to connect an opto-coupler instead of the LED. A 4N35 will work fine.

Anyway, old habits die hard. I guess I can't analyze a circuit even partially and then not go into the lab and build it. Since I had the parts available...

I use computer electronics simulators to check some of my designs. And I test for real. Here the link for the simulators I use.
Circuit Simulator Applet <--- It free but can not save & print.
http://www.new-wave-concepts.com/ <--- I use Circuit Wizard Pro ( Cost me about $300 can ) Yeah ! But it was worth it .

@Techone,

That's it! It's quite a clever circuit, isn't it! Now the really cool thing (literally) is that it limits the current without generating heat, i.e. wasting power. The 0.22?F capacitor, with a reactance of about 12K?, dissipates effectively zero power. Sure, we could use a 12K? resistor instead, but assuming the same current of about 10mA, that resistor would dissipate about 1.2W; as you observed, a 2W resistor would be appropriate. The circuit with the capacitor only wastes about 100mW, not counting the power consumed by the diodes, so it wastes only about 8% of the energy than would the circuit with the resistor.

I was still wondering what the 1K resistor was for, technically it's not needed, the capacitor alone should be enough. Then I thought about failure modes, and I'm thinking it may be to limit current in case another component in the circuit (especially the capacitor) fails. The worst failure modes would involve a component shorting out. In this circuit, the diodes are the most fragile components and effectively act as fuses. If the capacitor failed and became a dead short, without the 1K resistor, we'd have 120VAC straight across the diodes. It wouldn't last long, but there could be a few fireworks. With the resistor, the diodes would still fail, but in a much less spectacular manner, opening the circuit and resulting in a safe condition. If any other component in the circuit failed by shorting out, there would be effectively very little change in operation, the circuit would continue to draw ~10mA and would still be safe. And of course if any component failed by going open-circuit, then the current stops and things are still safe. So I think whoever originally designed this circuit thought it through a bit!

Now to delve into AC circuit theory a bit more, consider the fact that going around the circuit and adding up the observed voltage drops across the various components results in a total that is greater than the input voltage, i.e.

Vcap + Vdiodes + Vr = 119.0 + 1.318 + 9.91 = 130.2 > 119.9 input voltage

Have a great day! :slight_smile:

Just circling back with my final solution. After thinking about the second-wall-wart idea, I abandoned the idea of using a DC signal to detect a utility power failure. Until I put the thing in practice, I probably won't have a feel for how brief an outage I'm actually interested in detecting (but below some minimum, I won't worry about it). With a wall-wart, there are filter capacitors involved, not sure how long they'll last, the MCU pin is effectively no load, so need a resistor to load it, have to figure time constants, etc. etc.

Much easier with an opto-isolator where the LED is driven direct from the AC line, using the circuit I posted earlier in the thread. I think this is quite a safe circuit, and of course it effectively keeps the mains voltage away from the MCU, etc. Connected the collector from the opto transistor to the INT0 pin and turned the pullup on, so while the power is on, it'll generate 60 interrupts/second. The main loop simply counts milliseconds since the last interrupt, and compares it against a threshold value, so very easy to change, and easy to set quite accurately. The ISR is one line of code, simply setting a variable to zero, so very minimal impact to other processing.

It's running as I write this, counting cycles per second, mostly giving a boring string of 60s, but it gets interesting once in a while. I just saw a string of 12 or 15 61s in a row, with a couple 63s or 64s thrown in. Also see the occasional string of 59/61 pairs which is probably just random phase synchronization between the MCU clock and the line frequency. I've heard that power line frequency is very, very accurate over the long term because they count the cycles and adjust accordingly, but it can be off a bit at any point in time. Looks like that is indeed the case given my small sample here.

In industrial settings where things have to work, battery powered emergency lights are operated by a simple relay. With ac available the relay that controls power to the light stays open. When power is lost, the relay fails closed supplying battery power to the light. Simple and reliable. Instead of powering a light, the closed contact could be used to provide on/off info to the arduino.

zoomkat:
In industrial settings where things have to work, battery powered emergency lights are operated by a simple relay. With ac available the relay that controls power to the light stays open. When power is lost, the relay fails closed supplying battery power to the light. Simple and reliable. Instead of powering a light, the closed contact could be used to provide on/off info to the arduino.

That's a clever solution, someone actually mentioned it earlier in the thread I think. Relays are relatively large and expensive, though; I think I might have $0.70 in the four components here (over half of which is probably the capacitor, which I find odd). With no moving parts, should be pretty darn reliable. I suppose the opto-isolator could fail, maybe its LED might die some day. I will be immediately aware if that happens, and finding the fault should be straightforward!

A relay with multiple contacts, can also be wired such that the power failure state can stay 'latched' in the AC failed mode until a manual push button is pressed to reset the relay once AC power returns. This is useful in some cases where you want to not just depend of returning AC power to restart some systems.

Often the return of a AC power failure can be quite unstable for a few seconds, false starts, surge voltages, brown voltages, etc. A latched power failure detector with manual restart can be the best way to 'restart' some system and devices.

Lefty

Relays are relatively large and expensive, though;

Depends on where you buy and the type of relay used (5-6v relays are less than $1 when mail ordered). If you already have a wallwart, it can be used to power a small DC relay. If you have a photo resistor (RS may still carry these), you could combine it with a $1 LED night light from the Dollar Tree store (where everything is just $1) for power loss detection.

Interesting item on the accuracy of the power line frequency.

http://catless.ncl.ac.uk/Risks/26.49.html#subj6

From my experience, aka I wondered if it'd work, you can power a led directly from ac mains with as little as a 20k resistor
I used a r of about 18k in series with the led and it worked fine, the resistor got warm but not hot,
now its probably not the safest or most relible but its real cheap to just set the one led up to the mains and tape another directly opposite as an optoisolator to the arduino,
the color of the led used will be the output voltage, I find that uv works best since it puts out about 4 volts

here is a basic solution: AC line detection with two components | Psychic Inside!