Back to Tutorial

INA219 Current Sensor with ESP32 – Measure Voltage, Current, and Power

If you are building an IoT power monitoring project, battery system, or power bank device, measuring current, voltage, and power accurately is very important. The INA219 Current Sensor Module is one of the best sensors for this purpose. In this project, we will focus on using the INA219 with ESP32.

In this guide, you will learn how to interface the INA219 current sensor with ESP32, measure voltage and current, understand the circuit diagram, and run the complete Arduino code. This tutorial is perfect for electronics beginners, IoT developers, and embedded system engineers. The integration of INA219 with ESP32 provides excellent performance.


Table of Contents

  1. What is INA219 Current Sensor
  2. Features of INA219 Module
  3. Components Required
  4. INA219 Pinout
  5. ESP32 and INA219 Circuit Diagram
  6. Wiring Connection
  7. Installing Required Library
  8. Arduino Code for ESP32 INA219
  9. Output in Serial Monitor
  10. Advantages of INA219
  11. Disadvantages of INA219
  12. Precautions While Using INA219
  13. Applications of INA219
  14. Conclusion

What is INA219 Current Sensor

The INA219 is a high-side current sensor IC developed by Texas Instruments. It measures current, voltage, and power digitally using I2C communication.

Unlike traditional current sensors, INA219 allows measurement without interrupting the ground line, making it perfect for battery-powered and embedded systems.

The module can measure:

  • Bus Voltage
  • Shunt Voltage
  • Current
  • Power

This makes it very useful for power monitoring systems, battery management, and IoT devices.


Features of INA219 Module

Some important features of the INA219 module include:

  • High-side current sensing
  • I2C communication interface
  • Measures voltage up to 32V
  • Current measurement up to 3.2A
  • Built-in ADC for digital output
  • High accuracy measurements
  • Compatible with Arduino, ESP32, ESP8266, Raspberry Pi

Components Required

To build this project you need the following components:

  • ESP32 Development Board
  • INA219 Current Sensor Module
  • Jumper Wires
  • Power Source / Battery
  • Load (LED, motor, etc.)

INA219 Pinout

The INA219 module has the following pins:

PinFunction
VCCPower supply (3.3V – 5V)
GNDGround
SDAI2C Data
SCLI2C Clock
VIN+Input Voltage Positive
VIN-Output to Load


ESP32 and INA219 Circuit Diagram

I2C Wiring

INA219ESP32
VCC3.3V
GNDGND
SDAGPIO21
SCLGPIO22

Using INA219 with ESP32 for Accurate Power Monitoring

Power Source +  → VIN+
VIN-            → Load +
Load -          → Ground

The sensor measures the current flowing through the shunt resistor between VIN+ and VIN-.


Installing Required Library

Before uploading the code, install the library:

  1. Open Arduino IDE
  2. Go to Library Manager
  3. Search for Adafruit INA219
  4. Install the library

Library name:

Adafruit INA219

HOW TO CONNECT


ESP32 INA219 Arduino Code

Below is the complete code to measure voltage, current, and power using INA219 with ESP32.

#include <Wire.h>
#include <Adafruit_INA219.h>

Adafruit_INA219 ina219;

void setup(void) 
{
  Serial.begin(115200);
  while (!Serial) {
      delay(1);
  }
    
  Serial.println("Hello!");
  
  if (! ina219.begin()) {
    Serial.println("Failed to find INA219 chip");
    while (1) { delay(10); }
  }

  ina219.setCalibration_16V_400mA();

  Serial.println("Measuring voltage and current with INA219 ...");
}

void loop(void) 
{
  float shuntvoltage = 0;
  float busvoltage = 0;
  float current_mA = 0;
  float loadvoltage = 0;
  float power_mW = 0;

  shuntvoltage = ina219.getShuntVoltage_mV();
  busvoltage = ina219.getBusVoltage_V();
  current_mA = ina219.getCurrent_mA();
  power_mW = ina219.getPower_mW();
  loadvoltage = busvoltage + (shuntvoltage / 1000);
  
  Serial.print("Bus Voltage:   "); Serial.print(busvoltage); Serial.println(" V");
  Serial.print("Shunt Voltage: "); Serial.print(shuntvoltage); Serial.println(" mV");
  Serial.print("Load Voltage:  "); Serial.print(loadvoltage); Serial.println(" V");
  Serial.print("Current:       "); Serial.print(current_mA); Serial.println(" mA");
  Serial.print("Power:         "); Serial.print(power_mW); Serial.println(" mW");
  Serial.println("");

  delay(2000);
}

Serial Monitor Output

After uploading the code, open Serial Monitor (115200 baud).

Example output:

Bus Voltage: 5.02 V
Shunt Voltage: 10.45 mV
Load Voltage: 5.03 V
Current: 215.30 mA
Power: 1080.00 mW

This shows the real-time voltage, current, and power consumption of the connected load.


Advantages of INA219

  1. High accuracy current measurement
  2. Measures voltage, current, and power simultaneously
  3. Digital output via I2C communication
  4. Works with both 3.3V and 5V microcontrollers
  5. Ideal for battery monitoring and IoT projects

Disadvantages of INA219

  1. Limited current range compared to industrial sensors
  2. Requires I2C communication setup
  3. Slight voltage drop across shunt resistor
  4. Not suitable for very high current applications

Precautions While Using INA219

To ensure accurate and safe operation:

  • Always connect VIN+ and VIN- correctly
  • Do not exceed the maximum current rating
  • Use proper wiring to avoid loose connections
  • Ensure correct I2C pins for ESP32
  • Avoid measuring high current loads beyond module limits

Applications of INA219

The INA219 sensor is widely used in many projects such as:

  • Battery monitoring systems
  • Power bank current monitoring
  • Solar energy systems
  • IoT energy monitoring
  • Smart power meters
  • Embedded system power analysis

Conclusion

The INA219 current sensor with ESP32 provides an easy and reliable way to measure voltage, current, and power digitally. With its I2C communication and high accuracy, it is perfect for IoT, battery monitoring, and smart energy projects.

By following this guide, you can quickly build a real-time power monitoring system using ESP32 and INA219.

This sensor is especially useful for developers building power bank devices, battery management systems, or energy monitoring solutions.


Share this post

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Back to Tutorial