Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Troubleshooting
  3. Problem with battery level value

Problem with battery level value

Scheduled Pinned Locked Moved Troubleshooting
12 Posts 3 Posters 8.2k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mattia Reggiani
    wrote on last edited by
    #1

    Good morning,
    Congratulations for this fantastic project ; are my first steps with Arduino and I have a litle problem with battery monitor on Arduino Pro Mini 5V, I use the sketch and instructions find in this page http://www.mysensors.org/build/battery , but the value read in pin A0 is always 1023, i have try othe analog pin with the same result
    In touch point however the value is 1,4 /1,5 measured with digital multimeter, in pin a0 the value is the same.
    The sensor is powered from 4 AA battery 1,5V .
    I do not understand where wrong.

    Sorry for the English is not perfect

    Thanks
    Mattia

    B 1 Reply Last reply
    0
    • M Mattia Reggiani

      Good morning,
      Congratulations for this fantastic project ; are my first steps with Arduino and I have a litle problem with battery monitor on Arduino Pro Mini 5V, I use the sketch and instructions find in this page http://www.mysensors.org/build/battery , but the value read in pin A0 is always 1023, i have try othe analog pin with the same result
      In touch point however the value is 1,4 /1,5 measured with digital multimeter, in pin a0 the value is the same.
      The sensor is powered from 4 AA battery 1,5V .
      I do not understand where wrong.

      Sorry for the English is not perfect

      Thanks
      Mattia

      B Offline
      B Offline
      boozz
      wrote on last edited by boozz
      #2

      @Mattia-Reggiani

      In the sketch a internal voltage reference of 1.1 V is used. This means that if a value of 1.1V or higher is measured at the A0 input, you'll read the max int value, which is 1023.

      Two options :

      1. Change the voltage divider to get maximum of 1.1 V if the batteries supply app. 6 V (4x1.5 V). instead of the 470k you could use 230k or instead of the 1M you could use 2M.

      or
      2. don't use the internal reference of 1.1V.

      I would go for the first option.

      some additional info on the internal voltage reference of the arduino to be found here

      Note that 4x1.5 VDC is 6 VDC, with a fresh set of batteries possibly higher. you probably connect it to the raw input, so that the step down converter build on the pro-mini will do its work.

      Succes!

      Boozz

      1 Reply Last reply
      0
      • M Offline
        M Offline
        Mattia Reggiani
        wrote on last edited by
        #3

        @boozz
        Many Thanks, now I understand but I still have doubts, in the skecth i have change this
        float batteryV = sensorValue * 0.003363075;
        in
        float batteryV = sensorValue * 0.00575035;

        because if I understand it ((1e6+470e3)/470e3)*1.1 = Vmax = 3.44 Volts
        in my case is ((1+0,23)/0,23)*1,1 = 5,88 and after 5,88/1023 = 0,0057478
        Now, however with new battery the output is

        99
        Battery Voltage: 0.57 V
        Battery percent: 9 %
        :(

        The code i used is
        // get the battery Voltage
        int sensorValue = analogRead(BATTERY_SENSE_PIN);
        Serial.println(sensorValue);
        // 1M, 470K divider across battery and using internal ADC ref of 1.1V
        // Sense point is bypassed with 0.1 uF cap to reduce noise at that point
        // ((1e6+470e3)/470e3)*1.1 = Vmax = 3.44 Volts
        // 3.44/1023 = Volts per bit = 0.003363075
        float batteryV = sensorValue * 0.00575035;
        int batteryPcnt = sensorValue / 10;

        Thanks
        Mattia

        B 1 Reply Last reply
        0
        • T Offline
          T Offline
          TimO
          Hero Member
          wrote on last edited by
          #4

          Did you change the divider?

          In my temperature sensor i measure the battery level with:

          R1: 1 MOhm
          R2: 220 kOHM

          float batteryV = sensorValue * 6.1 / 1023;
          

          With an input voltage of 7.2 V the dividers gives 1.1 V (1023) on the analog input.

          Don't forget to place a capacitor between AREF & GND to stabilize the measurement.

          1 Reply Last reply
          0
          • M Mattia Reggiani

            @boozz
            Many Thanks, now I understand but I still have doubts, in the skecth i have change this
            float batteryV = sensorValue * 0.003363075;
            in
            float batteryV = sensorValue * 0.00575035;

            because if I understand it ((1e6+470e3)/470e3)*1.1 = Vmax = 3.44 Volts
            in my case is ((1+0,23)/0,23)*1,1 = 5,88 and after 5,88/1023 = 0,0057478
            Now, however with new battery the output is

            99
            Battery Voltage: 0.57 V
            Battery percent: 9 %
            :(

            The code i used is
            // get the battery Voltage
            int sensorValue = analogRead(BATTERY_SENSE_PIN);
            Serial.println(sensorValue);
            // 1M, 470K divider across battery and using internal ADC ref of 1.1V
            // Sense point is bypassed with 0.1 uF cap to reduce noise at that point
            // ((1e6+470e3)/470e3)*1.1 = Vmax = 3.44 Volts
            // 3.44/1023 = Volts per bit = 0.003363075
            float batteryV = sensorValue * 0.00575035;
            int batteryPcnt = sensorValue / 10;

            Thanks
            Mattia

            B Offline
            B Offline
            boozz
            wrote on last edited by
            #5

            @Mattia-Reggiani
            As TimO already asked: did you change the divider? (replace the resistor 470k into a resistor 220k or the 1M into 2M)? it's essential.

            Boozz

            1 Reply Last reply
            0
            • M Offline
              M Offline
              Mattia Reggiani
              wrote on last edited by
              #6

              I have change R1 to 2M and R2 470k , I think to have some problem with resistors, tomorrow will buy new resistors and try again from scratch.

              Thanks for your help
              Mattia

              1 Reply Last reply
              0
              • M Offline
                M Offline
                Mattia Reggiani
                wrote on last edited by
                #7

                I have rebuild the dividers with R1 1M ohm and R2 220k ohm, i have try with pin A1 and A0 and have strange value

                990
                Battery Voltage: 5.59 V
                Battery percent: 99 %

                1023
                Battery Voltage: 5.78 V
                Battery percent: 102 %

                First read is correct, but after this all other value have value 1023, if use multimeter on R1 and R2 have a value of 0,93 on touch point have 0,93 and on the Pin A0 or A1 have the same value.
                It is possible that Arduino read the wrong value ?

                1 Reply Last reply
                0
                • T Offline
                  T Offline
                  TimO
                  Hero Member
                  wrote on last edited by
                  #8

                  Did you place a capacitor between AREF and GND?

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    Mattia Reggiani
                    wrote on last edited by
                    #9

                    @TimO
                    Sorry, but Whatsapp is AREF? Is the Pin thai I use to measure the battery voltage (A0) ? Bcause on Google i find some Arduino Board with AREF pin but my Arduino mini pro has not that pin.

                    Thanks
                    Mattia

                    1 Reply Last reply
                    0
                    • T Offline
                      T Offline
                      TimO
                      Hero Member
                      wrote on last edited by TimO
                      #10

                      Oh, I'm sorry, at the Arduino pro mini there already is a capacitor between AREF & GND, so don't worry about it.

                      Here is my working example, a sensor for humidity, temperature and status of the battery:

                      link text

                      It's basically:

                      line 30: with "analogReference("INTERNAL)", did you call that?

                      The function in line 70 measures the battery status.

                      1 Reply Last reply
                      0
                      • M Offline
                        M Offline
                        Mattia Reggiani
                        wrote on last edited by
                        #11

                        @TimO @boozz
                        Finally there I did, the problem was due by the resistances; I bought the new resistors
                        2M Ohm and 470k Ohm and now works correctly.

                        Thank you all for your support and for your patience

                        (Now I have a little more knowledge on electronics :) )

                        Mattia

                        B 1 Reply Last reply
                        0
                        • M Mattia Reggiani

                          @TimO @boozz
                          Finally there I did, the problem was due by the resistances; I bought the new resistors
                          2M Ohm and 470k Ohm and now works correctly.

                          Thank you all for your support and for your patience

                          (Now I have a little more knowledge on electronics :) )

                          Mattia

                          B Offline
                          B Offline
                          boozz
                          wrote on last edited by
                          #12

                          @Mattia-Reggiani
                          Good to see that you solved it and learned by doing. Congrats!

                          Boozz

                          1 Reply Last reply
                          0

                          Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                          Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                          With your input, this post could be even better 💗

                          Register Login
                          Reply
                          • Reply as topic
                          Log in to reply
                          • Oldest to Newest
                          • Newest to Oldest
                          • Most Votes


                          55

                          Online

                          12.0k

                          Users

                          11.2k

                          Topics

                          113.4k

                          Posts


                          Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
                          • Login

                          • Don't have an account? Register

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • MySensors
                          • OpenHardware.io
                          • Categories
                          • Recent
                          • Tags
                          • Popular