The INA219 is a high-side current sensor: you cut the positive wire of whatever you want to measure and route it through VIN+ → VIN−. It then reports voltage, current and power over I2C — exactly what a NodeMCU solar or battery logger needs.
It talks I2C, so it shares D1 (SCL) and D2 (SDA) with any other sensors, runs from 3V3, and never touches the ESP8266’s single analog pin.
Wiring
| NodeMCU ESP8266 | INA219 DC current/voltage sensor | Wire | Notes |
|---|---|---|---|
| — | VIN+ | — | To Load supply + (up to 26 V) (not drawn) |
| — | VIN- | — | To Load + (fan, LED strip, battery being charged) (not drawn) |
| — | GND | — | To Load supply − (common ground) (not drawn) |
| 3V3 | VCC | red | The module’s I2C pull-ups go to VCC, so 3V3 keeps SDA/SCL at 3.3 V. |
| GND | GND | black | Also the common ground with the load supply — without it the bus voltage reads wrong. |
| D1 | SCL | yellow | D1 is GPIO5, the default SCL. |
| D2 | SDA | blue | D2 is GPIO4, the default SDA. |
3.0–5.5 V part, 3.3 V board. Power VCC from your board's logic voltage (3.3 V or 5 V); the I2C pull-ups go to VCC, so they match your board.
Board quirks
- The INA219 measures the voltage across its 0.1 Ω shunt and the voltage on VIN− against GND. That second reading is why the load supply’s negative must join the NodeMCU GND.
- Why not use A0? The NodeMCU has a single 10-bit ADC limited to 0–3.3 V — it can’t read a 12 V line, let alone a few milliamps of current. The INA219 does both over I2C and leaves A0 free.
- VIN+ is rated to 26 V. A 12 V battery, solar panel or 24 V adapter is fine; anything mains-connected is not.
- With the default 0.1 Ω shunt the library’s
setCalibration_32V_2A()reads up to about ±3.2 A in 0.8 mA steps. For small loads (under 400 mA) usesetCalibration_16V_400mA()for finer steps. - I2C sits on D1/D2 with the other sensors; D3, D4 and D8 stay free so nothing upsets the boot pins. Up to four INA219s fit on one bus using the A0/A1 address pads (0x40, 0x41, 0x44, 0x45).
Code
// INA219 current / voltage / power monitor on a NodeMCU (ESP8266).
// VCC → 3V3, GND → GND, SCL → D1 (GPIO5), SDA → D2 (GPIO4).
// The load's positive line goes through VIN+ → VIN−; the load supply's GND joins the NodeMCU GND.
#include <Wire.h>
#include <Adafruit_INA219.h>
Adafruit_INA219 ina219(0x40);
void setup() {
Serial.begin(115200);
Serial.println();
Wire.begin(); // SDA = D2 (GPIO4), SCL = D1 (GPIO5)
if (!ina219.begin(&Wire)) {
Serial.println("INA219 not found at 0x40 - check SDA/SCL and the A0/A1 address pads");
while (true) delay(1000); // delay() keeps the ESP8266 watchdog fed
}
ina219.setCalibration_32V_2A(); // 0.1 ohm shunt: up to 26 V on VIN+, about ±3.2 A
Serial.println("INA219 ready at 0x40");
}
void loop() {
float busV = ina219.getBusVoltage_V();
float shuntmV = ina219.getShuntVoltage_mV();
float mA = ina219.getCurrent_mA();
float mW = ina219.getPower_mW();
Serial.printf("Load %.2f V Current %.1f mA Power %.0f mW (shunt %.2f mV)\n", busV, mA, mW, shuntmV);
delay(1000);
}// INA219 current / voltage / power monitor on a NodeMCU (ESP8266).
// VCC → 3V3, GND → GND, SCL → D1 (GPIO5), SDA → D2 (GPIO4).
// The load's positive line goes through VIN+ → VIN−; the load supply's GND joins the NodeMCU GND.
#include <Wire.h>
#include <Adafruit_INA219.h>
Adafruit_INA219 ina219(0x40);
void setup() {
Serial.begin(115200);
Serial.println();
Wire.begin(); // SDA = D2 (GPIO4), SCL = D1 (GPIO5)
if (!ina219.begin(&Wire)) {
Serial.println("INA219 not found at 0x40 - check SDA/SCL and the A0/A1 address pads");
while (true) delay(1000); // delay() keeps the ESP8266 watchdog fed
}
ina219.setCalibration_32V_2A(); // 0.1 ohm shunt: up to 26 V on VIN+, about ±3.2 A
Serial.println("INA219 ready at 0x40");
}
void loop() {
float busV = ina219.getBusVoltage_V();
float shuntmV = ina219.getShuntVoltage_mV();
float mA = ina219.getCurrent_mA();
float mW = ina219.getPower_mW();
Serial.printf("Load %.2f V Current %.1f mA Power %.0f mW (shunt %.2f mV)\n", busV, mA, mW, shuntmV);
delay(1000);
}Library: Adafruit INA219 (Adafruit) — compiled with Adafruit INA219 1.2.3.
Expected serial output
INA219 ready at 0x40
Load 12.08 V Current 312.4 mA Power 3776 mW (shunt 31.24 mV)
Load 12.07 V Current 314.0 mA Power 3790 mW (shunt 31.40 mV)INA219 ready at 0x40 Load 12.08 V Current 312.4 mA Power 3776 mW (shunt 31.24 mV) Load 12.07 V Current 314.0 mA Power 3790 mW (shunt 31.40 mV)
Common errors
“INA219 not found at 0x40”
SDA/SCL swapped (SDA is D2) or an address pad bridged. Run the I2C scanner.
Current reads but voltage is 0 or nonsense
The load supply’s negative isn’t connected to GND. Join it to the NodeMCU GND.
Current is negative
VIN+ and VIN− are swapped. VIN+ goes to the supply, VIN− to the load.