9
\$\begingroup\$

I am powering an Arduino using a 5v battery (3.7v to a step-up module), and I need to measure the voltage. Let's say the battery delivers high current, is it safe to measure the voltage via Analog In? As in this:

enter image description here

The reason I'm asking is that I don't know much about the Arduino's ADC architecture and limitations. So normally, I'd do so for safety:

enter image description here

Are the connections in the first diagram safe for the ADC? Thanks in advance!

Note: A similar question was asked here: (Monitor DC Power Usage), but it doesn't answer the question of high current loads on the battery.

\$\endgroup\$
  • 1
    \$\begingroup\$ Where did you get a 5V battery? \$\endgroup\$ – user17592 Apr 7 '13 at 17:11
  • \$\begingroup\$ Actually it's a 3.7v battery that goes into a step-up voltage regulator circuit. I am indeed interested in measuring the 3.7v battery itself, but for the sake of example, just assumed its 5v to show that the Arduino is working. \$\endgroup\$ – Ahmed Farid Apr 7 '13 at 17:13
  • \$\begingroup\$ Ah, but it might change things. Probably not though: the arduino won't care how much current is drawn by the battery, as long as not all that current goes through the IO pin. But I'm not sure, I don't know arduino. \$\endgroup\$ – user17592 Apr 7 '13 at 17:14
  • \$\begingroup\$ That's true. I'm worried about the current input to the Analog In pin if I directly connect it to a battery. \$\endgroup\$ – Ahmed Farid Apr 7 '13 at 17:18
6
\$\begingroup\$

Check the datasheet for the input current on a I/O pin It depens on the exact type of controller on your Arduino. It is probably called Input Leakage Current I/O pin and will be near 1μA.

Here is a typical ATmega datasheet used on Uno / Duemilanove / ... , you can find the parameter on page 304. Check the datasheet for your specific controller for accurate details.

If you use a 3.7V battery and a step up converter to supply 5V to the controller, you can connect the battery directly to your controller analog input. However when the output voltage of the step up converter drops below the voltage of the battery (for whatever reason) then your entire Arduino will be fed through the analog input pin and that is what you don't want. All input pins have protection against overvoltage which enables this behaviour, but the diodes are not rated for continuous currents. In conclusion: it is best to include a series resistor between battery and input pin.

But now your measurement relies on the accuracy of the 5V power supply. Depending on which exact controller you have, there are various internal reference voltages available which are far more accurate than the power supply voltage. If you add an extra resistor to ground (R2) you can use such a reference to accurately measure the input voltage. This is called a (resistive) voltage divider. With the given ratio, the voltaga on the input pin will be 1V when the battery voltage is 3.7V:

\$V_{measurement} = \dfrac{R2×V_{BATT}}{R1+R2}\$

schematic

simulate this circuit – Schematic created using CircuitLab

\$\endgroup\$
  • 1
    \$\begingroup\$ So in essence, it is possible to connect it directly to a battery but NOT recommended if the 5v varies. Even if the 5v is regulated and constant? \$\endgroup\$ – Ahmed Farid Apr 7 '13 at 18:11
  • 2
    \$\begingroup\$ It should be safe if 5V is constant, but things go wrong all the time so: better safe than sorry. One or two resistors are much cheaper than a new microcontroller. Engineering is not only about making things work, it is also about making things that keep working as required. \$\endgroup\$ – jippie Apr 7 '13 at 18:15
  • \$\begingroup\$ Another question if I may: Isn't a single resistance (1K) in parallel to the battery good enough to prevent a high current input? (See my second figure) \$\endgroup\$ – Ahmed Farid Apr 7 '13 at 18:19
  • \$\begingroup\$ No, it does nothing other than draw the battery. \$\endgroup\$ – jippie Apr 7 '13 at 18:20
4
\$\begingroup\$

Another option is to use the Arduino's internal 1.1V bandgap voltage reference to determine the value of VCC without the use of any additional external parts as detailed at these two links:

http://jeelabs.org/2012/05/04/measuring-vcc-via-the-bandgap/

and

http://arduino.cc/forum/index.php?topic=88935.0

The only gotcha is that you need to determine a calibration value against the internal 1.1V bandgap since it can be off by as much as 10%.

But that would require no additional parts, and would allow your atmega to determine the voltage of its power source.

\$\endgroup\$
  • 3
    \$\begingroup\$ Here is another article which discusses how to do this. The code it uses is slightly different: provideyourown.com/2012/… \$\endgroup\$ – ThomasW Jun 4 '13 at 6:44
  • \$\begingroup\$ @ThomasW nice! Another great article on using the 1.1v bandgap. \$\endgroup\$ – Wing Tang Wong Jun 4 '13 at 20:29

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.