On the other hand, why make it so complicated?
If the 7805 is just there to make the 9V into 5V for the arduino to read,
I would ditch it and the capacitors and just use two 5K resistors to make the 9V into 4.5V, and when 9V goes away the 4.5V goes away too.