Connect with us

detecting battery charge level

Discussion in 'Power Electronics' started by mikgol, Mar 16, 2016.

Scroll to continue with content
  1. mikgol

    mikgol

    87
    1
    Jul 6, 2013
    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
     
  2. Gryd3

    Gryd3

    4,098
    875
    Jun 25, 2014
    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.
     
  3. cjdelphi

    cjdelphi

    1,096
    104
    Oct 26, 2011
    Edit... might be easier to use a comparitor
     
    Gryd3 likes this.
  4. mikgol

    mikgol

    87
    1
    Jul 6, 2013
    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?
     
  5. hevans1944

    hevans1944 Hop - AC8NS

    4,631
    2,159
    Jun 21, 2012
    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.
     
  6. mikgol

    mikgol

    87
    1
    Jul 6, 2013
    Awesome, thanks for pointing me in the right direction guys. I'll try the multiple analog comparators approach - cheers @cjdelphi
     
  7. (*steve*)

    (*steve*) ¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd Moderator

    25,500
    2,840
    Jan 21, 2010
    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%.
     
    hevans1944 likes this.
  8. mikgol

    mikgol

    87
    1
    Jul 6, 2013
    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.
     
  9. cjdelphi

    cjdelphi

    1,096
    104
    Oct 26, 2011
    What's the voltage(s)?
     
  10. hevans1944

    hevans1944 Hop - AC8NS

    4,631
    2,159
    Jun 21, 2012
    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: Mar 16, 2016
  11. BobK

    BobK

    7,682
    1,688
    Jan 5, 2010
    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
     
    Gryd3 likes this.
  12. cjdelphi

    cjdelphi

    1,096
    104
    Oct 26, 2011
  13. BlackMelon

    BlackMelon

    188
    5
    Aug 7, 2012
    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 likes this.
  14. Gryd3

    Gryd3

    4,098
    875
    Jun 25, 2014
    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.
     
  15. BobK

    BobK

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

    Bob
     
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day

-