Hello,
I am using 2 x 18650 Lithium Battery Shield V8 with ESP32. Batteries are connected in Parallel connection
How can I get the Battery Percentage/ How much battery is remaining with ESP32.
Battery Shield having 5V and Ground Pin, i connect Voltage Divider, to calculate the percentage, but it is not giving me the right result.
Voltage Divider--
V = 5V
R1 = 500
R2 = 1k
Vout = 3.3
#define ANALOG_IN_PIN 34
// Floats for ADC voltage & Input voltage
float adc_voltage = 0.0;
float in_voltage = 0.0;
// Floats for resistor values in divider (in ohms)
float R1 = 510.0;
float R2 = 1000.0;
// Float for Reference Voltage
float ref_voltage = 3.3;
// Integer for ADC value
int adc_value = 0;
void setup(){
// Setup Serial Monitor
Serial.begin(9600);
Serial.println("DC Voltage Test");
}
void loop(){
// Read the Analog Input
adc_value = analogRead(ANALOG_IN_PIN);
// Determine voltage at ADC input
adc_voltage = (adc_value * ref_voltage) / 4096.0;
// Calculate voltage at divider input
in_voltage = adc_voltage / (R2/(R1+R2));
//float value = (((adc_voltage - 3.0)/(4.2- 3.0)) * 100); // for battery percentage
// Print results to Serial Monitor to 2 decimal places
Serial.print("Input Voltage = ");
Serial.println(in_voltage, 2);
// Short delay
delay(500);
}