I wanted ISS Notify to work for a while not plugged in, so I've worked out a rechargeable backup battery system. But if you have a battery in a circuit you want to know how much charge it has left so you don't run it down too low (damaging the battery) and so the other parts of the circuit maintain proper voltage.
The microcontroller and everything else is running at 3.3V, but the battery can be higher, up to about 4.4 V, so how can you measure the higher voltages? Use of voltage divider. A basic voltage divider is just two resistors in series connected to ground. The voltage in between the two resistors will always be lower than the input voltage by a fraction based on the ratio of the resistor values.
But there is a problem, this will drain a small amount of power continuously! One thing you can do is make the resistors really big so they drain less power. I started with this, but I can do better. I don't need to measure the battery voltage continuously. So by adding a digital switch, is this case something called a MOSFET. Then I can periodically switch the battery sensing circuit on, measure the voltage, and turn it back off. This will eat up almost no power at all.
But that introduces another problem, the switch needs to be on the high side of the voltage divider, which is not at the same voltage as the microcontroller. In order to keep the microcontroller isolated and safe, a second MOSFET is used to switch the other.
The final circuit diagram is attached.
Q1 turns on the voltage divider (R10 and R11), while Q2 gets attached to the microcontroller. The other two resistors keep the MOSFETS off when nothing else is happening. By turning on Q2, and using an analog pin attached to the divider I can measure how much voltage is left in the battery and let you know if you need to plug it in.
Next week: Full parts list (I hope!)