INA219 current monitor

A current, voltage and power monitor on a purple breakout with a 0.1 Ω shunt resistor. Aliases: current sensor, power monitor, wattmeter module.

Put it in series with a load and it tells you, over I2C, how much current the load draws and at what voltage. It does it by measuring the tiny voltage across the shunt with an amplifier that resolves ten microvolts.

Pins

Pin What it does
VCC The chip's own supply, 3 to 5.5 V.
GND Ground, shared with the circuit being measured.
SCL I2C clock. The module carries the pull-ups.
SDA I2C data.
VIN+ One end of the shunt: the supply side.
VIN- The other end: to the load.

Properties

address is 0x40 as the module ships, and 0x41, 0x44 or 0x45 with its solder jumpers closed; any of the chip's sixteen addresses from 0x40 to 0x4F works.

A real resistor in the circuit

VIN+ and VIN- are the two ends of the shunt, and the part is that 0.1 Ω resistor: the load's current really flows through it and really drops 0.1 V per amp. So the reading is whatever the circuit is doing, not a number on a slider, and the face shows the same current the simulation computes. Put the module in backwards and the current reads negative, as it does on a bench.

It measures two things:

  • the shunt voltage, VIN+ minus VIN-, in 10 µV steps;
  • the bus voltage, VIN- to ground, in 4 mV steps.

The current and the power are the chip's own arithmetic on those two.

The library

Adafruit_INA219.h works as the tutorials use it:

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

Adafruit_INA219 ina219;

void setup() {
  Serial.begin(115200);
  if (!ina219.begin()) { Serial.println("No INA219"); while (1); }
}

void loop() {
  Serial.print(ina219.getBusVoltage_V());  Serial.println(" V");
  Serial.print(ina219.getCurrent_mA());    Serial.println(" mA");
  Serial.print(ina219.getPower_mW());      Serial.println(" mW");
  delay(1000);
}

setCalibration_32V_1A() and setCalibration_16V_400mA() trade range for resolution, as upstream.

What the model gets right

Calibration. The chip powers up with its calibration register at zero, and until something writes it the current and power registers read zero, whatever flows. The library's begin() writes it; a hand-written driver that forgets gets a perfectly steady zero.

Gain. The shunt amplifier's range is ±40, 80, 160 or 320 mV, which through 0.1 Ω is 0.4, 0.8, 1.6 or 3.2 A. A current past the range reads as the end of it.

Time. The ADC converts continuously by default, shunt then bus, 532 µs each at 12 bits and up to 68 ms each when averaging 128 samples. Results change when a conversion finishes, and the conversion-ready bit says so. The triggered and power-down modes are there too.

What it does not model

Noise, so averaging changes only the conversion time here. The 16 V bus range does not saturate above 16 V. The address pins, which are the address property. The chip's own supply current.

Common mistakes

Putting the load's supply on VIN- and the load on VIN+: the current reads negative. Forgetting that the bus voltage is measured at VIN-, the load side, so it is the supply less the shunt's drop. Forgetting the common ground between the monitored circuit and the board.