Any recommendations for finding Sealed Lead Acid battery capacity using an ESP32?
Planning to log capacity and send alert once capacity reaches a set point. I have seen Amazon Smart Battery Monitors
Regards,
William
Prompted Google’s Bard; this is the response for using a INA219
sensor:
Sure, here is an example of integrating the current over time to calculate the battery capacity:
C++
#include <Wire.h>
#include <INA219.h>
INA219 ina219(0x40);
long totalCharge = 0; // Variable to store the total charge consumed
long startTime = 0; // Variable to store the start time
void setup() {
Serial.begin(115200);
Wire.begin();
ina219.begin();
startTime = millis(); // Record the start time
}
void loop() {
long current = ina219.getCurrent_mA(); // Read the current in mA
long elapsedTime = millis() - startTime; // Calculate the elapsed time in milliseconds
totalCharge += current * elapsedTime; // Update the total charge consumed
startTime = millis(); // Reset the start time for the next iteration
Serial.print("Total Charge: ");
Serial.println(totalCharge);
delay(1000); // Delay for 1 second
}
This code will print the total charge consumed by the battery to the serial monitor every second. You can modify this code to calculate the remaining battery capacity by dividing the total charge by the battery’s nominal capacity (in mAh).
Will investigate and experiment further.
Regards,
William