I've seen that resistor dividers can be used to read negative voltages, but I'ld like if there is a way to accomplish this with less components and having a way to turn this off.

I was thinking if there would be an extreme option of changing from pinMode INPUT to INPUT_PULLUP or INPUT_PULLDOWN to power the circuit and use the 20k pullups to make part of the divider, together with another resistances on the input. Alternatively, switching from INPUT to OUTPUT would be fine.

What I want to measure is an external +3V/GND/-3V power supply (battery pack) that shares the GND with the arduino SAMD21 (3.3V), measuring both +3V and -3V, and avoiding drain when not measuring (hence the pin mode changes)

Currently I'm using this schema to measure the voltage of +5V supply battery (connected through VIN, thus using the internal regulator), by dividing with 2 1Mohm resistances, ground to digital pin and measurement by internal adc. I don't need so much precision, so this is enough here. So I'm looking for the same or better alternatives, but for the -3V I don't know how to properly calculate the 3 resistor divider.

2 Answers 2


When measuring a voltage that is higher than the maximum rating, the voltage of interest is tied to ground with a voltage divider. When measuring a negative voltage, you instead have to tie the voltage of interest to the positive supply voltage (study the answers to this question).

In theory you can use the internal pullup to spare one resistor, but I would consider this a bad practice and recommend using an external pullup for the following reasons:

  • a uC's internal pullups/-downs are not accurate and sometimes not specified
  • especially when measuring negative voltage, chances are that harmful voltage is applied to the adc (consider the default state of a gpio)
  • a pullup/-down is an uncritical component concerning its value and precision. Therefore they are very cheap

Two 1M resistors for a voltage divider is high. You could add a capacitor (1nF or 10nF) to GND and the analog input.

Could you try to find what the leakage current or the self-discharge current of the battery itself is? Then take a percentage of that, for example 20%, then calculate what resistor value the voltage divider should be.

It does not have to be 20%, it can be any current that you are willing to give up to be able to measure the voltage.

For example, when the battery has a self-discharge current of 10µA, then 20% is 2µA, which is two resistors of 825kΩ. That happens to be close to the 1M resistors that you already use.

  • Yes, 1M resistor were high, but I tried with 10k ones and behaviour was bad. Later, I deduced that the reason was that I was switching the digital pin (low) from output to input to avoid consumption, and when left floating, the analog pin was receiving 5V (for a 3.3V MCU...). Probably it works with 1M due to very low current, but I've also to change that.
    – avelo
    Jul 4, 2019 at 10:47
  • @avelo there will be no relevant consumption. Why do you switch "to input"? When using the adc the corresponding gpio is an input allready. The adc only sinks a very small current to charge its sample-and-hold circuitry (small capacity).
    – Sim Son
    Jul 4, 2019 at 11:49
  • 1
    @SimSon i was using an analog (A1) pin in the middle of the divider, and a digital one (6) at the end to connect to ground digitalWrite(6,LOW); pinMode(6,OUTPUT); when measuring (disconnecting by changing it to INPUT). Just as a way to save the 5/20k power waste. With 2*1Mohm the consumption drop to irrelevant as you said, so no reason to use the digital pin for that (and I'll have the +5V problem if let it floating), I agree!
    – avelo
    Jul 4, 2019 at 12:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.