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 current and power monitor with ESP32 — wiring and code

Measure DC voltage, current and power of a load with an INA219 on an ESP32 DevKit V1 (I2C on GPIO21/22) using the Adafruit INA219 library.

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

Community draft — report a mistake

The INA219 measures the voltage across a tiny shunt resistor and the bus voltage, and reports current and power over I2C — ideal for solar, battery and router-power monitors.

The I2C side is four wires to the ESP32 at 3.3 V. The measurement side goes in series with the positive line of the DC circuit you want to watch. The sketch prints load voltage, current and power every second.

Wiring

ESP32 DevKit V1Only the pins used are shown · 3.3 V logicINA219 DC current/voltage sensorGNDD22D213V3VCCGNDSCLSDAVIN+ (not connected)VIN- (not connected)
Also needed: The DC load to measure, wired through VIN+ → VIN− (high side, up to 26 V).
Every connection
ESP32 DevKit V1INA219 DC current/voltage sensorWireNotes
3V3VCCred
GNDGNDblack
D22SCLyellow
D21SDAblue

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

  • VIN+ and VIN− go in series with the positive wire of the circuit you measure (supply + → VIN+, VIN− → load +). The load’s ground must be joined to the ESP32 GND.
  • The default 0.1 Ω shunt measures up to about ±3.2 A; the sketch uses the 32 V / 2 A calibration for 0.8 mA resolution.
  • DC only, 26 V maximum on VIN+/VIN− — never mains.

Code

ina219-esp32.inoArduino C++Open in PlaygroundOpen in PlaygroundFlash
// INA219 current / voltage / power monitor on an ESP32 DevKit V1.
// VCC → 3V3, GND → GND, SDA → D21, SCL → D22. Put the load's positive line through VIN+ → VIN−.
#include <Wire.h>
#include <Adafruit_INA219.h>

Adafruit_INA219 ina219(0x40);

void setup() {
  Serial.begin(115200);
  Wire.begin(21, 22);  // SDA, SCL
  if (!ina219.begin(&Wire)) {
    Serial.println("INA219 not found at 0x40 — check wiring and the A0/A1 address jumpers");
    while (true) delay(1000);
  }
  ina219.setCalibration_32V_2A();  // default 0.1 Ω shunt: up to 32 V, ±3.2 A, 0.8 mA steps
  Serial.println("INA219 ready");
}

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  Shunt %.2f mV  Current %.1f mA  Power %.0f mW\n", busV + shuntmV / 1000.0F, shuntmV, mA, mW);
  delay(1000);
}

Library: Adafruit INA219 (Adafruit) — compiled with Adafruit INA219 1.2.3.

Expected serial output

Serial Monitor · 115200Output
INA219 ready
Load 12.03 V  Shunt 18.40 mV  Current 184.0 mA  Power 2214 mW
Load 12.03 V  Shunt 18.30 mV  Current 183.0 mA  Power 2202 mW

Common errors

Current always 0 mA

VIN+/VIN− are not in series with the load, or the load ground is not shared with the ESP32.

Negative current

VIN+ and VIN− are swapped — supply goes to VIN+.

↑↓ to move · Enter to open