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.
INA219 at a glance
INA219 in one paragraph. Put the board in series with the positive wire (supply → VIN+, VIN− → load), share ground with your microcontroller, and read it over I²C at 0x40. It handles 0 to 26 V and, with the standard 0.1 Ω shunt, up to about 3.2 A in 0.1 mA steps. Need more than 26 V or better accuracy: the INA226. More than 3 A without swapping a resistor: the INA260. AC current or isolation: the ACS712.
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.
Two sides, two jobs. The screw terminals VIN+ and VIN− are the two ends of the shunt: your load current flows through them, so the board sits in series with the positive wire between source and load. The header row (VCC, GND, SDA, SCL) is the I²C side that goes to your Arduino or ESP32. The measured circuit can run at a different voltage, up to 26 V, as long as its ground is shared with the microcontroller's.
How the INA219 measures current
The INA219 never measures current directly. It measures a small voltage, and Ohm's law does the rest. When your load current flows through the shunt, a voltage appears across it equal to current × resistance: with 0.1 Ω, 1 A makes 100 mV and 100 mA makes just 10 mV. The chip's 12-bit converter reads that in steps of 10 µV, which with 0.1 Ω is 0.1 mA per step.
It reads two voltages, one after the other:
- the shunt voltage, between VIN+ and VIN−, which is proportional to the current;
- the bus voltage, at VIN− relative to ground, which is what your load actually sees.
A value in the calibration register tells the chip how to turn shunt voltage into amps: Cal = 0.04096 ÷ (Current_LSB × R_shunt). For a 0.1 Ω shunt and 0.1 mA steps that is exactly 4096, the value the Adafruit library writes for its default range. Power is bus voltage × current, and the power step is always 20 × the current step.
Because the shunt is on the positive side (high-side), the load keeps a solid ground. Put a shunt in the ground wire instead and the circuit's ground floats up by the voltage drop, so your microcontroller and sensors no longer share a true ground.
Worked example. A 12 V pump draws 1 A through the 0.1 Ω shunt. The shunt drops 100 mV, which the ADC reads as 10,000 steps of 10 µV. With calibration 4096 the current register also reads 10,000, × 0.1 mA = 1000.0 mA. The bus voltage at VIN− is 12.00 V, so power is 12.0 W. The supply itself is at 12.00 + 0.10 = 12.10 V: that 0.1 V is the shunt's "burden", the voltage your load loses to the measurement.
The shunt resistor: range and resolution
The shunt is the single most important design choice. A larger shunt makes a larger voltage for the same current, so it resolves small currents better, but it wastes more voltage and heat at high current. A smaller shunt does the opposite.
Shunt choice at the ±320 mV range
| Shunt | Max current | Current step | Drop at full scale | Best for |
|---|---|---|---|---|
| 1 Ω | 320 mA | 10 µA | 0.32 V | Small sensor nodes, low-power IoT |
| 0.1 Ω (standard board) | 3.2 A | 0.1 mA | 0.32 V | Motors, LED strips, battery projects |
| 0.01 Ω | 32 A | 1 mA | 0.32 V | High-current loads (needs a proper shunt and wiring) |
- Burden voltage. At 1 A through 0.1 Ω you lose 0.1 V; at 3 A, 0.3 V. On a 12 V motor that does not matter. On a 3.3 V ESP32 rail it can trigger a brown-out, so measure the higher-voltage side of the regulator where you can.
- Heat. Power in the shunt is I²R: 3 A through 0.1 Ω is 0.9 W. Check your board's resistor rating (often 1 W or less) and keep continuous current well below the maximum.
- Resolution is not accuracy. A 10 µV step is tiny, but the offset (up to ±100 µV, about ±1 mA with 0.1 Ω), noise and the shunt's own tolerance limit real precision. Subtract the zero reading in software and expect a percent or so of gain error.
To change the shunt, replace the resistor and recalculate the calibration. The INA219_WE and Rob Tillaart INA219 libraries accept a custom shunt value; the Adafruit library assumes 0.1 Ω.
Choosing a calibration preset
The Adafruit library offers three presets for the 0.1 Ω shunt. They change two things: the shunt voltage range (the programmable gain) and the current step the chip reports in.
setCalibration_32V_2A()is the default: ±320 mV, so up to 3.2 A, in 0.1 mA steps.setCalibration_32V_1A()keeps ±320 mV but uses 40 µA steps. The current register then tops out at about 1.3 A, so above that the reading clips even though the shunt could go higher.setCalibration_16V_400mA()switches to the ±40 mV range (gain /1) and a 16 V bus range. Its step is 50 µA, but the lower gain reduces noise and offset, which is what helps small loads. Never use it on a supply above 16 V.
Pick the smallest preset that safely covers your peak current, including motor start-up or Wi-Fi bursts.
Wiring: in series with the positive line
The INA219 is wired like an ammeter: the current must pass through the board. The most common beginner mistake is connecting VIN+ and VIN− across the load like a voltmeter, which either shorts the supply through the shunt or reads nothing useful.
- Source (+) → VIN+
- VIN− → load (+)
- Load (−) → source (−), as normal
- INA219 GND → the same ground, shared with the microcontroller
- VCC → 3.3 V or 5 V from the microcontroller (3.3 V on an ESP32)
- SDA / SCL → the board's I²C pins: A4 / A5 on an Uno, GPIO21 / GPIO22 on an ESP32 DevKit
For more than one INA219 on a bus, bridge the address pads: A0 gives 0x41, A1 gives 0x44 and both give 0x45, so four breakouts can share two wires without extra work. The chip itself supports 16 addresses if you tie A0 and A1 to SDA or SCL instead of ground or VCC. See ESP32 I²C pins and multiple devices for running several I²C parts together.
Warning
Add a fuse between the supply and VIN+. A short circuit, a stalled motor or a battery with no current limit can push many amps through the 0.1 Ω shunt in a fraction of a second, long before your code can react.
Getting accurate readings
- Remove the zero offset. With the load disconnected the reading should be 0.0 mA. A small steady value, such as 0.4 mA, is offset error: measure it once and subtract it in code. The Uno battery tester does this automatically before it starts.
- Use the right range. A 3.2 A range measuring a 20 mA sensor node jumps in 0.1 mA steps and noise looks large. Switch to the 16 V / 400 mA preset or a bigger shunt for low-current work.
- Average noisy loads. Motors, switching regulators and radios draw current in spikes, and one 532 µs conversion can land on a peak or a trough. Average many samples, or set the chip's built-in averaging with a library that exposes it.
- Don't expect sleep current. A deep-sleeping ESP32 draws microamps; 0.1 mA steps plus offset cannot see that. Use a 1 Ω or larger shunt, or a tool made for low currents.
- Short, thick wires and tight terminals. Wire resistance adds to the shunt's and heats up; a loose screw terminal is a classic cause of flickering readings.
- Check once against a multimeter. Put a trusted meter in series and compare at two or three currents. If the INA219 is consistently a percent or two off, apply a gain correction factor.
INA219 vs INA226 vs INA260 vs INA3221 vs ACS712
INA219
- Bus voltage
- 0–26 V
- Current range
- ±3.2 A with 0.1 Ω
- ADC
- 12-bit
- Pick it when
- Cheap, everywhere, plenty for battery and motor projects
INA226
- Bus voltage
- 0–36 V
- Current range
- Depends on shunt (often ±0.8 A or more)
- ADC
- 16-bit
- Pick it when
- You need better accuracy, 12 V/24 V systems with headroom, or an alert pin
INA260
- Bus voltage
- 0–36 V
- Current range
- ±15 A, 2 mΩ shunt built in
- ADC
- 16-bit
- Pick it when
- High current without choosing or soldering a shunt
INA3221
- Bus voltage
- 0–26 V
- Current range
- Three channels, 0.1 Ω each
- ADC
- 13-bit
- Pick it when
- Monitoring three rails with one chip
ACS712
- Bus voltage
- Not measured
- Current range
- 5 / 20 / 30 A versions
- ADC
- Analog output
- Pick it when
- AC current or galvanic isolation; noisier with a large zero offset
Ranges from each part's datasheet. The ACS712 needs your board's ADC, so its real resolution depends on the microcontroller.
Ready to build? Both guides start with wiring and a first reading, then go further:
- INA219 with Arduino Uno: readings explained line by line, a battery capacity tester that logs mAh and Wh and cuts the load at a safe voltage, and an LCD1602 power meter sharing the I²C bus
- INA219 with ESP32: a live power and energy page on your phone, and an electronic fuse that switches the load off when the current stays too high
Troubleshooting
'INA219 not found'
- Likely cause
- Wiring, no VCC, wrong I²C pins or address
- Fix
- Check VCC, GND, SDA, SCL and run an I²C scanner. The default address is 0x40
Current always reads 0
- Likely cause
- Load not passing through the board, or VIN+ / VIN− across the load
- Fix
- Put the board in series with the positive wire: source to VIN+, load to VIN−
Current is negative
- Likely cause
- Current flows from VIN− to VIN+
- Fix
- Swap the two wires, or keep the sign if it is a charging current
Bus voltage reads 0 or very low
- Likely cause
- Ground not shared, or the load side is unpowered
- Fix
- Join the INA219 GND, the microcontroller GND and the circuit's ground
A few mA with nothing connected
- Likely cause
- Offset of the shunt amplifier
- Fix
- Measure the zero reading and subtract it
Readings jump around
- Likely cause
- Spiky load, loose terminal or long wires
- Fix
- Average samples, tighten the terminals, shorten the wires
Current stuck at about 1.31 A or 3.2 A
- Likely cause
- The load exceeds the calibration range
- Fix
- Use a larger preset, a smaller shunt, or reduce the load
ESP32 resets when the load starts
- Likely cause
- Shunt drop or inrush pulls the 3.3 V rail down
- Fix
- Measure a higher-voltage rail, or power the ESP32 separately
Board gets very hot
- Likely cause
- Current above the shunt's rating
- Fix
- Reduce the current or move to an INA260 or a heavier shunt
Two INA219s clash
- Likely cause
- Same address on both
- Fix
- Bridge A0 or A1 on one board
What to build with it
- Battery capacity tester that discharges a cell to a safe cut-off and reports real mAh and Wh (built in the Uno guide).
- Pocket USB power meter with an LCD or OLED that shows volts, amps, watts and mAh for chargers and cables.
- Solar charge monitor logging panel voltage and charging current across the day.
- Electronic fuse for DC loads that switches a relay or MOSFET off on overcurrent (built in the ESP32 guide).
- Motor stall detector that spots a jam from the jump in current.
- Energy dashboard sending readings over MQTT to Home Assistant, or into InfluxDB and Grafana.
Frequently asked questions
What is the maximum voltage and current of the INA219? The bus voltage can go up to 26 V. With the common 0.1 Ω shunt, full scale is about 3.2 A, though the resistor's power rating limits how long you can run near that.
Why does the library say "32V" if the chip only handles 26 V? "32 V" is the full-scale range setting of the bus-voltage converter. The pins' limit is 26 V, so never apply more.
Can I use it with a 3.3 V board like the ESP32? Yes. Power VCC from 3.3 V and use the ESP32's I²C pins. The measured circuit can be at a higher voltage, up to 26 V.
What does "high-side" mean? The sensing resistor sits in the positive supply line, not in the ground return, so the load keeps its true ground.
Can it measure charging and discharging? Yes. Current is signed: positive from VIN+ to VIN−, negative the other way. With a battery between a charger and a load, the sign tells you which way energy is flowing.
Can I measure AC current with it? No. The INA219 is for DC, and its bus voltage is referenced to ground. For AC mains use an isolated sensor made for the job and take proper safety precautions.
How do I use several INA219 boards?
Give each one a different address with the A0 / A1 pads (0x40, 0x41, 0x44, 0x45) and create one library object per address, for example Adafruit_INA219 battery(0x40); and Adafruit_INA219 solar(0x41);.
INA219 or INA226? Choose the INA226 if you need more than 26 V, 16-bit resolution or an alert pin; it costs a little more and needs a different library. For hobby battery, motor and USB projects the INA219 is enough.
INA219 or ACS712? The INA219 is a digital shunt monitor that reports voltage, current and power over I²C and is far more accurate at small currents. The ACS712 is a Hall-effect sensor with an analog output that is isolated and can measure AC, but it is noisier and has a large zero offset.
Is it accurate enough to test battery capacity? For hobby use, yes: after removing the zero offset, expect results within a few percent, enough to compare cells and spot fakes.
Datasheets and references
- Texas Instruments INA219 datasheet - ranges, calibration formula, conversion times and offset figures used on this page.
- Adafruit INA219 library - the library used in the Uno and ESP32 guides, including its three calibration presets.
- INA219_WE (Wolfgang Ewald) and INA219 (Rob Tillaart) libraries - for custom shunts, gain and averaging settings.
Validate your board's voltage, current and heating limits against your exact hardware before using it in a critical system.
Wiring & code
Board integration
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.
