10
\$\begingroup\$

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?

enter image description here

\$\endgroup\$
10
\$\begingroup\$

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.

schematic

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.

\$\endgroup\$
  • \$\begingroup\$ I'd try 10Mohm and see what the ADC reads and use that as your reference for a charged battery. Tis a tricky measurement if you want to avoid unwanted drainage. \$\endgroup\$ – Andy aka May 22 '13 at 21:26
  • \$\begingroup\$ That could work, though it is spec'd as an input current and not as a input impedance. Response may be non linear, but not necessarily useless. It might need some sort of calibration and maybe the 1V1 band gap reference can be used (instead of 3V3 external reference) when the measured voltage drops below 1.1V. \$\endgroup\$ – jippie May 22 '13 at 21:29
  • \$\begingroup\$ Nice answer!! I was thinking if a resistor divider with 100kΩ and 50kΩ will work. In this case, I am supposing a max battery voltage of 3.2 volts. This gives a 1.067v drop voltage, which can be compatible with the internal analog reference of 1v1. This can work? or will drain the battery too soon? \$\endgroup\$ – alvarolb May 22 '13 at 21:38
  • 2
    \$\begingroup\$ I don't know the capacity of your battery. It should be specified in mAh. A coarse indication of it's lifetime would be \$T = \dfrac{\text{mAh}}{\frac{3V×1000}{100kΩ+50kΩ}} = \dfrac{\text{mAh × (100kΩ+50kΩ)}}{3V×1000}\$. A coin cell may not last very long, but you should check the datasheet to be sure. \$\endgroup\$ – jippie May 22 '13 at 21:44
  • 1
    \$\begingroup\$ These diodes are present on most microcontrollers in general - not just AVR. They're not unheard of on other types of ICs as well. \$\endgroup\$ – Adam Lawrence May 22 '13 at 21:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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