12V battery meter with Arduino MEGA

There must be a way to do this in math, not piecewise. Capacity is a function of terminal voltage and temperature, so there must BE an equation C = (fv, ft)

I'm constantly searching. At least the measured capacity vs. terminal voltage @ specific temperature & @ specific discharge rage (C) (from which the curves itself made) in a big Excel table would be a great help.

However, have you spotted that the terminal voltage is ALSO very significantly a function of load current?

Yes, because as the load current go up, then due to the internal resistance of the battery, the terminal voltage will drop. But we are measuring the actual voltage on the battery. So this factor already considered in the discharge curve. (Please correct me if I was wrong.)

The graph you are using is for a discharge current of 0.5C - which for the 32Ah battery is 16A.

Correct. I had only this one. (Unfortunately the manufacturers are not sharing all infos, which are needed.)
The studied C-rate shall be near to the real average load during the operation.

Your calculations will only be valid at all if that current is being drawn.

This is the aim, so during the continuous operation, the rover can realize when the battery capacity hit the low limit (let say 10%) and can go to the charging station or trigger alarm etc.

As for a rover the load current will be constantly changing you cant calculate the remaining capacity unless you can correct for the load current, and it gets more complicated.

Yes, and this is a really disturbing factor. If the load is not stable for a certain of period of time let say 30 sec. , then the the C-rate is constantly changing and hampering the discharge curves/calculation.
To help on this, the schematic can be upgraded with an accurate current sensor. (ref my post on Jan 09.21 05:16 am) so one more factor but curves/data are required.
C = (fv, ft, fc)
C: battery capacity
fv: terminal voltage
ft: temperature
fc: discharge/c-rate

@steger, this thread might be of interest.

@ johnerrington: Thank You ! It was a very useful link (I add 1 Karma :-).

As I saw in this link there are 3 points for consideration:

  1. Coulomb Counter (Battery Fuel Gauge)
    Measure the current instead of ACS712 with INA216 (datasheet attached), because it is more accurate
    Okay, I attached my schematic.

But in the same thread I dont' understand this:

An INA216 breakout board could be a better solution for your (unspecified) project.
Voltage, current, power, all in one.
Leo..

The terminal voltage not measured with INA, just volt drop on shunt. So the LM4040 AIZ-4.1 diode and voltage divider shall remain.

  1. Calculate the capacity consumption as I(load)*time and store. Later subtract from nominal capacity of the battery (2200 mAh).

  2. How the whatever state of the battery can be taken ? For this we have to know the actual voltage and discharge curves. (Already solved in this thread :slight_smile:
    Anyhow, we need voltage value, because if the terminal voltage reach the cut-off value, we have to be re-charged.

So I would like combine the till achieved results with the new one (point 2&3):
I know the voltage & temperature, so when I start the rover, I can take a low 0.1C discharge cure as reference. -> I know the initial battery state and how much max. capacity is possible on the actual temperature (for example @ -10C (green line) only 75% of the max. Let saying 12Ah battery 1275%= 9Ah max).
If I start the rover and measure the terminal voltage let say showing: 12 V, then it means 25% already consumed (12 Ah
25% = 3Ah). (See on the discharge curve.)

So If I run the rover over a certain time, I can collect / calculate / integrate the I(load)*time.
Recharge required when this equation is less than zero: 9Ah - 3Ah - I(load)*time.
With this, the dependency of the discharge cure from the c-rate is resolved, but during operation the temperature shouldn't changed. C = (fv, ft)

Required current load vs Vout on INA.jpg

Connecting INA.jpg

Required current load vs Vout on INA.jpg

Connecting INA.jpg

TDS_INA210-215.pdf (1.54 MB)

@Steger, I have been thinking about this and perhaps we are looking at it from the wrong end.

The fuel guage on my car gives me an INDICATION of the remailing fuel.

Accepting that there are serious limitations on how accurately you can estimate the remaining capacity, why not look at the conditions that match 5%, 10% etc. ?
So eg if temp = 20C and voltage = 11.3V and current drain = 3A;

not explaining very well but maybe you get the idea

@:johnerrington Yes, I got the idea:
So eg if temp = 20C and voltage = 11.3V and current drain = 3A;
I'm measuring the actual current drain of the load and we know the nominal capacity of the battery, let say: 12Ah
The discharge rate will be 3A/12Ah -> C=0.25
If the discharge curve known @ 20C temperature and @ C=0.25 (manufacturer's data sheet) and we are already measuring the actual terminal voltage, then remaining battery capacity can be easily calculated with the interpolated curves based on the curves of the datasheet. (my post on Jan 14, 2021, 03:02 pm)
The accuracy issue is coming due to:
Only few discharge curves are given from (0.1, ... 1C ...) on a discrete temperatures (-10, 0, 10, 20, ...).
So we don't known about the battery capacity for example at t=22.45C and C=0.234.
This can be resolved, if we know the function of the Capacity = (fv, ft, fc) with 3 independent variables.
(Of course, there are more factors, which are playing role as well.)

I think I found some sort of solution, how the capacity can be calculated.
One way is: linear regression on multiple variants.
Lets take this model:
Battery Capacity = AVterminal + BCrate + C*Temp + D (A, B ... D constants)
If we have data-set (simple table with hundred of rows) with Capacity; Vterminal; Crate and Temp data, then this data can be used to train the above model -> the constants (A, B, ... D ) can be be figured out. (Machine learning.)

After that, with this constants the model can be tested as well. -> Accuracy can be checked.

I found some battery data-sets here (MATLAB might be required to open .mat files):
link1
link2
How to train a model (video with Python):
link3
like4

Other, non-linear algorithms (NASA):
link5

If Your found a good-data set for LiFePO4 battery with the above parameters, kindly share.
Thank You !

Just to have a more comprehensive picture, I'm attaching the 12V battery meter with Arduino MEGA incl. temperature and current measuring options for further consideration and improvement.

I'm afraid we all forgot to tell that the 1-Wire bus needs a pullup resistor.

You already showed a DS18B20 in the picture in reply #13 and #34, and we didn't tell about the pullup resistor :-[

@ Koepel: thank You very much for advise, I changed the schematics.

Before continue with codding, assuming you do have 4 cells of LifePO4, I think your volt range (12.8-10.7) is wrong.
I suspect it should be 11.2-14.6V. You better verify this point before blow-up your battery.

I did some projects like this, thought the whole idea of "running" after the charge / discharge curve will not work.

Or you exclude the first and last ~15% capacity, measuring the ~15-85%, consider it linear (knowing you are +-10%. For the edges just specify you are on the edge).

Or, back to ASC712 current sensor (mention early), you can measure the charge and discharge current all the time and calculate the balance. When charging current it minimal and battery volt reach to the Max., I'm resetting the balance (to zero). I have few projects (with ASC712, 15, 758) and it's the best way I found to figure out the battery status.
If you go this direction (using ASC712), these sensors are tricky to use. I can post my code and share my experience.

@ Zivo: Thank You for Your comment.
Yes, You are right. I use 4 cells of LifePO4. Actually in my case the max voltage went up to 12.8V (may be not the best battery) and I set the minimum to 10.7V as cut-off. (Can be 10V as well.)

I would sincerely appreciate, if You would share Your experience with ASC712. :wink:

To simplify the math, I thought the following:
Let say, I have the discharge curves only @C/10 from -10 to 50 Celsius .
(In this outdoor application the C/10 is the typical current consumption, on a long distance.)
It means, have to make 7x3 regressions. (I already made for 3 temperatures and may be from 30 Celsius to 50 Celsius will be the same. So only two more required).
Lat say, the rover running up & down. In every 30 minutes, I can adjust the speed for 1 minute to C/10 (let say to 1.2 A total current consumption for 12 Ah battery) and calculate the actual remaining capacity %.
This will not giving the best accuracy, but considering with temperature, which in this outdoor application is important.

Once again, I'd advise you to re-check your LifePo4 spec. 10V is 2.5 per cell, this is too low for LifePo4.
You better stay above 2.7. Pay attention to Lithium discharge curves, the capacity contribution (around these number) are neglected. At other hand the risk of damage the cell is big.
Don't go there.
Regarding the capacity curves, you are focusing on ambient temp', while there are few others parameter (like charge and discharge current, # of cycles) which have no less impact on these curves.
By the end of the day, the simple method i'd proposed, will give you about the same accuracy , with much simple solution.

@ Zivo: thank You for the advise. I will try your approach as soon as possible.
The 10V is the cut-off on 2.5V, so the battery during discharging can go max to this point, not below.

For Your kind information and for other Arduino users who are vising this page as well.
I started a new thread:
Power Supply for Arduino MEGA + Shield
in "Arduino Forum > Using Arduino > Project Guidance section"
https://forum.arduino.cc/index.php?topic=724297.0
It is very useful with a lot of learning points.

If You are interested, just jump in. :wink:
Have a nice week ahead.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.