This question already has an answer here:
Currently I am running my micro-controller boards with power adapter(AC to DC).
Now I am developing a system which senses AC power and sends me some signal when AC power is gone.
The problem is I am running my board with the AC power(through adapter) which I am sensing. So, I need to switch to battery power( as backup ) instantly when AC power is gone making sure my board doesn't turn off while switching.
I am not sure how it should be done.