The INA219 is a high-side current shunt and power monitor with an I2C-compatible interface. Manufactured by Virgo Energy, the INA219 provides precise current and voltage monitoring with programmable calibration values. It is commonly used in applications such as battery chargers, power supplies, and portable instruments to monitor the current draw and power consumption of the system.
Pin Number | Name | Description |
---|---|---|
1 | V_IN+ | Positive voltage input. Connect to the positive side of the power supply. |
2 | GND | Ground. Connect to the system ground. |
3 | SDA | I2C Data. Connect to the I2C data line. |
4 | SCL | I2C Clock. Connect to the I2C clock line. |
5 | A0 | Address pin 0. Used to set the I2C address. |
6 | A1 | Address pin 1. Used to set the I2C address. |
7 | V_IN- | Negative voltage input. Connect to the negative side of the shunt resistor. |
8 | V_BUS | Bus voltage. Connect to the positive side of the shunt resistor. |
#include <Wire.h>
#include <Adafruit_INA219.h>
Adafruit_INA219 ina219;
void setup() {
Serial.begin(9600);
while (!Serial) {
// Wait for serial port to connect (needed for Leonardo only)
}
ina219.begin(); // Initialize the INA219
}
void loop() {
float shuntvoltage = 0;
float busvoltage = 0;
float current_mA = 0;
float loadvoltage = 0;
busvoltage = ina219.getBusVoltage_V();
shuntvoltage = ina219.getShuntVoltage_mV();
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);
}
Q: Can I measure current in both directions? A: Yes, the INA219 can measure bidirectional current, but you may need to adjust the calibration settings.
Q: What is the maximum wire length for the I2C connection? A: I2C is typically used for short distances, but with proper shielding and pull-up resistors, longer distances up to a few meters can be achieved.
Q: How do I change the I2C address? A: The I2C address can be changed by setting the A0 and A1 pins to different logic levels. Refer to the datasheet for the address table.
Q: Can the INA219 be used with a microcontroller other than an Arduino? A: Yes, as long as the microcontroller supports I2C communication, you can use the INA219 with it. You may need to adapt the code and library accordingly.