Preview build — page text is a draft awaiting human review. Code badges come from real compiles. The flasher is real but not yet hardware-tested; the Playground is still a preview.

INA219 with NodeMCU ESP8266 — current and power monitor

Measure voltage, current and power with an INA219 on a NodeMCU ESP8266: I2C on D1/D2 at 3.3 V, the load wired through VIN+ and VIN−.

Arduino C++Verified — core esp8266 3.1.2, Adafruit INA219 1.2.3, 3 Nov 2026Compile-only

Community draft — report a mistake

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 ESP8266Only the pins used are shown · 3.3 V logicINA219 DC current/voltage sensorGND3V3D1D2VCCGND → Load supply − (common ground)SCLSDAVIN+ → Load supply + (up to 26 V)VIN- → Load + (fan, LED strip, battery being charged)
Every connection
NodeMCU ESP8266INA219 DC current/voltage sensorWireNotes
—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)
3V3VCCredThe module’s I2C pull-ups go to VCC, so 3V3 keeps SDA/SCL at 3.3 V.
GNDGNDblackAlso the common ground with the load supply — without it the bus voltage reads wrong.
D1SCLyellowD1 is GPIO5, the default SCL.
D2SDAblueD2 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) use setCalibration_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-nodemcu.inoArduino C++Open in PlaygroundOpen in PlaygroundFlash
// 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

Serial Monitor · 115200Output
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.

↑↓ to move · Enter to open