To know the % charge of the battery using Arduino

自闭症网瘾萝莉.ら 提交于 2020-02-15 23:17:27

问题


I am using Arduino Nano and various Li-Fe , Li-Po batteries of 9.9V , 6.6V and 3.7V. I can read the voltage of the battery using Arduino . My Arduino works at 5V so for batteries like 9.9V and 6.6V I have used a voltage divider using two 10k resistors.But the problem is I need to read the the % of charged battery , I tried something in the code but I am not sure about it. Please anyone help me with it. My code is:

#define cellPin A0

const float mvpc = 4.55 ; //measured voltage of arduino through voltmeter
float counts = 0;  //battery volts in millivolts
float mv = 0;
float multiplier = 2;
float output = 0;
int charge = 0;

void setup() {
  // put your setup code here, to run once:
Serial.begin(115200);
}

void loop() {
  // put your main code here, to run repeatedly:
counts = analogRead(cellPin);
Serial.println(counts);

mv = counts * mvpc;
Serial.println(mv);

output = (mv * multiplier)/1000 ;
Serial.print(output);
Serial.println("V");

charge = (counts/1024)*100;
Serial.print(charge);
Serial.println("%");

delay(1000);

}

回答1:


In order to accurately determine the % of the charged battery, you need the discharge graph for each of the batteries. The discharge graph is usually non-linear for lithium batteries. The discharge curve is basically the voltage versus the % charge and it is different for charging and discharging batteries.

If you have the discharge curve, you can create a map for each of the % to the corresponding voltage value. Then you can map each voltage to a % value from the map you created.

For example:

100% -> 5.00 V 99% -> 4.95 V .... 0% -> 3.23 V

Create an array to store the map of size 100 (for each %): [5.00, 4.95, ... 3.23]

You can then find the %s using the voltage. I hope you can find the discharge graph, otherwise, you can manually find it yourself by discharging the battery using a safe current




回答2:


In addition to maheenul I'd like to add that you're calculations are a bit off.

const float mvpc = 4.55 ; //measured voltage of arduino through voltmeter

I presume you're supplying your Arduino via USB. This voltage is not very reliable.

float counts = 0;  //battery volts in millivolts
counts = analogRead(cellPin);

analogRead returns a 10bit (0-1023) ADC reading. A fraction of your voltage reference. It is not a value in millivolts! So in the following you shoudl use 1024 instead of 1000.

output = (mv * multiplier)/1000 ;

charge = (counts/1024)*100; this calculates the percentage of your Vref. It is not a charge as explained by maheenul.

If you want accurate measurements you should use a better Vref. Either the internal 1.1Vref or some well regulated Vref. Both with appropriate voltage dividers.

But I guess being 5-10% off is not a big deal for a battery charge measurement.



来源:https://stackoverflow.com/questions/58387966/to-know-the-charge-of-the-battery-using-arduino

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!