1

I am using the following circuit to measure the Li-ion 3.7V battery capacity.

Setup for 3.7V Batteries

Figure 1 – Schematic for 3.7 V batteries.

This setup works fine for the 3.7V batteries.

To be able to measure 9V batteries, I modified the circuit with a voltage divider so that the Arduino sees max 5v at the analog input. However Arduino reports 0V. I have measured the output of voltage divider with a DMM and it shows 5V. I wonder why doesn't Arduino report the correct voltage. Could you please help me fix it?

Modified schematic for 9 V batteries which doesn't work

Figure 2 – Modified schematic for 9 V batteries which doesn't work.

My code:

#include "LCD5110_Graph.h"
LCD5110 myGLCD(5, 6, 7, 9, 8); // Setup Nokia 5110 Screen SCLK/CLK=5, DIN/MOSI/DATA=6, DC/CS=7, RST=9 Chip Select/CE/SCE=8,
extern uint8_t SmallFont[];
extern uint8_t MediumNumbers[];

#define gatePin 10
#define highPin A0
#define lowPin A1

boolean finished = false;
int printStart = 0;
int interval = 5000; // Interval (ms) between measurements

float mAh = 0.0;
float shuntRes = 1.0; // In Ohms – Shunt resistor resistance
float voltRef = 4.71; // Reference voltage
float current = 0.0;
float battVolt = 0.0;
float shuntVolt = 0.0;
float battLow = 2.9;

unsigned long previousMillis = 0;
unsigned long millisPassed = 0;

void setup()
{
    Serial.begin(9600);
    Serial.println("Battery Capacity Checker v1.1");
    Serial.println("battVolt current mAh");

    pinMode(gatePin, OUTPUT);
    digitalWrite(gatePin, LOW);

    myGLCD.InitLCD(); // initialize LCD with default contrast of 70
    myGLCD.setContrast(68);
    myGLCD.setFont(SmallFont); // Set default font size. tinyFont 4×6, smallFont 6×8, mediumNumber 12×16, bigNumbers 14×24
    myGLCD.clrScr();

    myGLCD.print("Battery", CENTER, 0);
    myGLCD.print("Check", CENTER, 12);
    myGLCD.print("Please Wait", CENTER, 24);
    myGLCD.print("AdamWelch.Uk", 8, 40);
    myGLCD.update();
    delay(2000);
    myGLCD.clrScr();
}

void loop()
{
    battVolt = analogRead(highPin) * voltRef / 1024.0;
    shuntVolt = analogRead(lowPin) * voltRef / 1024.0;

    if (battVolt >= battLow && finished == false)
    {
        digitalWrite(gatePin, HIGH);
        millisPassed = millis() – previousMillis;
        current = (battVolt – shuntVolt) / shuntRes;
        mAh = mAh + (current * 1000.0) * (millisPassed / 3600000.0);
        previousMillis = millis();

        myGLCD.clrScr();
        myGLCD.print("Discharge", CENTER, 0);
        myGLCD.print("Voltage:", 0, 10);
        myGLCD.printNumF(battVolt, 2, 50, 10);
        myGLCD.print("v", 77, 10);
        myGLCD.print("Current:", 0, 20);
        myGLCD.printNumF(current, 2, 50, 20);
        myGLCD.print("a", 77, 20);
        myGLCD.printNumI(mAh, 30, 30);
        myGLCD.print("mAh", 65, 30);
        myGLCD.print("Running", CENTER, 40);
        myGLCD.update();

        Serial.print(battVolt);
        Serial.print("\t");
        Serial.print(current);
        Serial.print("\t");
        Serial.println(mAh);

        delay(interval);
    }
    if (battVolt < battLow)
    {
        digitalWrite(gatePin, LOW);

        finished = true;

        if (mAh < 10)
        {
            printStart = 40;
        }
        else if (mAh < 100)
        {
            printStart = 30;
        }
        else if (mAh < 1000)
        {
            printStart = 24;
        }
        else if (mAh < 10000)
        {
            printStart = 14;
        }
        else
        {
            printStart = 0;
        }

        myGLCD.clrScr();
        myGLCD.print("Discharge", CENTER, 0);
        myGLCD.print("Voltage:", 0, 10);
        myGLCD.printNumF(battVolt, 2, 50, 10);
        myGLCD.print("v", 77, 10);
        myGLCD.setFont(MediumNumbers);
        myGLCD.printNumI(mAh, printStart, 21);
        myGLCD.setFont(SmallFont);
        myGLCD.print("mAh", 65, 30);
        myGLCD.print("Complete", CENTER, 40);
        myGLCD.update();

        delay(interval * 2);
    }
}

Circuit with modifications

Schematic for 9 V Batteries

Figure 3 – Schematic for 9 V batteries.

5
  • Why such tiny resistor values?
    – Majenko
    Jul 13, 2021 at 18:56
  • Sorry it wasn't the correct schematic. I have updated the post with the correct one. I suppose you were referring to the voltage divider resistors?
    – Zaffresky
    Jul 13, 2021 at 18:57
  • Actually, ignore that - I was looking at the resistors wrong. The small ones are current sense and load, not the battery divider.
    – Majenko
    Jul 13, 2021 at 18:59
  • A load of 4.3ohm on a 9volt battery draws 2amps???
    – SBF
    Jul 16, 2021 at 12:09
  • Yes that's indeed high so I am planning to use Rload = 10 ohm. My 9V nominal Li-ion battery has max voltage of 8V so with a total 11 ohm resistance the current will be limited around 819 mA. Since the resistors can take upto 10 W so it should be fine .
    – Zaffresky
    Jul 16, 2021 at 17:01

1 Answer 1

3

The problem comes because you are powering your load through the voltage divider you use for reading your battery voltage.

You cannot do high-side current reading like that with a voltage higher than the ADC voltage. Instead you need to do the current sensing before your voltage divider and then divide that result down again.

Your circuit should look more like:

schematic

simulate this circuit – Schematic created using CircuitLab

1
  • 1
    Thanks for the explanation. I have uploaded a new schematic and I hope I have incorporated your suggestion correctly. Can you please have a look? :)
    – Zaffresky
    Jul 15, 2021 at 17:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.