【发布时间】:2019-10-15 05:48:07
【问题描述】:
我正在使用 Arduino Nano 和各种 9.9V、6.6V 和 3.7V 的 Li-Fe、Li-Po 电池。 我可以使用 Arduino 读取电池的电压。我的 Arduino 在 5V 下工作,因此对于 9.9V 和 6.6V 等电池,我使用了一个使用两个 10k 电阻的分压器。但问题是我需要读取充电电池的百分比,我在代码中尝试了一些东西,但我不确定关于它。请任何人帮助我。 我的代码是:
#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);
}
【问题讨论】:
标签: arduino arduino-ide battery batterylevel