Identify Power Outage

Hello,
Currently, My Arduino Mega is connected directly to the wall using 9v transformer.

I want the Arduino to idenify a power outage and start an alarm (of course I will have to connect it also to a battery).

I have 2 questions:

  1. How can I identify power outage?
  2. How can I work with 2 power sources?

Thanks!
Danofri.

Thanks Richard!
Unfortunately, this is my first electronics project so I didn't understand what you mean.

How can I keep the battery charged when it's plugged to the Arduino?
How exactly I connect the Arduino to the wall so it will sense power outage?
I thought on connecting 4.5v transformer from the wall to one of the digital pins and read it, when the value is LOW then it means a power outage.

Am I right?
Please explain slowly including when to connect what...

Many thanks!!!
Danofri.

Thank you.
You right, I will explain exactly whay my project is and what my needs are.

I'm building a reef aquarium controller.
My current needs are:

  1. I want my controller to work non-stop.
    After reading the link you posted, I know that I want to have float charger with 9v battery.
    Is there any plug and play circuit that does that?

  2. My second need is to sound an alarm (and later maybe send SMS) when there is a power failure, this way I will know that my aquarium pumps does not work.
    My idea was to connect a second transformer to one of the digital pins on the board and sample it, but I guess there are better was to do that (maybe connect the circuit from plug and play circuit from above to the digital pins).

Thanks!!
Danofri.

All my equipment is 220V.

My the main issue here is to get SMS on power outage (let's say that for now, a secondary power supply for the arduino is on second priority).

I would consider using 12V pumps, heaters, and lights, and running everything off a big car battery on the floor.

You DO NOT want to charge a car battery indoors (hydrogen gas and sulfuric acid leakage, among other bad stuff); and you certainly don't want to set one on the floor when doing so (unless the floor is concrete).

It would be better to use a SLA (sealed-lead acid) battery with an appropriate charger (note: do not use a car battery charger with an SLA!) - or better yet, a computer UPS of the appropriate volt-amp size for the system you are trying to keep running.

Thanks for your help!

I don't have enough knowledge to build one on my own, so I will try to see if there is a ready solution I can buy online.

I just don't understand why my solution will not work (connect a 220v to 5v transformer from the wall to the digitial pin and sample for LOW).

Thanks!