Maker Pro
Maker Pro

detecting battery charge level

mikgol

Jul 6, 2013
87
Joined
Jul 6, 2013
Messages
87
Hi there,

What's a low cost and simple way for an arduino to monitor it's own battery level?
Should I feed the + from the battery though a resistor to an analog pin and measure it there? Or is it more complicated than that?

Cheers
 

Gryd3

Jun 25, 2014
4,098
Joined
Jun 25, 2014
Messages
4,098
Hi there,

What's a low cost and simple way for an arduino to monitor it's own battery level?
Should I feed the + from the battery though a resistor to an analog pin and measure it there? Or is it more complicated than that?

Cheers
You need to monitor the batter voltage, but it's not quite that easy...
If you want to use an analogue input, you need to be sure that the 'reference' it is using to be able to convert the input to a value is consistent...
That will require looking at the data sheet for the μC used in the Arduino you decide to use. If there is not stable reference you will need to make your own.
From there, you need to be sure you measure the voltage while it is under 'load'. If you simply detect the voltage while the battery is not doing anything, the reading will be higher than expected... and when you finally 'do' something, the voltage will dip and the Arduino may lock or, brown-out, or behave unexpectedly.
So... as long as you satisfy the 'reference' and only measure while you are doing something then yes... you can do a battery level monitor / alarm.
*Note! Rechargeable batteries have a lower voltage than disposable!
Getting a 'time' or 'percentage' of a battery may be difficult and requires you to know the specific discharge curve for the battery in question. You can always guess, or simply choose a couple thresholds and call it low, med, and full. This is up to you of course.
 

mikgol

Jul 6, 2013
87
Joined
Jul 6, 2013
Messages
87
Thanks for your help guys. By reference I assume that this would be a separate power supply - if that's the case, does that make it impossible to do this if there is only one battery source that powers the arduino and needs to be measured?
 

hevans1944

Hop - AC8NS
Jun 21, 2012
4,878
Joined
Jun 21, 2012
Messages
4,878
Thanks for your help guys. By reference I assume that this would be a separate power supply - if that's the case, does that make it impossible to do this if there is only one battery source that powers the arduino and needs to be measured?
No, the reference voltage is a circuit that derives its power from the battery you are trying to measure but provides a stable reference voltage as the battery voltage varies. You can purchase an IC that does this. And the multiple analog comparators suggested by @cjdelphi is also a viable approach with possibly less programming involved.
 

mikgol

Jul 6, 2013
87
Joined
Jul 6, 2013
Messages
87
Awesome, thanks for pointing me in the right direction guys. I'll try the multiple analog comparators approach - cheers @cjdelphi
 

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
Jan 21, 2010
25,510
Joined
Jan 21, 2010
Messages
25,510
The easy way is to measure the internal 1.1V reference and then compare it to Vcc.

Note that the internal reference can vary by up to 10%.
 

mikgol

Jul 6, 2013
87
Joined
Jul 6, 2013
Messages
87
Thanks Steve, I'll look into that as well. 10% variance should be OK, I just need a rough guide to sound a "change battery" alarm.
 

hevans1944

Hop - AC8NS
Jun 21, 2012
4,878
Joined
Jun 21, 2012
Messages
4,878
Hi there,

What's a low cost and simple way for an arduino to monitor it's own battery level?
Should I feed the + from the battery though a resistor to an analog pin and measure it there? Or is it more complicated than that?

Cheers
I would build a voltage divider to reduce the analog input by 50%, because the battery voltage could be considerably larger than the Arduino's voltage-regulated 5 V. It isn't uncommon to power an Arduino from a 9 V battery so reducing this to 4.5 V before measuring it is desirable. The Arduino will digitize (convert from analog to digital) an analog signal between 0 V and 5 V as a digital value from 0 to 255. So, 4.5 V is 90% of the full-scale range, and your program could set an alarm when the digitized value is significantly less than 255 counts and it is time to change the battery. How much less? That depends on what the minimum voltage requirement for the Arduino on-board voltage regulator is. Most three-terminal regulators (except for low-dropout or LDO regulators) need about 2 V more than the regulator voltage output, so about 7 V for a 5 V output. When the 9 V battery voltage drops below 7 V it is time to change the battery. That would be 3.5 V at the measuring input, which is 3.5/5.0 or about 178 counts out of 255 full-scale counts. Set this as the "trip" level for your alarm.

By using the voltage divider, you are effectively making the full-scale range of the A/D converter larger at the sacrifice of resolution. A divider that reduces the battery voltage to 50% effectively boosts the full scale range of the A/D converter 10 volts. Bear in mind that the voltage divider is a constant load across your battery, so use as large a value for the two resistors as the A/D input impedance will tolerate... two 33 kΩ resistors in series is probably as large as you can get away with. However, you could also use a MOSFET switch or a relay, controlled by the Arduino, to apply battery voltage to the voltage divider only at periodic intervals, leaving the divider connected only long enough to make the voltage measurement. That will considerably extend the life of the battery and even allow you to use a "stiffer" voltage divider with lower-valued resistors. That could even be a "feature" that loads the battery and produces a more realistic evaluation of battery condition. Lots of room to experiment here, but get the basic voltage measuring circuit working first.
 
Last edited:

BobK

Jan 5, 2010
7,682
Joined
Jan 5, 2010
Messages
7,682
Don't know if this is possible with Arduino, but here is a good trick to do this on PICs.

PICs have an internal precision reference, which is settable to 1.024, 2.048 or 4.096V. You can measure this voltage with the A/D using the battery voltage as the reference for the A/D. From that you can calculate the actual battery voltage.

Bob
 

BlackMelon

Aug 7, 2012
188
Joined
Aug 7, 2012
Messages
188
Don't know if this is possible with Arduino, but here is a good trick to do this on PICs.

PICs have an internal precision reference, which is settable to 1.024, 2.048 or 4.096V. You can measure this voltage with the A/D using the battery voltage as the reference for the A/D. From that you can calculate the actual battery voltage.

Bob

As I interpreted your words, the 4.096V reference will always be constant, the battery voltage will continually drop. Then, we have to compare the 4.096V with the battery voltage, which is reduced by a voltage divider first to be able to feed to the PIC. Am I correct??
 

Gryd3

Jun 25, 2014
4,098
Joined
Jun 25, 2014
Messages
4,098
As I interpreted your words, the 4.096V reference will always be constant, the battery voltage will continually drop. Then, we have to compare the 4.096V with the battery voltage, which is reduced by a voltage divider first to be able to feed to the PIC. Am I correct??
you can use either one as a reference, but the whole idea here is to measure the battery voltage AND a known reference voltage. Otherwise relying on the A/D by itself may give skewed results... as the A/D conversion may drift as the supply voltage drops.
 

BobK

Jan 5, 2010
7,682
Joined
Jan 5, 2010
Messages
7,682
Is the battery going directly to the Vdd supply of the micro or are you going through a regulator first?

Bob
 
Top