# Messuring battery voltage and current with INA219  inconsistent values.

**URL:** <https://forum.arduino.cc/t/messuring-battery-voltage-and-current-with-ina219-inconsistent-values/620464>\
**Category:** General Electronics\
**Created:** [November 13, 2019, 12:50pm UTC](https://forum.arduino.cc/t/messuring-battery-voltage-and-current-with-ina219-inconsistent-values/620464 "2019-11-13T12:50:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![David\_0111](https://avatars.discourse-cdn.com/v4/letter/d/ad7895/32.png) [@David\_0111](https://forum.arduino.cc/u/David_0111)\
**Post date:** [November 13, 2019, 12:50pm UTC](https://forum.arduino.cc/t/messuring-battery-voltage-and-current-with-ina219-inconsistent-values/620464/1 "2019-11-13T12:50:46Z")

</div>

I'm messuring a batteries voltage and current as it's being charged by a solar panel. But I get really inconsitent and weird vaules. Here's my values

```cpp
Bus Voltage:  3.62 V
Shunt Voltage: -2.41 mV
Load Voltage:  3.62 V
Current:      -24.10 mA
Power:        87.00 mW

Bus Voltage:  3.61 V
Shunt Voltage: 0.00 mV
Load Voltage:  3.61 V
Current:      0.00 mA
Power:        0.00 mW

Bus Voltage:  3.61 V
Shunt Voltage: -0.01 mV
Load Voltage:  3.61 V
Current:      0.00 mA
Power:        0.00 mW

Bus Voltage:  3.61 V
Shunt Voltage: 0.00 mV
Load Voltage:  3.61 V
Current:      -0.10 mA
Power:        0.00 mW

Bus Voltage:  3.61 V
Shunt Voltage: -0.01 mV
Load Voltage:  3.61 V
Current:      0.00 mA
Power:        0.00 mW

Bus Voltage:  3.61 V
Shunt Voltage: 0.00 mV
Load Voltage:  3.61 V
Current:      0.00 mA
Power:        0.00 mW

Bus Voltage:  3.61 V
Shunt Voltage: 0.00 mV
Load Voltage:  3.61 V
Current:      0.00 mA
Power:        0.00 mW

Bus Voltage:  3.61 V
Shunt Voltage: 0.00 mV
Load Voltage:  3.61 V
Current:      -0.10 mA
Power:        0.00 mW

Bus Voltage:  3.61 V
Shunt Voltage: 0.00 mV
Load Voltage:  3.61 V
Current:      0.00 mA
Power:        0.00 mW

Bus Voltage:  3.61 V
Shunt Voltage: 0.00 mV
Load Voltage:  3.61 V
Current:      0.00 mA
Power:        0.00 mW

Bus Voltage:  3.61 V
Shunt Voltage: -0.01 mV
Load Voltage:  3.61 V
Current:      -0.10 mA
Power:        0.00 mW

Bus Voltage:  3.61 V
Shunt Voltage: 0.00 mV
Load Voltage:  3.61 V
Current:      -0.10 mA
Power:        0.00 mW

Bus Voltage:  3.61 V
Shunt Voltage: -0.01 mV
Load Voltage:  3.61 V
Current:      0.00 mA
Power:        0.00 mW

Bus Voltage:  3.61 V
Shunt Voltage: 0.00 mV
Load Voltage:  3.61 V
Current:      0.00 mA
Power:        0.00 mW

Bus Voltage:  3.61 V
Shunt Voltage: 0.00 mV
Load Voltage:  3.61 V
Current:      -0.10 mA
Power:        0.00 mW

Bus Voltage:  3.62 V
Shunt Voltage: -2.41 mV
Load Voltage:  3.62 V
Current:      -24.10 mA
Power:        87.00 mW

Bus Voltage:  3.61 V
Shunt Voltage: 0.00 mV
Load Voltage:  3.61 V
Current:      0.00 mA
Power:        0.00 mW

Bus Voltage:  3.62 V
Shunt Voltage: -1.05 mV
Load Voltage:  3.62 V
Current:      -24.00 mA
Power:        87.00 mW

Bus Voltage:  3.61 V
Shunt Voltage: 0.00 mV
Load Voltage:  3.61 V
Current:      -0.10 mA
Power:        0.00 mW

Bus Voltage:  3.61 V
Shunt Voltage: -0.01 mV
Load Voltage:  3.61 V
Current:      0.00 mA
Power:        0.00 mW

Bus Voltage:  3.62 V
Shunt Voltage: -2.41 mV
Load Voltage:  3.62 V
Current:      -24.10 mA
Power:        87.00 mW

```

I'm linking a picture to my circuit as well.

 ![Solar_Panel_Circut.jpg](https://europe1.discourse-cdn.com/arduino/original/4X/1/7/3/17309981def6d5ab415a812bd5723fe5437ecdeb.jpeg)

---

<div class="post-metadata">

**Author:** ![MarkT](https://avatars.discourse-cdn.com/v4/letter/m/c89c15/32.png) [@MarkT](https://forum.arduino.cc/u/MarkT)\
**Post date:** [November 13, 2019, 2:39pm UTC](https://forum.arduino.cc/t/messuring-battery-voltage-and-current-with-ina219-inconsistent-values/620464/2 "2019-11-13T14:39:31Z")

</div>

Lets see the code so we can find the problem...

---

<div class="post-metadata">

**Author:** ![David\_0111](https://avatars.discourse-cdn.com/v4/letter/d/ad7895/32.png) [@David\_0111](https://forum.arduino.cc/u/David_0111)\
**Post date:** [November 13, 2019, 2:48pm UTC](https://forum.arduino.cc/t/messuring-battery-voltage-and-current-with-ina219-inconsistent-values/620464/3 "2019-11-13T14:48:32Z")

</div>

Here's the code

```cpp
#include <Wire.h>
#include <Adafruit_INA219.h>

Adafruit_INA219 ina219;

void setup(void) 
{
  Serial.begin(115200);
  while (!Serial) {
      // will pause Zero, Leonardo, etc until serial console opens
      delay(1);
  }

  uint32_t currentFrequency;
    
  Serial.println("Hello!");
  
  // Initialize the INA219.
  // By default the initialization will use the largest range (32V, 2A).  However
  // you can call a setCalibration function to change this range (see comments).
  ina219.begin();
  // To use a slightly lower 32V, 1A range (higher precision on amps):
  //ina219.setCalibration_32V_1A();
  // Or to use a lower 16V, 400mA range (higher precision on volts and amps):
  ina219.setCalibration_16V_400mA();

  Serial.println("Measuring voltage and current with INA219 ...");
}

void loop(void) 
{
  float shuntvoltage = 0;
  float busvoltage = 0;
  float current_mA = 0;
  float loadvoltage = 0;
  float power_mW = 0;

  shuntvoltage = ina219.getShuntVoltage_mV();
  busvoltage = ina219.getBusVoltage_V();
  current_mA = ina219.getCurrent_mA();
  power_mW = ina219.getPower_mW();
  loadvoltage = busvoltage + (shuntvoltage / 1000);
  
  Serial.print("Bus Voltage:  "); Serial.print(busvoltage); Serial.println(" V");
  Serial.print("Shunt Voltage: "); Serial.print(shuntvoltage); Serial.println(" mV");
  Serial.print("Load Voltage:  "); Serial.print(loadvoltage); Serial.println(" V");
  Serial.print("Current:      "); Serial.print(current_mA); Serial.println(" mA");
  Serial.print("Power:        "); Serial.print(power_mW); Serial.println(" mW");
  Serial.println("");

  delay(2000);
}

```

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 6, 2021, 2:28am UTC](https://forum.arduino.cc/t/messuring-battery-voltage-and-current-with-ina219-inconsistent-values/620464/4 "2021-05-06T02:28:12Z")

</div>


