I am using Arduino Nano and various Li-Fe , Li-Po batteries of 9.9V , 6.6V and 3.7V.My Arduino works at 5V so for batteries like 9.9V and 6.6V .
I have used a voltage divider using two 10k resistors.
Now I want to read the volatges of the battery using Arduino and also the battery percentage.
Below is my code.
I did this coding by refering
TUTORIAL: How to Measure / Read Voltages Into Arduino - (Part 1/3 Voltages Less than 5v) - YouTube and https://www.instructables.com/id/Displaying-Battery-Life-on-a-Liquid-Crystal-Displa/
After reading through Arduino I need to cross check it with mulimeter, so please help me with both the questions. (1) How to exactly read the voltages of battery using Arduino (2) To check battery voltages using multimeter (If anything us wrong in the code please let me know.)
#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);
}