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

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?

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

Figure 3 – Schematic for 9 V batteries.

user4143: 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:

simulate this circuit – Schematic created using CircuitLab

63496: <p>I am using the following circuit to measure the Li-ion 3.7V battery capacity.</p>
<p><a href="https://i.stack.imgur.com/hcKtR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hcKtR.png" alt="Setup for 3.7V Batteries" /></a></p>
<p><em>Figure 1 – Schematic for 3.7 V batteries.</em></p>
<p>This setup works fine for the 3.7V batteries.</p>
<p>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?</p>
<p><a href="https://i.stack.imgur.com/uJHVe.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/uJHVe.png" alt="Modified schematic for 9 V batteries which doesn't work" /></a></p>
<p><em>Figure 2 – Modified schematic for 9 V batteries which doesn't work.</em></p>
<p>My code:</p>
<pre class="lang-cpp prettyprint-override"><code>#include &quot;LCD5110_Graph.h&quot;
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(&quot;Battery Capacity Checker v1.1&quot;);
    Serial.println(&quot;battVolt current mAh&quot;);

    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(&quot;Battery&quot;, CENTER, 0);
    myGLCD.print(&quot;Check&quot;, CENTER, 12);
    myGLCD.print(&quot;Please Wait&quot;, CENTER, 24);
    myGLCD.print(&quot;AdamWelch.Uk&quot;, 8, 40);
    myGLCD.update();
    delay(2000);
    myGLCD.clrScr();
}

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

    if (battVolt &gt;= battLow &amp;&amp; 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(&quot;Discharge&quot;, CENTER, 0);
        myGLCD.print(&quot;Voltage:&quot;, 0, 10);
        myGLCD.printNumF(battVolt, 2, 50, 10);
        myGLCD.print(&quot;v&quot;, 77, 10);
        myGLCD.print(&quot;Current:&quot;, 0, 20);
        myGLCD.printNumF(current, 2, 50, 20);
        myGLCD.print(&quot;a&quot;, 77, 20);
        myGLCD.printNumI(mAh, 30, 30);
        myGLCD.print(&quot;mAh&quot;, 65, 30);
        myGLCD.print(&quot;Running&quot;, CENTER, 40);
        myGLCD.update();

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

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

        finished = true;

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

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

        delay(interval * 2);
    }
}
</code></pre>
<p>Circuit with modifications</p>
<p><a href="https://i.stack.imgur.com/Iowen.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Iowen.png" alt="Schematic for 9 V Batteries" /></a></p>
<p><em>Figure 3 – Schematic for 9 V batteries.</em></p>
 4143: <p>The problem comes because you are powering your load through the voltage divider you use for reading your battery voltage.</p>
<p>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 <em>before</em> your voltage divider and <em>then</em> divide that result down again.</p>
<p>Your circuit should look more like:</p>

<p><img src="https://i.stack.imgur.com/v81u4.png" alt="schematic" /></p>

<p><sup><a href="/plugins/schematics?image=http%3a%2f%2fi.stack.imgur.com%2fv81u4.png">simulate this circuit</a> &ndash; Schematic created using <a href="https://www.circuitlab.com/" rel="nofollow">CircuitLab</a></sup></p>
