The project is to measure a battery state of health by determining the open circuit voltage and the short circuit current, and a push button is used to toggle between OCV and SCC. I do not know where I'm going wrong. Kindly let me know as I am a beginner.
const int buttonPin = 2; // Pin for the pushbutton
const int analogPin = A0; // Analog pin connected to the battery through a voltage divider
const int resistorValue = 10; // Resistance value (ohms) for current measurement
void setup() {
Serial.begin(9600);
pinMode(buttonPin, INPUT_PULLUP);
}
void loop() {
// Check if the pushbutton is pressed
if (digitalRead(buttonPin) == LOW) {
// Measure short circuit current
float voltageDrop = analogRead(analogPin) * 5.0 / 1023.0; // Convert ADC value to voltage
float shortCircuitCurrent = voltageDrop / resistorValue;
// Print short circuit current to the serial monitor
Serial.print("Short Circuit Current (A): ");
Serial.println(shortCircuitCurrent);
delay(1000); // Delay for stability, adjust as needed
} else {
// Measure open circuit voltage
int adcValue = analogRead(analogPin);
float openCircuitVoltage = adcValue * (5.0 / 1023.0); // Convert ADC value to voltage
// Print open circuit voltage to the serial monitor
Serial.print("Open Circuit Voltage (V): ");
Serial.println(openCircuitVoltage);
delay(1000); // Delay for stability, adjust as needed
}
}
P.S. the code works fine when the button is pressed, i.e. it toggles between the values. But the value is always zero.
Take attention to the schematics, it looks wrong for me.
Your battery is always in the SCC state, toggling the button doesn't change it connection and, logically, the voltage drop is always zero.
Your button should switch the battery connection between OCV to SCC circuits rather than just to send a signal to arduino.
@samsparks99 better yet woukd be to draw a real schematic. Take a look at a few schematics and do your best to fake it if you aren't sure how.
The picture is ambiguous at best. I see places that might be what you want and might not be. What I do make of it places me in agreement with @b707's impressions.
For the SCC I assume you are measuring the voltage across a small value resistor. What value have you chosen for that?
As I see, OP has a problem with terminology: "voltage drop" is a DIFFERENCE between battery voltage, measured in OCV and SCC modes, and not a SCC voltage itself.
Measuring a SCC voltage with such moderate currents giving nothing to test the battery....
Yet another issue: OP is trying to measure an absolute voltage (the battery voltage) using a ratiometric ADC (the Arduino ADC with default reference). Any change in supply voltage will skew the measuments. Much better is to use the internal 1.1V reference, and of course a 2:3 ratio voltage divider for the battery to get its output voltage in range of the ADC.
And ⦠passing high current through a breadboard ( if thats what you are doing ) is a mistake .
I tested a couple of AA batteries and got around 1A short circuit* but it falls rapidly as the battery dies , so Iām not sure this helps with predicting the condition. What do you hope from that ?
measured with a multimeter , which was probably the limiting impedance .
Mr Google says an AA Alkaline has an internal resistance of around 0.15ohm when new, falling to 0.75ohm when tired .
Bear in mind if you use the default A/D setup, the voltage measured may not be correct or steady ( , as the A/D reference is the chip power supply ,so 5/1023 is wrong ) . Use the internal reference
This circuit will work.
You detect the button state by looking at A0 and A1.
When the button is NOT pushed, A0 will be the OC voltage and A1 = 0V
When the button IS pushed, both A0 and A1 will be the SC voltage.
Button not pushed A0=OC, A1=0V
Button pushed A0=SC, A1=SC