ESP32 INA226 Power Monitor – Measure Voltage, Current and Power

Turn your ESP32 and INA226 sensor into a digital power monitoring system! The SensorLab INA226 Power Monitor measures voltage, current, and electrical power in real time via USB. Explore live measurements using graphical instruments and interactive charts, investigate Ohm’s law, and record voltage-current pairs to determine electrical resistance. Export your measurement data as CSV files for further analysis in Excel, Numbers, or other spreadsheet applications.

Ideal for hands-on physics experiments in electricity and electronics.

ina 226 sensor to ESP32

Browser Compatibility

To use the SensorLab Weather Station with an ESP32 via USB, please use Google Chrome or Microsoft Edge. SensorLab uses the Web Serial API for direct communication with the ESP32, which is not supported by all web browsers.

Your Power Dashboard

▣
SENSORLAB
INA226 Power Monitor
Live--:--:--?
Voltage
Current
Voltage
--V
Min: --Max: --
Current
--mA
Min: --Max: --
Power
--W
Min: --Max: --
Live Chart
Ohm's Law Data: Voltage vs Current
# Voltage V Current A Current mA
Add voltage-current pairs to estimate resistance from the slope: R = U / I.
SensorLab.world – Measure. Export. Analyse.

ESP32 Firmware – Arduino IDE for INA226

The following Arduino code configures the ESP32 to communicate with the INA226 sensor and transmit voltage, current, and power measurements to the SensorLab dashboard via USB.

Important: Check the shunt resistor value!

The INA226 measures current by detecting the small voltage drop across a shunt resistor. Its resistance must be specified correctly in the firmware to obtain accurate current readings.

Our INA226 module uses a resistor marked R002, corresponding to 0.002 Ω (2 mΩ). Other modules may use different values, such as R100 (0.1 Ω).

Check the marking on your module and adjust the following line in the Arduino code if necessary:

const float SHUNT_OHMS = 0.002;

An incorrect shunt resistance value will result in incorrect current and power measurements, even if the voltage readings are correct.

/*
SensorLab INA226 USB Firmware for ESP32

 

Output format via USB Serial at 115200 baud:
time_ms,voltage_V,current_A,power_W

 

Wiring INA226 -> ESP32:
VCC/VIN -> 3V3
GND -> GND
SDA -> GPIO21
SCL -> GPIO22

 

Measurement side:
Place the INA226 shunt in series with the load.
The common breakout-board shunt is often marked R100 = 0.1 ohm.
*/

 

#include <Wire.h>

 

const uint8_t INA226_ADDR = 0x40;
const int I2C_SDA = 21;
const int I2C_SCL = 22;
const float SHUNT_OHMS = 0.002; // R002 = 0.002 ohm
const unsigned long INTERVAL_MS = 300;

 

uint16_t readRegister16(uint8_t reg) {
Wire.beginTransmission(INA226_ADDR);
Wire.write(reg);
Wire.endTransmission(false);
Wire.requestFrom(INA226_ADDR, (uint8_t)2);
uint16_t value = 0;
if (Wire.available() >= 2) {
value = ((uint16_t)Wire.read() << 8) | Wire.read();
}
return value;
}

 

void writeRegister16(uint8_t reg, uint16_t value) {
Wire.beginTransmission(INA226_ADDR);
Wire.write(reg);
Wire.write((value >> 8) & 0xFF);
Wire.write(value & 0xFF);
Wire.endTransmission();
}

 

bool ina226Found() {
Wire.beginTransmission(INA226_ADDR);
return Wire.endTransmission() == 0;
}

 

void setup() {
Serial.begin(115200);
delay(1000);
Wire.begin(I2C_SDA, I2C_SCL);
delay(200);

 

if (!ina226Found()) {
Serial.println("INA226 not found");
Serial.println("Check VCC=3V3, GND, SDA=21, SCL=22 and address 0x40");
while (true) delay(1000);
}

 

// Average 16 samples, 1.1 ms conversion times, continuous shunt + bus.
writeRegister16(0x00, 0x4527);
Serial.println("SensorLab INA226 ready");
}

 

void loop() {
static unsigned long last = 0;
if (millis() - last < INTERVAL_MS) return;
last = millis();

 

// Bus voltage register: LSB = 1.25 mV
uint16_t busRaw = readRegister16(0x02);
float voltage_V = busRaw * 0.00125;

 

// Shunt voltage register: signed, LSB = 2.5 µV
int16_t shuntRaw = (int16_t)readRegister16(0x01);
float shuntVoltage_V = shuntRaw * 0.0000025;
float current_A = shuntVoltage_V / SHUNT_OHMS;
float power_W = voltage_V * current_A;

 

Serial.print(millis());
Serial.print(",");
Serial.print(voltage_V, 4);
Serial.print(",");
Serial.print(current_A, 6);
Serial.print(",");
Serial.println(power_W, 6);
}