Arduino: Digital Current Sensor (INA219)

Chip which will reach current in a circuit and report it to Arduino via I2C.

DEVICENANOLOADPower Supply
VCC5V
GNDGNDNegative TerminalNegative Terminal
SCLA5
SDAA4
VIN-Positive Terminal
VIN+Positive Terminal

The default I2C address is 0x40. This can be changed by shorting a couple pads, so you could use up to four devices if you wanted.

AddressA0 PadsA1 Pads
0x40OPENOPEN
0x41OPENCLOSED
0x44CLOSEDOPEN
0x45CLOSEDCLOSED

Install the Adafruit INA219 library.

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

#define ina219_addr 0x40;
 
Adafruit_INA219 ina219(ina219_addr);
 
void setup(void) 
{
  ina219.begin();  // Initialize first board (default address 0x40)
}

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 Vo: "); Serial.print(shuntvoltage); Serial.println(" mV");
  Serial.print("Load Volt: "); 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);
}

From Adafruit’s documentation:

float getBusVoltage_V(void);  
Reads the voltage between GND and V-.  This is the total voltage seen by the circuit under test.  (Supply voltage – shunt voltage).  

The return value is in Volts.

float getShuntVoltage_mV(void);  
Reads the voltage between V- and V+.  This is the measured voltage drop across the shunt resistor.  

The return value is in Milivolts.

float getCurrent_mA(void);
Reads the current, derived via Ohms Law from the measured shunt voltage.

The return value is in Milliamps.

This entry was posted in Arduino and tagged . Bookmark the permalink.