INA219 with ESP32: DC Current, Voltage & Power
Connect the INA219 in series with a DC load, match the shunt calibration and read voltage, current and power over I2C.
On this page
Identify the shunt and terminalsPrepare a small DC testConnect I2C and the load pathInstall the INA219 driverRead voltage, current and powerValidate with one known loadTroubleshootingReferences and further readingRelated product
Measure the DC voltage, current and power of a small load with an INA219 breakout. The tutorial separates the low-voltage I2C connection from the load-current path so that the measurement circuit is clear.
Identify the shunt and terminals
Check that the board really uses INA219 and identify VCC, GND, SDA, SCL, VIN+ and VIN−. The large resistor in the measurement path is the shunt. This example uses the driver's standard calibration for a 0.1 Ω shunt, usually marked R100. If your resistor differs, use a calibration appropriate to that resistance instead of assuming the current reading is correct.
Prepare a small DC test
The example controller is an ESP32-C3 Supermini with free, exposed GPIO6 and GPIO7. First confirm that its serial/upload test works. Select ESP32C3 Dev Module and enable USB CDC On Boot for native USB. Open Serial Monitor at 115200 baud. Disconnect power before changing wires.
Start with a current-limited low-voltage supply and a modest known load. Keep the load within the breakout's resistor, connector and thermal ratings. The sensor's measured bus limit is 26 V; a library preset with “32V” in its name does not increase that hardware limit.
Connect I2C and the load path
| Module label | ESP32-C3 Supermini | Connection |
|---|---|---|
| VCC / VDD | 3V3 | 3.3 V for this example |
| GND | GND | Common ground |
| SDA | GPIO6 | I2C data |
| SCL | GPIO7 | I2C clock |
These are explicitly assigned GPIO numbers for this C3 example, not physical header positions or universal ESP32 defaults. For another controller, choose free pins from its own pinout and change Wire.begin() in the sketch. Keep the first test on short wires with one peripheral.
| Load-side connection | Destination |
|---|---|
| Supply positive | INA219 VIN+ |
| INA219 VIN− | Load positive |
| Load negative | Supply negative |
| Supply negative | Common INA219 / ESP32 GND |
Current flows through VIN+ → shunt → VIN− → load. VCC powers the measurement electronics; it is not the load-current input. Do not connect VIN+ and VIN− across a supply as though they were a voltage-meter pair: that would place the low-resistance shunt directly across it.
Install the INA219 driver
In Arduino Library Manager install Adafruit INA219 and Adafruit BusIO. Accept the listed dependencies. Create a new sketch, paste the complete example, click Verify, then Upload. Keep a record of your board profile and library versions when reporting an issue.
The starting address is 0x40. Address solder links can change it; inspect those links and use an I2C scan before changing the code. Verify common ground before applying load power.
Read voltage, current and power
The sketch reports bus voltage at VIN−, shunt voltage, current in mA and calculated power in mW. These units differ by factors of 1,000; label any saved data accordingly. Upload before switching the load on.
#include <Arduino.h>
#include <Wire.h>
#include <Adafruit_INA219.h>
Adafruit_INA219 powerMonitor(0x40);
void setup() {
Serial.begin(115200);
delay(1500);
Wire.begin(6, 7);
if (!powerMonitor.begin(&Wire)) {
Serial.println("INA219 not found.");
while (true) delay(1000);
}
// Only for the standard 0.1-ohm (R100) shunt.
powerMonitor.setCalibration_32V_2A();
}
void loop() {
const float busV = powerMonitor.getBusVoltage_V();
const float shuntMv = powerMonitor.getShuntVoltage_mV();
const float currentMa = powerMonitor.getCurrent_mA();
const float milliwatts = powerMonitor.getPower_mW();
if (!powerMonitor.success()) {
Serial.println("I2C read failed; check wiring.");
} else {
Serial.printf("VIN-: %.3f V | Shunt: %.3f mV | Current: %.2f mA | Power: %.2f mW\n",
busV, shuntMv, currentMa, milliwatts);
}
delay(1000);
}
Validate with one known load
- Switch the load off and note the near-zero current baseline.
- Switch on a modest load and confirm that current rises.
- Compare the load voltage and current against an independent meter or an expected resistor calculation.
- Check the shunt value and calibration if readings differ by a consistent scale factor.
Reversing the current path reverses the sign. Bus voltage is measured on the load side; adding the shunt drop estimates the supply-side voltage. The shunt adds a small voltage drop of its own, so place it deliberately in the power path you intend to characterize.
Troubleshooting
| Symptom | Check next |
|---|---|
| I2C not found | Check 3.3 V logic supply, common ground, bus wiring and address links. |
| Voltage shown but current near zero | Confirm the load actually draws current through both measurement terminals. |
| Current has the wrong sign | Check VIN+ and VIN− orientation. |
| Current consistently scaled incorrectly | Check the physical shunt resistance and matching calibration. |
| Unstable readings during switching | First reduce the test load and inspect supply noise, connection resistance and layout of the load-current loop. |
References and further reading
Related product
Share the product link, hardware revision, software version and any error messages.
Contact ESP32S support →