INA219 sensor and Resistor Shunt

Hello friends,

Sorry if this has been already discussed, but I can't find anything in the other posts.

I have an INA219 I2C sensor that I want to use to measure currents up to a maximum of 50A (it's very rare to reach this figure).

The circuit to be measured is 12V and an external shunt sensor.

I've removed the on-board 0.1Ω shunt from the INA219 and connected it to my external 50A shunt, 75mV which has a resistance of 1.5mΩ. I connected it to the Arduino uno according to the sketch below and received the results on the serial monitor.

However, I'm having trouble calibrating the INA219 library to a 50A, 75mV shunt to get an accurate reading. I just want to measure Bus Voltage and Shunt Current for my application.

Does anyone have experience calibrating this board that might help me?

Appreciate any help and tips, thank you!

image

Please post the code, using code tags, and links to the board and the library you are using.

If you are using the Adafruit library, there are some notes on their site about calibration for an external shunt. If I recall correctly, that requires modifying the library code.

1 Like

here the link of the library Adafruit_INA219/Adafruit_INA219.cpp at master · adafruit/Adafruit_INA219 · GitHub and here the sketch

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

// Adafruit_INA219 ina219;        //Default adress is 0x40
Adafruit_INA219 ina219 (0x41);    // if A0 is jumpered
// Adafruit_INA219 ina219 (0x44); // if A1 is jumpered
// Adafruit_INA219 ina219 (0x45); // if A0 and A1 is jumpered


void setup(void)
{
  Serial.begin(9600);

  if (! ina219.begin()) {
    Serial.println("Failed to find INA219 chip");
    while (1) {
      delay(10);
    }
  }

  // By default the initialization will use the largest range (32V, 2A).  
  
  // 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();
}

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 = busvoltage * current_mA; 
  loadvoltage = busvoltage + (shuntvoltage / 1000);

  Serial.print("BUS: ");
  Serial.print(busvoltage);
  Serial.print(" V     ");

  Serial.print("SHUNT: ");
  Serial.print(shuntvoltage);
  Serial.print(" mV     ");

  Serial.print("LOAD: ");
  Serial.print(loadvoltage);
  Serial.print(" V     ");

  Serial.print("CURRENT: ");
  Serial.print(current_mA);
  Serial.print(" mA     ");

  Serial.print("POWER: ");
  Serial.print(power_mW);
  Serial.print(" mW");
  Serial.print(" or ");
  Serial.print(power_mW / 1000);
  Serial.println(" W");

  delay(500);

and this is link of the board DC Current Sensing with Raspberry Pi and Python | Medium

It is a somewhat complex process to calibrate a new shunt for that module.

See the answer to this post, and study the INA219 data sheet. arduino - Adafruit INA219 module, shunt voltage values and calibration - Stack Overflow

and study the INA219 data sheet. arduino - Adafruit INA219 module, shunt voltage values and calibration - Stack Overflow

Okay, Thankyou. I'll try

I looked quickly at the code and it seems to just print out the data.
Can you go into more detail?
What trouble are you having?
Do you know your 75A test current is stable, or you trying to input mv to simulate the shunt voltage?

1 Like

YES

IDK =( how to test my current is stable or not??

I am still having trouble changing the reading range to 75mv. Which parts of the library are in ina219? thankyou

Below is part of the adafruit library.

The shunt voltage is the voltage across the shunt. It doesn't matter what shunt you have, this is the voltage across it. You can calculate the actual current in your program.

 float shuntvoltage = 0;      //<----------------------------------------- voltage across shunt
  float busvoltage = 0;        //<---------------------------------------- bus voltage
  float current_mA = 0;      // ignore for your application
  float loadvoltage = 0;      // ignore for your application;

  shuntvoltage = ina219.getShuntVoltage_mV();
  busvoltage = ina219.getBusVoltage_V();
  current_mA = ina219.getCurrent_mA();
  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.println("");

Have you been reading my sketch on #3? I already put the formula in my sketch, but the results on the serial monitor were incorrect. How come? What's wrong and what should I do? Does the library need to make changes? tia^^

Hi,
If you have ZERO current, but with voltage applied, what readings of current and voltage do you get?

Thanks.. Tom.. :smiley: :+1: :coffee: :australia:

The INA219 has an internal current calculation function.
Which is used by Adafruit's library.
Current doesn't calculate from shunt voltage with software.
Therefore, the magic number of fomula result with used shunt resistor values is written to the calibration register of INA219.

Of course, it is possible to read only the shunt voltage without using the current reading function and calculate it with software.

1 Like

This is the result of a series of screen screens. The results are still wrong. Can you help me with what caused the results that were still incorrect?

Hi,
What are the voltage and current conditions at the shunt for those figures?

Tom.. :smiley: :+1: :coffee: :australia:

Could you elaborate?

Hi,
Can you give us the printed results for.

  1. 0V, thus 0Amps
  2. Fixed voltage, say 12 or 10V and some current, 5A if possible.

So you should have four readings for 1) and 4 readings for 2).

Thanks.. Tom... :smiley: :+1: :coffee: :australia:

YES. READ reply #4. It is not a trivial change.

Hi,

I was wrong, there are different gain settings in the INA219.

I looked through your code and looked at the Adafruit example. I see only minor differences however since you are getting erroreornous results I suggest you try the Adafruit example: "getcurrent.ino" as it is written, make NO changes. Don't add the device address as you did with your code.

I don't know if the above will solve your issue but it is what I would do if I were in your place.

If that doesn't work then the only two options are:

  1. The wiring is not what you think

  2. the INA219 is not working properly.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.