rechargable batteries for uninterruptible power supply

karlok:
Ok now I understand.

gardner:
so you might have to use larger values for R3 and R4

This goes for R1 and R2, too?

And I changed the resistance values of R3, R4.
However, I think if D5 is not GND, then 9V goes straight to A1 which is not good because it is limited to 5V. Dangerous?

Yes, best to drive a npn switching transistor to pull the voltage divider to ground.

If D5 is GND then I understand how it works, is digitalWrite(5,LOW) really the same as attaching something to GND?

Yes, but it carries a maximum current limit of 40 ma and the actual 'ground voltage' at the pin when commanded low will tend to rise slowly as the current draw is increased. There should be a graph or specification showing the value of outputLow voltage Vs current draw for an output pin in the AVR datasheet for the specific chip.

I attached the schematics like I understood it.