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. Monitoring 2 x 18650 batteries

Monitoring 2 x 18650 batteries

Scheduled Pinned Locked Moved Troubleshooting
18 Posts 7 Posters 1.6k Views 6 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.
  • mfalkviddM mfalkvidd

    @crumpy10 do you have analogReference(INTERNAL); in setup()?
    Are you using a 3.3 or 5V device?

    C Offline
    C Offline
    Crumpy10
    wrote on last edited by
    #3

    @mfalkvidd I have left the analogReference as it was in the original like this-:

    void setup()
    {
    	// use the 1.1 V internal reference
    #if defined(__AVR_ATmega2560__)
    	analogReference(INTERNAL1V1);
    #else
    	analogReference(INTERNAL);
    #endif
    }
    
    void presentation()
    {
    	// Send the sketch version information to the gateway and Controller
    	sendSketchInfo("Battery Meter", "1.0");
    }
    

    Just for learning about battery monitoring, I am using a Nano with two 18650's in series to power it. in my final project I will be using a Pro Mini. Unfortunately the ultrasonic sensor I need to use is a 5v sensor and needs a good supply. Hence learning about monitoring the 18650's.
    Cheers.

    Thanks for the reply.

    1 Reply Last reply
    0
    • mfalkviddM Offline
      mfalkviddM Offline
      mfalkvidd
      Mod
      wrote on last edited by
      #4

      I did the calculations and got the same result as you, so that part seems ok.
      No sure what else to check :(

      C 1 Reply Last reply
      0
      • mfalkviddM mfalkvidd

        I did the calculations and got the same result as you, so that part seems ok.
        No sure what else to check :(

        C Offline
        C Offline
        Crumpy10
        wrote on last edited by
        #5

        @mfalkvidd Well thanks for looking at it, at least my maths is still working ok! Perhaps someone else may know whats going on...

        The strange thing is if I use this line-:

        float batteryV = sensorValue * 8.6 / 1023;
        

        I can get close. I found another thread where @TimO was using 7.2v with this in his sketch-:

        float batteryV = sensorValue * 6.1 / 1023;
        

        So I just increased the 6.1 slowly until my read value was close to my multimeter voltage. But I dont understand what the 6.1 in this line of code is doing, or where it comes from...

        mfalkviddM 1 Reply Last reply
        0
        • C Crumpy10

          @mfalkvidd Well thanks for looking at it, at least my maths is still working ok! Perhaps someone else may know whats going on...

          The strange thing is if I use this line-:

          float batteryV = sensorValue * 8.6 / 1023;
          

          I can get close. I found another thread where @TimO was using 7.2v with this in his sketch-:

          float batteryV = sensorValue * 6.1 / 1023;
          

          So I just increased the 6.1 slowly until my read value was close to my multimeter voltage. But I dont understand what the 6.1 in this line of code is doing, or where it comes from...

          mfalkviddM Offline
          mfalkviddM Offline
          mfalkvidd
          Mod
          wrote on last edited by
          #6

          @crumpy10 maybe double-check that the resistors have the values you think they have?

          Nca78N C 2 Replies Last reply
          1
          • mfalkviddM mfalkvidd

            @crumpy10 maybe double-check that the resistors have the values you think they have?

            Nca78N Offline
            Nca78N Offline
            Nca78
            Hardware Contributor
            wrote on last edited by
            #7

            @mfalkvidd said in Monitoring 2 x 18650 batteries:

            @crumpy10 maybe double-check that the resistors have the values you think they have?

            That + imprecision of the voltage reference. If I remember well, it's stable over time, but not precisely at 1.1V.

            zboblamontZ 1 Reply Last reply
            0
            • electrikE Offline
              electrikE Offline
              electrik
              wrote on last edited by
              #8

              You mentioned your two resistors, but how they are placed? So which one is connected to gnd and which one to the batteries?

              C 1 Reply Last reply
              0
              • Nca78N Nca78

                @mfalkvidd said in Monitoring 2 x 18650 batteries:

                @crumpy10 maybe double-check that the resistors have the values you think they have?

                That + imprecision of the voltage reference. If I remember well, it's stable over time, but not precisely at 1.1V.

                zboblamontZ Offline
                zboblamontZ Offline
                zboblamont
                wrote on last edited by
                #9

                @nca78 Correct, easily verified and corrected for however...

                1 Reply Last reply
                0
                • K Offline
                  K Offline
                  kimot
                  wrote on last edited by
                  #10

                  My way for monitoring battery.
                  Usually I have not got precise resistor with tolerance +-0.5% etc. for correct calculation, so I build resistor divider with what I approximately found.
                  Load my device with simple sketch, which reads data from ADC and write this raw ADC data to serial port.
                  I make notice, that for example 1009 corresponds to 6041mV with fresh battery measured with multimeter.
                  In my final sketch then using "magic" map Arduino function:

                  int raw_volt = analogRead(A1);
                  
                  int volt = map(raw_volt, 0, 1009, 0, 6041);
                  

                  Not very useful for "mass production", but for my prototyping it is ok.

                  Nca78N 1 Reply Last reply
                  0
                  • electrikE electrik

                    You mentioned your two resistors, but how they are placed? So which one is connected to gnd and which one to the batteries?

                    C Offline
                    C Offline
                    Crumpy10
                    wrote on last edited by
                    #11

                    @electrik Hi, the 2.2Meg is connected to the battery and the 330k is connected to GND.

                    Cheers

                    1 Reply Last reply
                    0
                    • mfalkviddM mfalkvidd

                      @crumpy10 maybe double-check that the resistors have the values you think they have?

                      C Offline
                      C Offline
                      Crumpy10
                      wrote on last edited by
                      #12

                      @mfalkvidd been there already but thanks.

                      1 Reply Last reply
                      0
                      • electrikE Offline
                        electrikE Offline
                        electrik
                        wrote on last edited by
                        #13

                        What is the value you read from the analog port, when the battery is 8.4v? So the value before calculating the voltage.

                        C 1 Reply Last reply
                        0
                        • K kimot

                          My way for monitoring battery.
                          Usually I have not got precise resistor with tolerance +-0.5% etc. for correct calculation, so I build resistor divider with what I approximately found.
                          Load my device with simple sketch, which reads data from ADC and write this raw ADC data to serial port.
                          I make notice, that for example 1009 corresponds to 6041mV with fresh battery measured with multimeter.
                          In my final sketch then using "magic" map Arduino function:

                          int raw_volt = analogRead(A1);
                          
                          int volt = map(raw_volt, 0, 1009, 0, 6041);
                          

                          Not very useful for "mass production", but for my prototyping it is ok.

                          Nca78N Offline
                          Nca78N Offline
                          Nca78
                          Hardware Contributor
                          wrote on last edited by
                          #14

                          @kimot said in Monitoring 2 x 18650 batteries:

                          My way for monitoring battery.
                          Usually I have not got precise resistor with tolerance +-0.5% etc. for correct calculation, so I build resistor divider with what I approximately found.
                          Load my device with simple sketch, which reads data from ADC and write this raw ADC data to serial port.
                          I make notice, that for example 1009 corresponds to 6041mV with fresh battery measured with multimeter.
                          In my final sketch then using "magic" map Arduino function:

                          int raw_volt = analogRead(A1);
                          
                          int volt = map(raw_volt, 0, 1009, 0, 6041);
                          

                          Not very useful for "mass production", but for my prototyping it is ok.

                          For "mass production", you would run a config script, with known vcc applied to the board, and save measured value in EEPROM. Then you just have to reload this value to pass to the map function.

                          1 Reply Last reply
                          0
                          • electrikE electrik

                            What is the value you read from the analog port, when the battery is 8.4v? So the value before calculating the voltage.

                            C Offline
                            C Offline
                            Crumpy10
                            wrote on last edited by
                            #15

                            @electrik Not sure what it would be at 8.4v because that would be two fully charged 18650's and the two I have on test are currently giving 7.80v on the multimeter and returning about 870 on the serial monitor, reporting battery at 0.94v and 86%

                            I would need to fully recharge two batteries later to tell what the max would be.

                            zboblamontZ 1 Reply Last reply
                            0
                            • C Crumpy10

                              @electrik Not sure what it would be at 8.4v because that would be two fully charged 18650's and the two I have on test are currently giving 7.80v on the multimeter and returning about 870 on the serial monitor, reporting battery at 0.94v and 86%

                              I would need to fully recharge two batteries later to tell what the max would be.

                              zboblamontZ Offline
                              zboblamontZ Offline
                              zboblamont
                              wrote on last edited by zboblamont
                              #16

                              @crumpy10 Am a bit rusty on this, but would an ADC reading 870 on a 7.8v supply not translate to an ADC reading of 1023 and 9.17v.?
                              Replacing the 6.1 factor in "float batteryV = sensorValue * 6.1 / 1023;" with 9.17 will derive the true voltage.
                              As to the weird results, it suggests the INTERNAL reference is not latching, perhaps remark out the #if define... etc lines to leave "analogReference(INTERNAL);" entirely on it's own.

                              1 Reply Last reply
                              0
                              • electrikE Offline
                                electrikE Offline
                                electrik
                                wrote on last edited by
                                #17

                                You should know at what voltage level the ADC tells you 1023. It can be 1,1 but if it is at 1,12 you're already far off with your calculation.
                                So probably calibrating like mentioned above would be the best.

                                1 Reply Last reply
                                0
                                • T Offline
                                  T Offline
                                  tochinet
                                  wrote on last edited by
                                  #18

                                  A few "reality checks" with ADCs :

                                  • The precision of the ADC is limited to 0.1% at full scale (1024). This means that when measuring smaller values, it's less precise. For example, when measuring 1/10 of the reference, your precision is down to 1% already.
                                  • Analog noise is usually in the range of 10mV is your circuit is carefully designed. Similar to above, it has a bigger effect on small values, but also on smaller references (1.1V is 3x more sensible to noise than 3.3V). Add a 10nF capacity in parallel to your 330k for better resilience.
                                  • ADC is slow and needs time to calculate. Wait enough time between changing parameters and reading value (the Ardunio routines don't).

                                  I'd suggest you do a for() loop of 20x reading your ADC, and see the variation : mean(), std() and trend (for example last 5 - first 5). It could learn you a few things.

                                  1 Reply Last reply
                                  2
                                  Reply
                                  • Reply as topic
                                  Log in to reply
                                  • Oldest to Newest
                                  • Newest to Oldest
                                  • Most Votes


                                  19

                                  Online

                                  11.7k

                                  Users

                                  11.2k

                                  Topics

                                  113.1k

                                  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