What do I need to take in account when using a voltage divider as a voltage sensor?
Most microcontroller inputs are protected by diodes to each rail. These diodes aren't very big, so they can't take a lot of current. You want to be sure that the input pin's protection diodes aren't accidentally subjected to currents that exceed their maximum specification. If you design your divider appropriately and don't make any other mistakes, then this is pretty easy. You just make sure your divider's node voltage doesn't go much lower than GND and doesn't go much higher than \$V_{cc}\$. I tend to prefer to add another resistor, though, going from the divider midpoint node to the input pin on the micro. Just in case one resistor is accidentally shorted for a moment. In the case of the MSP430x2xx family, this absolute maximum diode current value is \$\pm\$2mA.

Leakage current of the I/O pin used for an ADC (or comparator, I suppose) needs to also be consulted. In the MSP430x2xx family case, this is often around \$\pm\$50nA, worst case.

Here's an example circuit I might try:







simulate this circuit &ndash; Schematic created using CircuitLab

I started out assuming that I wanted the absolute maximum diode current to be well under 2mA -- let's call it 1mA. Assuming the battery voltage might accidentally get up to 14V or so, and assuming that somehow \$R_1\$ is momentarily shorted, I want \$R_3\$ to be more than \$\frac{14V-V_{cc}}{1mA}\$. With \$V_{cc}\$ of 5V, this means perhaps 10k\$\Omega\$. Just as a check, the worst case leakage current through \$R_3\$ leads to a drop of 500\$\mu\$V (which is an acceptable accuracy error, I think.)

The leakage of 50nA also suggests that if I want to keep errors under 0.1V or so, that I could tolerate a divider impedance of about 2M\$\Omega\$. So I decided that a 470k\$\Omega\$ is fine for \$R_1\$.

What remains is \$R_2\$. I decided that the center node voltage at \$V_x\$ should be about 2.5V when the battery voltage is at that arbitrary over-voltage value of 14V. So this set \$R_2\$ to 100k\$\Omega\$. At 12V, \$V_x\$ will be closer to 2.1V or so. Well within range of many ADCs.

You could do more. Or you could do it differently. I used higher resistor values because you asked about current consumption. This divider won't consume much power. But you could also consider a way to disable the divider entirely when it wasn't in use for even less power. Or you could lower the values of \$R_1\$ and \$R_2\$ to provide more load (against static.) Or you could try and use a timed RC constant to make your measurements, instead. You could also add external diodes from either the \$V_x\$ node or the ADC pin to both rails. There are more ideas, I'm sure.