Hi- For all the good suggestions that have come up, there has been one assumption that has been made. If indeed, the PIC is supplied with the same power as the application, then there is many good solutions already posted to choose from. However, if the mains in question are NOT being supplied by the same circuit as the PIC, or indeed, you want to monitor several power sources and switch in battery supply for more than one, well that might just change things. My circuit was for a PLC and to monitor several AC mains from a general purpose input. Also, I didn't have to worry about an instantanious switchover. More than a cycle dropout would be o.k. I went with a largeish (I'm doing this from memory) 0.1 500V non polarized non-electrolyic cap that can source about 10ma or so of current when 60Hz is passed through it. This was in series with a few K ohm resistor to a diode bridge. The output of the bridge supplied enough current to illuminate the LED in an opto-isolator (4x25 which is the worst of the bunch). The output was fed to a low voltage cap to smooth out the DC and not trigger the input. You can find reference to using a cap on AC mains in the microchip app notes. However, this is for driving an optoisolator, not powering the PIC. I like this circuit as it has a very small number of components and is still isolated from the mains. It will also work with DC. My calculations were for 110VAC, however, a bit of experimenting will allow it to work on 220V. You might find it worthwhile to experiment with an isolation transformer in the circuit, properly fused. Watch out for scope grounding problems too. The cap choosen was to allow for the passage of 10ma through the optoisolator. It is rather largish and might not be available cheaply. I did find mine in a surplus house for a few pennnies, so you might want to investigate an alternative like diodes and polarized electrolytics..... If you find some optoisolators that are more sensitive than the ones I choose, then this too will cut down the current requirements for the design. Hope that this helps! If you are monitoring a different power source than that of the PIC, then this hopefully will be of use. If you are powering from the same, then sorry and please disregard. Cheers, Rich S. ---- Original Message ---- From: Miguel Reznicek Date: Tue 6/26/07 12:11 To: piclist@mit.edu Subject: [PIC] need circuit to monitor AC mains and switch to battery on AC loss plus alarm Friends: Does someone know of a PIC chip circuit that will monitor the 220 VAC mains and use them to run, but that can automatically switch to a battery power when the mains fails? I need to make an alarm for when the power fails. Thanks in advance, Miguel Reznicek mreznicek@pretensa.com -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist