Another battery monitoring thread...


  • Hardware Contributor

    After making the custom in-wall light switch node that runs off of a 3v coin-cell battery i'm left thinking "Wouldn't it awesome if i could monitor the battery level and have the system act accordingly". So, after spending a few days sprawling the internet, i'm struggling to come to terms with the theory of monitoring the battery levels.

    I first started off by reading http://forum.mysensors.org/topic/186/new-library-to-read-arduino-vcc-supply-level-without-resistors-for-battery-powered-sensor-nodes-that-do-not-use-a-voltage-regulator-but-connect-directly-to-the-batteries/49 several time over with a vague understanding on the principles of the 'basic' method of using a voltage divider to find out the voltage of a connected point on the analog 0 pin with a analogRead(0) call. This is all well and good but like stated inside of that thread, when using battery power we need to lower the power draw to as low as possible (well as low as the uC sleep current and the current leakage on open pins). So, i then went on to look at reading a reference from the internal Vref like how the current sketch for mysensors works, however this is inaccurate to around 10%. I understand that we can 'calibrate' this method via a method known as 'secret multimeter'. I went ahead and tried to get this working from this blog post, I got it to the point it was reading 2.8v when i had a multimeter reading of 2.98v across VCC and GND.

    I get the principle and the methodology behind these two methods mentioned above, but i don't get how to incorporate this into the software, or even how to get it more accurate. I'm pretty sure that i'm doing something incorrect as 2.8v for an actual reading of 2.98 is pretty inaccurate.

    Basically what i'm looking for is the lowest power usage method, as accurate as it can be (within reasons) and i don't mind if i need to add physical components, if they will fit on my small footprint board. While this board uses the power straight from the battery itself without any regulators or step-up modules, i would like this method (or another method, if explained) to work on no matter what voltage/size battery is being used.

    Could someone try and explain or point me in the right direction to understand how i'm supposed to do this, that is if i'm doing it wrong, i just feel like i have it completely correct.

    The following links are all the information that i have been reading or watching to try and get my head around this, but still yet to come across the moment where it just 'clicks into place';

    http://forum.mysensors.org/topic/186/new-library-to-read-arduino-vcc-supply-level-without-resistors-for-battery-powered-sensor-nodes-that-do-not-use-a-voltage-regulator-but-connect-directly-to-the-batteries
    http://forum.mysensors.org/topic/2866/battery-percentage-help-needed
    http://forum.mysensors.org/topic/2210/battery-sensor-measure-for-li-ion-cells/3
    http://forum.mysensors.org/topic/486/my-2aa-battery-sensor
    http://jeelabs.org/2013/05/15/what-if-we-want-to-know-the-battery-state/index.html
    http://jeelabs.org/2013/05/16/measuring-the-battery-without-draining-it/index.html
    http://jeelabs.org/2013/05/17/zero-powe-battery-measurement/index.html
    http://provideyourown.com/2012/secret-arduino-voltmeter-measure-battery-voltage/
    https://code.google.com/archive/p/tinkerit/wikis/SecretVoltmeter.wiki
    How to Arduino BMS - Part 1 Battery Monitoring System LiPo LiFe – 09:31
    — Mega Mechatronics


  • Hardware Contributor

    To start a discussion off, I have a arduino nano connected to the PC and taken measurements of its 3v3 and 5v lines to be 100% they're nice and stable at the given voltages. All was perfect! So i went ahead and ran a simple sketch like illustrated in the 'secret' method to discover my internal VCC line and calibrate the calculation. So after running the following code i then went ahead and done the calibration calculation to change the default "1125300L" reading.

    The equation to calibrate is: ((1.1 * Actual Voltage) / ADC Voltage) * 1023 * 1000

    So I went ahead and ran the code to get my ADC Voltage of 4.850. This resulted in the calibration calculation of ((1.1 * 4.72) / 4.829) * 1023 * 1000 = 1099899.

    I went and put that into my sketch, simply changing the default value to my new value, uploaded and I got the exact reading i was getting on my multimeter. Awesome, so I now knew that the calibration worked perfectly. I now thought, so now i have a pretty stable reference voltage to work from, i can now take the basic calculation of vBatt = (analogueRead(0) / 1023) * VCC and substitute the VCC for my newly calibrated reference voltage (I suspect this is where i'm going wrong in assuming this). I thought this due to the 'secret' method stating that this new function of readVcc() can be used along side of analogRead(0) to get the voltage of a analog reference. The extract below is from the page itself;

    Checking Vcc or Battery Voltage
    You can call this function – readVcc(), if you want to monitor your Vcc. One example would be for checking your battery charge level. You could also use it to determine if you are connected to a power source or running from batteries.

    Measuring Vcc for Analog Reference
    You can also use it to get a correct value for Vcc to use with analogRead() when using the default (Vcc) voltage reference. Unless you are using a regulated supply, you can’t be sure Vcc is 5.0 volts or not. This function will provide the correct value to use. There is one caveat though…
    One of the articles I cited earlier made the claim that this function could be used to improve the accuracy of the analog measurement in cases where Vcc wasn’t exactly 5.0 volts. Unfortunately, this procedure will not provide that result. Why? It is dependent on the accuracy of the internal voltage reference. The spec sheet gives a nominal value of 1.1 volts, but states that it can vary from 1.0 to 1.2 volts. That means that any measurement of Vcc could be off by as much as 10%. Such a measurement could be less accurate than our power supply for the Arduino!*

    From the above extract, am i wrongly assuming that this should work with no matter what voltage you attach/read with analogRead(0)? Either way, i assumed this, I attached the battery to a breadboard rail, and connect my A0 pin to the positive rail. My arduino then reads out 3128.21mV (fluctuating from this to 3141.47mV).

    From everything here, would you say that i have the theory correct and on the path to the correct method of detecting the voltage on analog pin 0?

    While the arduino is reading 3.12821V, the multimeter is reading 3.13V. I can't ask for any more accurate than this when i'm using a very cheap off the shelf multimeter. I think this is the point i need to invest in some tools. New soldering iron is on its way, no idea how i'm surface mount soldering with a cheap soldering station >.<. What would you guys advise for my next tool? Oscilloscope? Quality multimeter? re-flow soldering station? Not too sure.


  • Hardware Contributor

    @samuel235 : hi.

    I am not sure where is your problem...as I think you have understood well the theory 😉
    There are lot of resources on adc read, improve readings...You can use voltage ref ic or internal ref. There are gauge batt ic for a precise measurement too (pros and cons of course). For adc accuracy, it's possible to filter if needed, average multiple readings...I can't explain everything!
    On some of my boards, I have a switched resistor divider to be low power (mosfet cut off gnd of resistor divider so no power consumption) but footprint is not the same than a simple divider or the "secret method" which is also very nice and maybe enough in lots of case.
    I think I am missing lots of info here, and not have the time to write a big post, guys will certainly add things 😉

    For equipment...it depends of your goals..some tools I have :
    iron solder : weller but the chinese ts100 is still tempting me (more for mobile use..),
    scope: rigol ds1054z,
    multimeter: an old but good voltcraft with some nice features (with an uCurrent Gold it's very nice).
    reflow oven: I have received a T962 reflow oven (size is enough for me, I don't need the "A", and I need to hack it now).
    I have lot of others tools (electro or mecha...) but all of this is mainly for my job which is actually mainly R&D and as I'm bootstraping as I can for startup (not iot field, it's for green tech/energy) I try to make good quality/price choice but it still cost money (arghh r&d not cheap !)
    So it really depends on your "real" needs but it's sure hobby has a cost;I stopped to calc! 🙂


  • Hardware Contributor

    @scalz

    You think that i have the method down properly. So the fact i'm reading to a decent accuracy is true and done properly you think from the information i passed on? Well, that has surprised me, i didn't think i had done it properly to be honest.

    I have a few Questions:
    Is there a limit on the voltage that the 'secret' method can monitor?
    If so, is it the voltage that it reads from VCC when doing the readVcc() call, or is this just a value for comparison?
    Would there be a reason you choose to use your current method of voltage divider and mosfet over the 'secret' method? Is it more accurate, lower power consumption or what?(i'm assuming your setup is the same roughly as the one in this topic/thread?)

    In terms of tooling, i have just been excepted on a 'embedded systems' University degree course so i'm thrilled to say that i will be working with IoT, embedded systems, swarming drones, low power electronics on a daily basis for the next 3 years, or longer depending if i go for extra education through masters and Dr. I'm planning on ordering my soldering iron (Hakko FX-888d, but i'm struggling to get a hold of them in the UK). Would you advise any other iron station? What if you had to pick an order for a reflow/hot-air re-work station, re-flow oven, quality multi-meter and Oscilloscope what would you go for? I'm thinking that i probably should get myself set-up so i can build and troubleshoot PCB's (even though i have somehow made a very small footprint in wall pcb with all surface mount components with a cheap soldering iron ;)). I will be making my own 3d printer in the next 6 months i think to enable me to be able to manufacturer everything about a IoT/home automation project from start to finish including a pretty high quality looking designed case/enclosure. The only thing I'd need to out-ship would be the PCB. I do plan on etching my own with time but that obviously isn't good enough for a end product that i plan on demonstrating or supplying.

    Just to let you know, I'm very interested in hearing and seeing your startup, when its ready to show to the public, please let me know so i can show my interest 😉


  • Hardware Contributor

    My little brain has been working over time all day, I've now come to realize that you can add a voltage divide onto the method that i'm using to measure those voltages above the VCC line, so that would enable you to measure a battery voltage of anything over 5v on a arduino nano even though it is stepped down to the 5v on the board. However, i'm currently trying it with two 1M resistors and a cap over one of them to GND and noticed that its giving me a reading of AROUND, it is fluctuating up and down, 4553.90mV, this then multiplied by 2 (because of the resistors being the same size) i end up with a reading of 9107.8mV when the multimeter itself is reading 9.14V. So you can it isn't the most accurate measurement this way.

    Would this be due to the fact of the resistors being slightly inaccurate maybe?
    Would this be better with say two 10k resistors instead maybe?

    I will carry on troubleshooting when i get home tonight.


  • Mod

    Most resistors have 5% tolerance (gold marking).

    BROWN:    1%
    RED:      2%
    GOLD:     5%
    SILVER:  10%
    NOTHING: 20%
    

    Is the step-down delivering exactly 5V (check with your multimeter)?


  • Hardware Contributor

    @mfalkvidd Indeed they do, and i can confirm that i'm currently using a 5% tolerance resistor (gold band). The voltage on the 5v pin is 4.72. The calibration calculation i did, i used the 4.72 reading, not 5v just to let you know 🙂

    While the readVcc() call is perfect for reading a simple setup of a battery powering an uC directly, without a voltage regulator, I'd love to learn how the method works to then add it into a analogRead() call to then be able to use it to monitor pretty much any voltage, within reason. I'm all about learning theories and methods rather than just learning enough to work out what i need to do to fix a current issue.


  • Mod

    @samuel235 sorry. I read that you checked the 5V voltage before, but then I forgot.

    The difference between 9.107 and 9.140 V is less than 0,3% if my math is right, so that's way better than expected with 5% tolerance resistors. The ADC has a 10 bit resolution but not 10 bit accuracy (more like 8-9 bits if I remeber correctly) so your measurements are very close to the limits.


  • Hardware Contributor

    @mfalkvidd, I'm glad it seems that I'm doing everything in theory and method correctly. Shows to myself that i have understood the principles properly. I think I'm correct in assuming/thinking the limitations are as I said in the previous post (post 4), however I would like a discussion regarding those to just confirm them so i know where and what i can do with this method of applying readVcc() to analogRead() to measure a voltage externally from the VCC line of the uC.


Log in to reply
 

Suggested Topics

  • 87
  • 2
  • 7
  • 3
  • 6
  • 10

0
Online

11.4k
Users

11.1k
Topics

112.7k
Posts