The INA219 is a high-side current shunt and power monitor with an I2C-compatible interface. The device monitors both shunt voltage drop and bus supply voltage, with programmable conversion times and filtering. A precision current-sensing amplifier, an analog-to-digital converter (ADC), and a data acquisition system are integrated into the INA219. It is commonly used in applications such as power management, system protection, battery chargers, and automotive systems.
Pin Number | Name | Description |
---|---|---|
1 | V_IN+ | Positive voltage input. Connect to the positive side of the power supply. |
2 | V_IN- | Negative voltage input. Connect to the load side of the shunt resistor. |
3 | GND | Ground. Connect to the system ground. |
4 | SDA | I2C Data. Connect to the I2C data line. |
5 | SCL | I2C Clock. Connect to the I2C clock line. |
6 | A0 | Address pin. Connect to GND or Vcc to set the I2C address. |
7 | A1 | Address pin. Connect to GND or Vcc to set the I2C address. |
8 | Vcc | Power supply for the INA219. Connect to 3.0V to 5.5V. |
#include <Wire.h>
#include <Adafruit_INA219.h>
Adafruit_INA219 ina219;
void setup(void)
{
Serial.begin(9600);
while (!Serial) {
// Wait for Serial to be ready
}
uint32_t currentFrequency;
// Initialize the INA219.
// By default the initialization will use the largest range (32V, 2A).
if (!ina219.begin()) {
Serial.println("Failed to find INA219 chip");
while (1) { delay(10); }
}
// 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;
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("");
delay(2000);
}
Wire
library's beginTransmission()
and endTransmission()
functions to check for I2C communication issues.Q: Can the INA219 measure both AC and DC currents? A: The INA219 is designed to measure DC currents only.
Q: What is the maximum voltage that can be measured? A: The INA219 can measure bus voltages up to 26V.
Q: How do I change the I2C address of the INA219? A: The I2C address can be changed by connecting the A0 and A1 pins to either GND or Vcc. The datasheet provides a table of the address configurations.
Q: Is it necessary to calibrate the INA219? A: The INA219 comes pre-calibrated, but you can adjust the calibration settings to match the shunt resistor and expected current range for higher accuracy.
Q: Can the INA219 be used with a microcontroller other than an Arduino? A: Yes, the INA219 can be interfaced with any microcontroller that supports I2C communication. Adjustments to the code may be necessary to accommodate different platforms.