# Electronic – Arduino: Measure external voltage

arduinocell-batteryvoltage measurement

I have a "problem" while trying to measure the external voltage from a coin cell. I have simplified my circuit, but basically I have a DS1307 real time clock powered by the Arduino 5v output, and a coin cell connected to vBat to keep the clock alive while the Arduino is shutdown. My idea was to measure the battery level with Arduino by connecting its positive to an analog input and read the voltage level. So, I thought, as the max voltage is 3v, I can use the 3v3 as AREF and set analog reference to external and then read accurate results. The result is pretty cool and the readings from Arduino are the same as reading the battery voltage from my multimeter. The problem comes when I disconnect the source power from Arduino (an USB connection). For my surprise, the Arduino does not shutdown (some leds keep turned on), and seems to be powered by the 3V input (at the moment not a coin cell, but two AA batteries) connected to Analog pin.

Why is this happening? How is the Arduino taking current from the Analog Pin? Is this little circuit an electronic aberration?

Most, if not all, input pins on AVR controllers are internally protected by clamping diodes. These diodes prevent that an input voltage can be higher than the supply voltage.

Why these internal diodes are there:

It is important to realize that when an input pin does rise above the supply voltage and these diodes weren't there, the chip might act as an SCR, latch, short the battery, and the chip itself would probably get damaged by overcurrent/overheating.

Why your Arduino runs from the battery Take a look at the circuit diagram below. When Vcc is detached from the normal power source, there is a path from the battery, via D1, to Vcc. The battery voltage is just high enough for the controller to operate.

simulate this circuit – Schematic created using CircuitLab

How to solve it

The solution is simple, add a high value resistor in series between the battery and the controller's input. Most AVR's have a maximum input leakage current specified (IIL) of 1μA, so you want to make sure the voltage drop is acceptable with that current, say 100kΩ.

But beware!

You do have to realize that the input may draw this current from your button cell and shorten its life time.