So I'm doing a project that monitors a li-ion battery. I am using the asc712 current sensor.
I need to find the State of Charge (SOC) and state of Health (SOH). I have codes ready for the SOC.
But the SOH, I need the current max ah of the battery. So I have an idea to do it. Whenever the battery is fully charged, the code can measure the total ampere-hour (AH) and update the max AH. But I can't figure out how to code it as I have one current sensor and a loop will be running to find the total AH when the ESP32 runs. And to get the Max Ah is only when the battery is above 98% capacity.
This is the snippet code of the part that continuously run to finds the total ah
currentMillis = millis(); //get the current "time" (actually the number of milliseconds since the program started)
if (currentMillis1 - startMillis1 >= period) //test whether the period has elapsed
{
totalCoulumbs = totalCoulumbs + AcsValueF;
float TotalAh = totalCoulumbs / 3600.0;
SOC = (TotalAh / (max AH of batt))*100;
SOH = (max Ah of battery / 50)*100;
startMillis = currentMillis; //IMPORTANT to save the start time of the current state.
}
So like what I mentioned above, I can continuously find the total, AH but I want to find the max AH of the battery when the battery is above 98% capacity. So how do I do it?
This is my full code.
#include <EEPROM.h>
#include "WiFi.h"
#include <Wire.h>
#include "cactus_io_HIH6130.h"
const char* ssid = "dlink-muthus";
const char* password = "Sujitha97";
//define the address used by the HIH6130 sensor (default is 0x27)
byte address = 0x27;
HIH6130 hih6130(address);
const int VoltageSensor = A0 ;
float vOUT = 0.0;
float vIN = 0.0;
int value = 0;
const int CurrentSensor = A1;
int smokesensor = A2;
int buzzer = A3;
int led = A4;
float SOC;
float SOH;
unsigned long startMillis1; //some global variables available anywhere in the program
unsigned long currentMillis1;
const int period1 = 1000; //the value is a number of milliseconds
float totalCoulumbs = 0.0;
void setup() {
Serial.begin(115200);
WiFi.begin(d-link-muthus, Sujitha97);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.println("Connecting to WiFi..");
}
Serial.println("Connected to the WiFi network");
startMillis1 = millis(); //initial start time
Wire.begin();
//Serial.println("Honeywell HIH6130 Humidity - Temperature Sensor");
//Serial.println("RH\tTemp (C)\tHeat Index (C)");
pinMode(smokesensor, INPUT);
pinMode(buzzer, OUTPUT);
pinMode(led, OUTPUT);
}
void loop() {
value = analogRead(VoltageSensor);
vOUT = (value * 5.0) / 1024.0;
VoltageValue = vOUT / 0.2;
//Serial.print(VoltageValue);
unsigned int x = 0;
float AcsValue = 0.0, Samples = 0.0, AvgAcs = 0.0, AcsValueF = 0.0;
for (int x = 0; x < 150; x++) {
AcsValue = analogRead(CurrentSensor);
Samples = Samples + AcsValue;
delay (3);
}
AvgAcs = Samples / 150.0; //Taking Average of Samples
CurrentValue = (2.5 - (AvgAcs * (5.0 / 1024.0)) ) / 0.185;
//Serial.print(CurrentValue);
int MQ2Sensor = analogRead(smokesensor);
//Serial.println(sensorValue, DEC);
hih6130.readSensor();
//Serial.print(hih6130.humidity); Serial.print("\t");
//Serial.print(hih6130.temperature_C); Serial.print("\t\t");
//Serial.print(hih6130.computeHeatIndex_C()); Serial.print("\t\t");
if (hih6130.temperature_C > 60 || hih6130.temperature_C < -20 || MQ2Sensor > 400 || hih6130.humidity > 75)
{
tone(buzzer, 1000);
digitalWrite(led, HIGH);
delay(1000);
digitalWrite(led, LOW);
delay(1000);
}
else
{
noTone(buzzer);
digitalWrite(led, LOW);
}
currentMillis = millis(); //get the current "time" (actually the number of milliseconds since the program started)
if (currentMillis1 - startMillis1 >= period) //test whether the period has elapsed
{
totalCoulumbs = totalCoulumbs + AcsValueF;
float TotalAh = totalCoulumbs / 3600.0;
// SOC = (TotalAh / (max AH of batt))*100;
// SOH = (max Ah of battery / 50)*100;
startMillis = currentMillis; //IMPORTANT to save the start time of the current state.
}