# Monitoring Voltage Level From Arduino.

**URL:** <https://community.sparkfun.com/t/monitoring-voltage-level-from-arduino/22658>\
**Category:** Arduino\
**Created:** [December 1, 2011, 2:38am UTC](https://community.sparkfun.com/t/monitoring-voltage-level-from-arduino/22658 "2011-12-01T02:38:54Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![moorejohn90](https://avatars.discourse-cdn.com/v4/letter/m/2acd7d/32.png) [@moorejohn90](https://community.sparkfun.com/u/moorejohn90)\
**Post date:** [December 1, 2011, 2:38am UTC](https://community.sparkfun.com/t/monitoring-voltage-level-from-arduino/22658/1 "2011-12-01T02:38:54Z")

</div>

Is there any way of monitoring Voltage level of battery from arduino.

I want to monitor voltage level of battery that is connected to motor in my robot.

Thanks.

---

<div class="post-metadata">

**Author:** ![leon\_heller](https://yyz1.discourse-cdn.com/sparkfun/user_avatar/community.sparkfun.com/leon_heller/32/7602_2.png) [@leon\_heller](https://community.sparkfun.com/u/leon_heller)\
**Post date:** [December 1, 2011, 3:13am UTC](https://community.sparkfun.com/t/monitoring-voltage-level-from-arduino/22658/2 "2011-12-01T03:13:45Z")

</div>

Use the ADC.

---

<div class="post-metadata">

**Author:** ![moorejohn90](https://avatars.discourse-cdn.com/v4/letter/m/2acd7d/32.png) [@moorejohn90](https://community.sparkfun.com/u/moorejohn90)\
**Post date:** [December 1, 2011, 4:50am UTC](https://community.sparkfun.com/t/monitoring-voltage-level-from-arduino/22658/3 "2011-12-01T04:50:17Z")

</div>

Thank leon\_heller, I want to read the input Voltage is more than 5V (12V) that arudino support.

How to convert 12 to 5 v for getting correct result, 1- using Voltage regulator or 2- Voltage Driver (with two resistors).

Thanks.

---

<div class="post-metadata">

**Author:** ![Mee\_n\_Mac](https://avatars.discourse-cdn.com/v4/letter/m/aeb1de/32.png) [@Mee\_n\_Mac](https://community.sparkfun.com/u/Mee_n_Mac)\
**Post date:** [December 1, 2011, 5:08am UTC](https://community.sparkfun.com/t/monitoring-voltage-level-from-arduino/22658/4 "2011-12-01T05:08:14Z")

</div>

> moorejohn90:  
> Thank leon\_heller, I want to read the input Voltage is more than 5V (12V) that arudino support.
> 
> How to convert 12 to 5 v for getting correct result, 1- using Voltage regulator or 2- Voltage Driver (with two resistors).
> 
> Thanks.

That would be #2, a voltage **\*\*divider\*\*** with 2 resistors. A voltage regulator takes a voltage that may range from some low to some high value and outputs a constant voltage. If you feed this constant voltage into the ADC it won't tell you anything about the regulators input voltage. The "trick" is to get the proper values for the 2 resistors so the Arduino's ADC makes an accurate measurement.

---

<div class="post-metadata">

**Author:** ![moorejohn90](https://avatars.discourse-cdn.com/v4/letter/m/2acd7d/32.png) [@moorejohn90](https://community.sparkfun.com/u/moorejohn90)\
**Post date:** [December 1, 2011, 12:09pm UTC](https://community.sparkfun.com/t/monitoring-voltage-level-from-arduino/22658/5 "2011-12-01T12:09:17Z")

</div>

Thank Mee\_n\_Mac for your advice.

---

<div class="post-metadata">

**Author:** ![fll-freak](https://avatars.discourse-cdn.com/v4/letter/f/49beb7/32.png) [@fll-freak](https://community.sparkfun.com/u/fll-freak)\
**Post date:** [December 1, 2011, 1:19pm UTC](https://community.sparkfun.com/t/monitoring-voltage-level-from-arduino/22658/6 "2011-12-01T13:19:33Z")

</div>

Just to add a bit of fuel to the fire, measuring voltage on a battery to guess at how much reserve capacity you have left is often an exercise in futility.

As an example, I have a single AA lithium battery that I have a 10 ohm resistor shorted across the terminals. The battery has been like this for weeks and is as dead as a door nail. If I measure the voltage across the terminals it is pretty much 0.0V. Now I disconnect the resistor and come back in 15 minutes. The battery now reads 1.7V just like a fresh battery. Replace the resistor and in short order the battery is back to 0.0V. Taking a measurement when the load was off would have indicated I had a fresh battery when in fact it is dead.

The above example is just one reason voltage is not a good indication of reserve. It is better than nothing, but only if the voltage is measured under load. A “real” solution (and those are not perfect by any means as well" is a dedicated “Coulomb” counter IC wired into the power distribution. These chips count electrons as they go by and decrement the count from how many electrons the battery is rated to push. The do pretty good but fall apart as rechargeable batteries age, or under temperature extremes.

---

<div class="post-metadata">

**Author:** ![green47](https://avatars.discourse-cdn.com/v4/letter/g/7feea3/32.png) [@green47](https://community.sparkfun.com/u/green47)\
**Post date:** [December 19, 2011, 11:08pm UTC](https://community.sparkfun.com/t/monitoring-voltage-level-from-arduino/22658/7 "2011-12-19T23:08:03Z")

</div>

an extra hint on the simpler voltage divider solution, be sure to pick fairly high resistors (10k+) to minimize current, otherwise you’ll drain your battery just by trying to measure it all the time. as an example, i’m reading a 0-5v analog signal on a 3.3v arduino with a divider made up of 18k and 33k resistors.

---

<div class="post-metadata">

**Author:** ![Valen](https://avatars.discourse-cdn.com/v4/letter/v/9dc877/32.png) [@Valen](https://community.sparkfun.com/u/Valen)\
**Post date:** [December 20, 2011, 12:17am UTC](https://community.sparkfun.com/t/monitoring-voltage-level-from-arduino/22658/8 "2011-12-20T00:17:13Z")

</div>

Even with just using a voltage divider you won’t know how much the battery level dropped. If the ADC compares the level of the voltage divider against Vcc (actually aVcc, like filtered battery voltage) then you only measure the divider ratio. As a drop in battery level results in proportional drop in voltage of the voltage divider. You need a voltage source that is independant of Vcc, or as much as possible constant. The good news is that AVR chips have one built in. (all Arduino bords have a AVR chip of some sort) This is often at 2.56 volt , or 1.3 volt in some devices iirc. Though could deviate based on temperature and manufacture tolerances. The ADC must select it as reference using the ADC multiplexer, and measure a pin on a voltage divider that has a level below the reference. Or, if the battery level is connected to the Aref pin then you could configure the ADC multiplexer to measure the internal voltage reference against the Aref pin. This is inverse battery level measurement, measuring the constant 2.56v against varying 5 volt. Math does the rest to make sense of it. I don’t know how this is configured with Arduino code though. You’ll have to investigate that yourself.

---

<div class="post-metadata">

**Author:** ![Philba](https://avatars.discourse-cdn.com/v4/letter/p/ed655f/32.png) [@Philba](https://community.sparkfun.com/u/Philba)\
**Post date:** [December 20, 2011, 5:18pm UTC](https://community.sparkfun.com/t/monitoring-voltage-level-from-arduino/22658/9 "2011-12-20T17:18:56Z")

</div>

What you want is analogreference() [http://www.arduino.cc/en/Reference/AnalogReference](http://www.arduino.cc/en/Reference/AnalogReference) to configure the ADC voltage reference.

You can divide down the Vbat to a bit below the reference voltage. If Vbat feeds the power supply in your system, you should have consistent readings until it falls below the power supply’s dropout voltage. As was mentioned earlier, you should consider the effect of battery load in your program. If you have a variable load (motors for example), then you will want to figure what constitutes a “discharged” level. For example, a motor start will pull your Vbat down and you would want to avoid false alarms.
