I'm building a circuit with an Arduino and a breakout board that has a small coin cell battery on it for maintaining a bit of state when power is off. The battery is exposed by a pin on the breakout board. I want to measure the battery's voltage with the Arduino.
In the schematic drawing, I have drawn only the battery for simplicity.
I have a voltage divider connected to the Arduino, but to avoid having a current flowing constantly from the small battery, I added a p-channel mosfet to keep the voltage divider disconnected from the battery most of the time, and I connect it occasionally in software to check the battery. That works well, but only if the system is powered.
Without power, I see a significant voltage at the mosfet's source, I guess because the gate is then floating. That's not what I want. Is there a way I can get the circuit to keep the battery disconnected when the Arduino is not powered (i.e. 5V and D0 are floating)?
(Sorry if this is a stupid question; I am trying to self-re-teach myself the terrible electrical engineering class that I semi-slept though 20 years ago in college.)