# Isolating small backup battery when power is off

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.)

A second FET can be used, and the pullup can be moved to the 3V, rather than 5V line:

simulate this circuit – Schematic created using CircuitLab

When D0 floats or outputs logic LOW, the gate of M2 is pulled down and M2's channel conducts no current. As a result, M1 gets pulled up to +3V (the battery voltage), but no significant current is drawn from the battery. When the microcontroller is powered and D0 is logic HIGH, M2 conducts, pulls M1's gate down, and connects the battery to the voltage divider.

You will need to make a software change to drive D0 HIGH for sensing, rather than driving it LOW.

Note that the naive approach (which I suggested before fixing this post) suggested using your original circuit but with the pullup going to the battery voltage. This was actually a poor idea on my part because it would lead to the battery powering the Arduino (and anything else on the 5V bus) in an inappropriate way through its protection diode:

simulate this circuit

• Thanks a lot! This works perfectly! Dec 16, 2021 at 22:47