Battery Level Measurement

  • Hi Guys,

    Need your advice for arduino battery level measurement.
    The goal is that I want to monitor my battery consumption so I can get notice for battery replacement if it's already low.
    This is my setup. is it correct already? I'm using this link as reference.



  • Admin

    Do you want to power it directly with battery connected to VCC of the atmega? Then it's possible to measure the battery voltage without any external components.

  • Hardware Contributor

    @funky81 The wiring priciple is correct but you have to think of the components. Try six 1,5V cells in series, use R1=5Mohm (=two 10Mohm in parallell) and R2=680kohm and preferably a 0.1uF capacitor in parallell with R2. And some of the code below.
    One (major) drawback with the "secret external-component-less" method from @tbowmo is the Vcc becomes unregulated and it will be more difficult to use and interact with other things like sensors.

      Internal_ref=1.1V, res=10bit=2^10-1=1023, 
      Some different 1.5V cell (I use AAs) configurations and some suggested corresponding resistor value relations:
      2AA: Vin/Vbat=470e3/(1e6+470e3), 3AA: Vin/Vbat=680e3/(2.5e6+680e3), 4AA: Vin/Vbat=1e6/(1e6+5e6), 5-6AA: Vin/Vbat=680e3/(5e6+680e3), 6-8AA: Vin/Vbat=1e6/(1e6+10e6)  
      Example with 6AAs and R1=5Mohm (=two 10Mohm in parallell) and R2=680kohm:
      Vlim = 1.1*Vbat/Vin = 9.188235 V (Set eventually to Vmax) 
                              (9.2V = 1.53V/cell which is a little low for a fresh cell but let's say it's ok to stay at 100% for the first period of time)
      Volts per bit = Vlim/1023 = 0.008982
      Vmin = 6V (Min input voltage to regulator according to datasheet. Or guess Vout+1V )   DEFINE
      Vmax = 9.188235V (Known or desired voltage of full batteries. If not, set to Vlim.)  DEFINE
      Vpercent = 100*(Vbat-Vmin)/(Vmax-Vmin)
      // some code
    #define VMIN 6.0 // (Min input voltage to regulator according to datasheet or guessing. (?) )
    #define VMAX 9.188235 // (Known or desired voltage of full batteries. If not, set to Vlim.)
      // some code
    int BATTERY_SENSE_PIN = A0;  // select the input pin for the battery sense point
    int oldBatteryPcnt = 0;
      // some code
    void setup() {
      analogReference(INTERNAL);    // use the 1.1 V internal reference for battery level measuring
      // some code
    void loop() {
        // some code
      int sensorValue = analogRead(BATTERY_SENSE_PIN);    // Battery monitoring reading
    //  Serial.println(sensorValue);
      float Vbat  = sensorValue * 0.008982;
    //  Serial.print("Battery Voltage: "); Serial.print(Vbat); Serial.println(" V");
     //int batteryPcnt = sensorValue / 10;
      int batteryPcnt = static_cast<int>(((Vbat-VMIN)/(VMAX-VMIN))*100.);   
    //  Serial.print("Battery percent: "); Serial.print(batteryPcnt); Serial.println(" %");
      if (oldBatteryPcnt != batteryPcnt) {
        oldBatteryPcnt = batteryPcnt;
      // some code 

  • Admin

    It highly depends on what sensors you want to use.

    If you want to go battery powered, you really should invest some time in finding the right sensors that can be used at low voltages.

  • Hardware Contributor

    @tbowmo I agree.
    ... and something else than an Uno. Given that it actually is an Uno, I expect we're not really in to specialized sensors yet.
    And, sometimes opinions are not as helpful when we don't know the specification or application.

  • @tbowmo right now, the battery will be connected only to vin, coz it raw.
    my step up power converter (in this link) havent arrived yet. So i will use vin only.

    if it stable enough I will connect battery => step up power converter => vcc
    then i will use the link that you provide before

    is my theory correct?

  • @m26872 right now, i dont have any plans to use more than 2 batteries in series.
    but if i do, i will use step up power converter to stable it.

    but ofcourse this is my theory. am I correct ?

  • Admin


    If you use a step-up converter, then you need to use the design you made in first post.

    My method can only be used if you don't have any voltage regulators etc. between the battery and the atmel chip (f.ex. something like, which do not use any regulators, and the battery is connected directly to the atmel.

  • Hardware Contributor

    @funky81 I'm confused. Are you trying to use a 3.3v step-up to an 5V Uno?
    One or two 1.5V cells works great with a 3V-step-up setup like to power a 3V Arduino Pro Mini to Vcc as I do myself here BUT you can NOT supply a 5V-configuration.

  • @m26872 said:

    I'm confused. Are you trying to use a 3.3v step-up to an 5V Uno?

    I'm sorry to make you confused. Currently I'm using 3.3v arduino pro mini.
    What I mean is not step up converter, but step up power converter ( => to stablize 3.3v to maintain a steady 3.3 VDC even as the battery capacity diminishes. (like in this page

    Hmm..after I read your post (, it seems I have the same goal like you. I'll asked few thing in your thread, if that's okay with you 🙂

  • Hi @tbowmo, do you mind to explain a bit about the design? I'm interested with your design.

    I will use these steps for removing voltage regulator,
    So the design will be battery > external step up regulator ( - to stabilize 3.3v) > vcc pin ?

    with these then I can use my first post design?


Log in to reply

Suggested Topics