What is the INA219?
A multimeter tells you the voltage and, if you break the circuit and put it in series, the current. The INA219 does both continuously, without breaking anything, and hands the results to your microcontroller as numbers. It is Texas Instruments' small high-side current and power monitor: it measures the voltage drop across a tiny shunt resistor in your supply line, measures the bus voltage at the same time and calculates power for you.
Most hobby boards carry the chip with a 0.1 Ω shunt and a pair of screw terminals, so the whole thing is a ready-made inline power meter. Connect VIN+ to the supply and VIN− to the load, wire four pins to your board, and read volts, milliamps and milliwatts over I²C.
This page explains how it measures, why the shunt and calibration choices matter, how to wire it without the classic mistakes, and how it compares with the INA226, INA260 and ACS712. For working code, the Arduino Uno guide builds a battery capacity tester and an LCD power meter, and the ESP32 guide builds a live power page for your phone and an electronic fuse.
Specifications
- Measures
- Bus voltage, shunt voltage, current and power over I²C
- Bus voltage range
- 0 to 26 V (the library's '32 V' setting is a range option, not a safe input level)
- Shunt voltage range
- ±40, ±80, ±160 or ±320 mV (programmable gain; ±320 mV by default)
- Typical breakout shunt
- 0.1 Ω (marked R100), giving about ±3.2 A full scale
- ADC resolution
- 12-bit; shunt step 10 µV, bus voltage step 4 mV
- Current resolution
- 0.1 mA with the library's default 32 V / 2 A calibration; 40 µA with 32 V / 1 A
- Offset
- About ±10 µV typical, ±100 µV max on the shunt input (up to ~1 mA with 0.1 Ω)
- Supply voltage (VCC)
- 3.0 to 5.5 V, so it works on 3.3 V and 5 V boards
- Supply current
- About 1 mA while converting
- Interface
- I²C / SMBus, up to 400 kHz on common boards
- I²C address
- 0x40 default; 0x41, 0x44 or 0x45 with the breakout's A0 / A1 pads (the chip supports 16)
- Conversion time
- 84 µs (9-bit) to 68 ms (128-sample average); 532 µs in the default 12-bit mode
- Sensing
- High-side: the shunt sits in the positive supply line; current is signed (±)
Figures from the Texas Instruments INA219 datasheet and the Adafruit INA219 library. Check your own board's shunt marking and resistor power rating.
Pinout
| Pin | Name | Description |
|---|---|---|
| 1 | VIN+ | Positive side of the shunt. Connect to the power source (+). Not a power input for the chip |
| 2 | VIN− | Other side of the shunt. Connect to the load (+). Bus voltage is measured here |
| 3 | VCC | Chip power, 3.0 to 5.5 V from your microcontroller |
| 4 | GND | Ground. Must be shared with the microcontroller and the measured circuit |
| 5 | SDA | I²C data |
| 6 | SCL | I²C clock |
Most breakouts repeat VIN+ and VIN− on the header and on the screw terminals; use the terminals for anything above a few hundred milliamps.
Wiring & code
Setting up INA219 with Arduino Uno
Library
Adafruit INA219 by Adafruit
Arduino IDE → Tools → Manage Libraries → search "Adafruit INA219" → Install (accept the prompt to also install "Adafruit BusIO")
This guide turns an INA219 and an Arduino Uno into a working power meter in three steps. First you wire it and read volts, milliamps and milliwatts in the Serial Monitor. Then you build a battery capacity tester that discharges a cell, counts milliamp-hours and watt-hours, and switches the load off at a safe voltage. Finally you put a live power meter on an LCD1602, sharing the same two I²C wires as the INA219.
New to the sensor? The INA219 overview explains the shunt, the calibration presets and the accuracy limits behind these sketches.
What you need
1Arduino Uno R3 (or Nano, Uno R4)
- Notes
- Any 5 V Arduino uses the same pins: SDA = A4, SCL = A5
1INA219 breakout with 0.1 Ω shunt
- Notes
- The common purple or blue board marked R100
1A load and its supply
- Notes
- For example a 12 V LED strip or a small motor with its own supply
1Fuse holder and fuse (1 to 3 A)
- Notes
- Between the supply and VIN+
1 each18650 cell (protected) or NiMH pack, 10 Ω 5 W resistor, logic-level MOSFET (IRLZ44N or similar), 220 Ω and 100 kΩ resistors
- Notes
- Only for Sketch 2
1LCD1602 with I²C backpack
- Notes
- Only for Sketch 3
Wiring
| INA219 pin | Arduino Uno pin | Note |
|---|---|---|
| VCC | 5V | The INA219 breakout accepts 3.0–5.5 V. Use 5 V on the Uno. |
| GND | GND | Must also be common with the ground of the circuit you measure. |
| SDA | A4 | Uno hardware I²C data pin. |
| SCL | A5 | Uno hardware I²C clock pin. |
| VIN+ | Power source (+) | Not an Arduino pin. Connect to the positive terminal of the supply or battery. |
| VIN− | Load (+) | Not an Arduino pin. Connect to the positive input of the load you want to measure. |
VIN+ and VIN− are not Arduino pins. They go in series with the positive wire of the circuit you are measuring. The only electrical links to the Uno are VCC, the I²C pair and the shared ground.
Don't measure big loads off the Uno's 5V pin. The Uno's regulator and your USB port limit that current. For motors, LED strips and chargers, use a separate supply and share only the ground. The Uno's A4 and A5 are the same signals as the SDA and SCL pins next to AREF on R3 boards, so either pair works; see the Arduino Uno pinout.
Install the library
- 1In the Arduino IDE open Sketch > Include Library > Manage Libraries (Ctrl+Shift+I).
- 2Search for "Adafruit INA219" and install it.
- 3When asked to install dependencies, choose Install All: the library needs "Adafruit BusIO".
- 4Select Tools > Board > Arduino AVR Boards > Arduino Uno and the Uno's port under Tools > Port.
Sketch 1 - Read voltage, current and power
Upload this, open the Serial Monitor at 115200 baud, and switch your load on and off. The current should jump from near zero to the load's draw, and the load voltage should sit slightly below the supply voltage.
#include <Wire.h>
#include <Adafruit_INA219.h>
Adafruit_INA219 ina219; // default I2C address 0x40
void setup() {
Serial.begin(115200);
if (!ina219.begin()) {
Serial.println(F("INA219 not found - check wiring and I2C address"));
while (1) delay(10);
}
ina219.setCalibration_32V_2A(); // 0.1 ohm shunt: up to ~3.2 A in 0.1 mA steps
Serial.println(F("INA219 ready"));
}
void loop() {
float shunt_mV = ina219.getShuntVoltage_mV();
float bus_V = ina219.getBusVoltage_V(); // load side (VIN-)
float current_mA = ina219.getCurrent_mA();
float power_mW = ina219.getPower_mW();
float supply_V = bus_V + shunt_mV / 1000.0; // source side (VIN+)
Serial.print(F("Supply: ")); Serial.print(supply_V, 3); Serial.print(F(" V "));
Serial.print(F("Load: ")); Serial.print(bus_V, 3); Serial.print(F(" V "));
Serial.print(F("Current: ")); Serial.print(current_mA, 1); Serial.print(F(" mA "));
Serial.print(F("Power: ")); Serial.print(power_mW, 0); Serial.println(F(" mW"));
delay(500);
}How Sketch 1 works
| Line | What it does |
|---|---|
| Adafruit_INA219 ina219; | Creates the sensor object at the default address 0x40. Pass another address, e.g. ina219(0x41), for a board with A0 bridged |
| ina219.begin() | Starts I²C, resets the chip and returns false if nothing answers: the first thing to check when it fails |
| setCalibration_32V_2A() | Writes calibration 4096 for a 0.1 Ω shunt: ±3.2 A in 0.1 mA steps. Try 32V_1A or 16V_400mA for smaller loads |
| getShuntVoltage_mV() | The drop across the shunt; 100 mV means 1 A with 0.1 Ω |
| getBusVoltage_V() | The voltage at VIN−, i.e. what the load sees |
| getCurrent_mA() | Signed current: positive from VIN+ to VIN−, negative if it flows the other way |
| getPower_mW() | Bus voltage × current, computed by the chip in 2 mW steps |
| bus_V + shunt_mV / 1000 | Adds the shunt drop back to estimate the supply voltage at VIN+ |
If it prints "INA219 not found", run an I²C scanner sketch. 0x40 means the chip answers and the problem is in the sketch; no address at all points to wiring, power or a header that was never soldered. If the current reads negative, VIN+ and VIN− are swapped.
Sketch 2 - Battery capacity tester (mAh and Wh)
The number printed on a cheap battery is often fiction. This sketch measures the real capacity: it discharges the cell through a power resistor, adds up current × time every second into milliamp-hours, and power × time into milliwatt-hours, then switches the load off at a safe cut-off voltage and prints the result.
Three details make the numbers trustworthy:
- It measures the real elapsed time with
millis()instead of assuming exactly one second, so slow Serial prints cannot make the total drift. - It zeroes itself. Before switching the load on it averages 20 readings with no current flowing and subtracts that offset from every sample.
- It reads the battery, not the load. The cut-off uses the voltage at VIN+ (bus + shunt), the battery's own terminal voltage under load.
Extra wiring for Sketch 2
| From | To | Notes |
|---|---|---|
| Battery (+) | INA219 VIN+ | Through a fuse |
| INA219 VIN− | 10 Ω 5 W resistor | About 370 mA from a 3.7 V Li-ion cell, 1.4 W of heat: mount it in free air |
| Resistor (other end) | MOSFET drain | Logic-level N-channel MOSFET such as IRLZ44N |
| MOSFET source | Battery (−) and Uno GND | All grounds joined |
| MOSFET gate | D7 through 220 Ω | Plus 100 kΩ from gate to GND so the load stays off during reset |
#include <Wire.h>
#include <Adafruit_INA219.h>
Adafruit_INA219 ina219;
const uint8_t LOAD_PIN = 7; // MOSFET gate: HIGH = load on
const float CUTOFF_V = 3.00; // Li-ion: 3.0 V under load. NiMH: 1.0 V per cell
const unsigned long SAMPLE_MS = 1000;
float zero_mA = 0; // offset measured with the load off
float mAh = 0, mWh = 0;
unsigned long startMs, lastMs;
bool running = false;
float batteryVolts() { // voltage at VIN+, i.e. the battery itself
return ina219.getBusVoltage_V() + ina219.getShuntVoltage_mV() / 1000.0;
}
void setup() {
Serial.begin(115200);
pinMode(LOAD_PIN, OUTPUT);
digitalWrite(LOAD_PIN, LOW);
if (!ina219.begin()) {
Serial.println(F("INA219 not found"));
while (1) delay(10);
}
ina219.setCalibration_32V_1A(); // up to ~1.3 A in 40 uA steps
float v = batteryVolts();
if (v <= CUTOFF_V) {
Serial.print(F("Battery at ")); Serial.print(v, 2);
Serial.println(F(" V: below cut-off or not connected. Not starting."));
while (1) delay(10);
}
for (int i = 0; i < 20; i++) { // auto-zero: no current is flowing yet
zero_mA += ina219.getCurrent_mA();
delay(20);
}
zero_mA /= 20;
Serial.println(F("seconds,volts,mA,mAh,mWh"));
digitalWrite(LOAD_PIN, HIGH); // start the discharge
startMs = lastMs = millis();
running = true;
}
void loop() {
if (!running || millis() - lastMs < SAMPLE_MS) return;
unsigned long now = millis();
float hours = (now - lastMs) / 3600000.0; // real time since the last sample
lastMs = now;
float v = batteryVolts();
float mA = ina219.getCurrent_mA() - zero_mA;
mAh += mA * hours;
mWh += mA * v * hours;
Serial.print((now - startMs) / 1000); Serial.print(',');
Serial.print(v, 3); Serial.print(',');
Serial.print(mA, 1); Serial.print(',');
Serial.print(mAh, 1); Serial.print(',');
Serial.println(mWh, 0);
if (v <= CUTOFF_V) {
digitalWrite(LOAD_PIN, LOW); // stop before the cell is over-discharged
running = false;
Serial.print(F("Done: ")); Serial.print(mAh, 0); Serial.print(F(" mAh, "));
Serial.print(mWh / 1000.0, 2); Serial.println(F(" Wh"));
}
}Danger
Discharging lithium cells is safe only with care: use a protected cell or a holder with protection, keep the 3.0 V cut-off (never lower), add the fuse, and do not leave the test unattended. The 10 Ω resistor gets hot enough to burn: keep it off the breadboard and away from plastic.
Reading the result. A fresh, genuine 2,500 mAh 18650 at about 370 mA should report something near its rating; a cell that stops at 800 mAh is either worn or mislabelled. The output is CSV: copy it from the Serial Monitor into a spreadsheet and chart volts against seconds to see the discharge curve. For NiMH packs, set CUTOFF_V to 1.0 V × the number of cells.
Why mWh as well as mAh? Two cells can deliver the same mAh at different voltages. Watt-hours count the energy actually delivered, which is what matters when you compare a cell with a power bank or estimate how long a project will run.
Sketch 3 - LCD1602 power meter on the same I²C bus
I²C devices with different addresses share the same two wires. The INA219 sits at 0x40 and an LCD1602 backpack at 0x27 (or 0x3F), so the display simply clips onto A4 and A5 alongside the sensor. This sketch averages ten readings for a steady display, shows volts and milliamps on the top line, and watts plus a running mAh total on the second.
Extra wiring for Sketch 3
| LCD1602 I²C pin | Uno pin | Notes |
|---|---|---|
| GND | GND | Shared ground |
| VCC | 5V | The backpack and backlight need 5 V |
| SDA | A4 | Same wire as the INA219's SDA |
| SCL | A5 | Same wire as the INA219's SCL |
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Adafruit_INA219.h>
Adafruit_INA219 ina219; // 0x40
LiquidCrystal_I2C lcd(0x27, 16, 2); // try 0x3F if the screen stays blank
float mAh = 0;
unsigned long lastMs;
void setup() {
lcd.init();
lcd.backlight();
if (!ina219.begin()) {
lcd.print(F("No INA219"));
while (1) delay(10);
}
ina219.setCalibration_32V_2A();
lastMs = millis();
}
void loop() {
// Average 10 readings over ~250 ms for a steady display
float mA = 0, v = 0;
for (byte i = 0; i < 10; i++) {
mA += ina219.getCurrent_mA();
v += ina219.getBusVoltage_V();
delay(25);
}
mA /= 10;
v /= 10;
unsigned long now = millis();
mAh += mA * (now - lastMs) / 3600000.0;
lastMs = now;
// Overwrite in place (no lcd.clear()) so the display does not flicker
lcd.setCursor(0, 0);
lcd.print(v, 2); lcd.print(F("V "));
lcd.print(mA, 0); lcd.print(F("mA "));
lcd.setCursor(0, 1);
lcd.print(v * mA / 1000.0, 2); lcd.print(F("W "));
lcd.print(mAh, 1); lcd.print(F("mAh "));
}Install LiquidCrystal I2C by Frank de Brabander from the Library Manager. If the backlight is on but no text shows, turn the contrast potentiometer on the backpack, then try 0x3F. The LCD1602 I2C guide has an address scanner. To use a 0.96" OLED instead, see the SSD1306 OLED guide; it also lives on the same bus.
Troubleshooting on the Uno
'INA219 not found'
- Likely cause
- SDA/SCL swapped, VCC missing, or header not soldered
- Fix
- SDA to A4, SCL to A5, VCC to 5V; run an I²C scanner and expect 0x40
Current reads 0 while the load runs
- Likely cause
- The load's current does not pass through VIN+ → VIN−
- Fix
- Re-wire in series with the positive wire
Sketch 2 refuses to start
- Likely cause
- Battery below the cut-off, not connected, or VIN+ not on the battery
- Fix
- Check the battery voltage with a meter; the sketch reads VIN+
Sketch 2 current is ~0 after the start
- Likely cause
- MOSFET not switching: wrong pin, missing gate resistor or a non-logic-level MOSFET
- Fix
- Use a logic-level part, gate on D7, source to ground
mAh total far too low or too high
- Likely cause
- Wrong preset clips the current, or the offset was taken with current flowing
- Fix
- Use 32V_1A up to ~1.3 A (32V_2A above), and keep the load off until the sketch starts it
LCD blank, backlight on
- Likely cause
- Contrast, or the backpack is at 0x3F
- Fix
- Turn the contrast potentiometer, then change the address in the sketch
Readings drop out when the load switches
- Likely cause
- Supply dip resets the Uno or upsets I²C
- Fix
- Separate supplies for load and Uno, grounds joined; short I²C wires
Arduino Uno FAQ
Does this work on a Nano, Mega or Uno R4? Yes. The Nano uses A4/A5 like the Uno; the Mega's I²C pins are 20 (SDA) and 21 (SCL). The sketches are unchanged.
Can I read two INA219s on one Uno?
Yes. Bridge A0 on the second board (address 0x41) and create two objects: Adafruit_INA219 battery(0x40); and Adafruit_INA219 solar(0x41);. Call begin() on both.
Why is the power reading slightly different from volts × amps in my head? The chip computes power from the bus voltage (after the shunt) and reports it in 2 mW steps, while your mental sum may use the supply voltage. Both are correct; they measure at different points.
Can I log for hours?
Yes. The millis() timer wraps after about 49 days, and the unsigned subtraction in the sketches handles the wrap correctly.
Where next? Move the meter onto Wi-Fi with the INA219 ESP32 guide, or compare current sensors in the INA219 overview.








