INA226 With Arduino (DC Current Sensor) | INA226 Library + Code

In this tutorial, you’ll learn how to interface an INA226 With Arduino (DC Current Sensor), install the Arduino INA226 library, and test some code examples to Measure DC Current with Arduino + INA226. Without further ado, let’s get right into it!

Table of Contents

  1. Arduino INA226 DC Current Sensor
  2. INA226 With Arduino (Interfacing)
  3. Arduino INA226 Library Installation
  4. Arduino INA226 DC Current Measurement Example
  5. More Arduino Current Sensors
  6. Wrap Up

Arduino INA226 DC Current Sensor

The INA226 DC current sensor is an excellent choice for Arduino projects that need precision (DC current, bus voltage, and power) measurements. The INA226 current sensor provides an I2C digital output that makes it so easy to measure the DC currents with multiple INA226 sensors using only 2 wires (up to 16 different addresses).

The INA226 sensor can also determine the polarity of the current (positive or negative) while measuring DC currents up to ±0.8A. It can also measure the bus voltage (0 up to 36v) and also do power calculations (P = I x V) in hardware. All of this and other features make the INA226 an ideal choice for a wide range of power monitoring applications.

INA226 Pinout Diagram

Below is the pinout diagram of the INA226 DC current sensor.

INA226 Pinout Diagram (DC Current Sensor)

Key Specifications of the INA226 DC Current Sensor:

  • 3-5v single supply operation
  • Up to ±0.8A DC current measurement
  • Supply voltage measurement from 0v up to 36v
  • Reports Current, Voltage, and Power (P = I x V)
  • Integrated 16 Bits ADC for precise measurements
  • High accuracy (0.1%) over the temperature range
  • I2C digital output with 16 programmable addresses

INA226 DC Current Sensor Working Principles

The INA226 sensor depends on an external shunt resistor connected to the high side or the low side of your load circuitry. The “to be measured” DC current goes through the shunt resistor which develops a voltage drop over the current-sensing shunt resistor. The differential voltage between the shunt’s terminals (Vin+ & Vin-) is then amplified and measured by the INA226 sensor.

The internal 16-bit ADC takes the measurement and converts the input differential voltage into current output. There is also hardware support for measuring and storing the bus voltage and calculating the power consumption (P = I x V). All these digital values are stored in internal registers and sent to the microcontroller (Arduino, ESP32, or whatever) over the I2C bus. The diagram below shows the internal structure of the INA226 sensor.

INA226 DC Current Sensor Working Principles & Shunt Resistor

The onboard shunt resistor that you’ll find on your INA226 sensor’s board is a 0.1Ω power resistor that’s used to sense the DC current going through your load. The sensor’s board has a couple of I2C pull-up resistors, so you don’t need to connect anything to the I2C lines.

Buy an INA226 Current Sensor: you can find it here on ( Amazon, AliExpress, eBay )


INA226 With Arduino (Interfacing)

Interfacing the INA226 current sensor with Arduino is so easy as it only requires two wires (I2C bus). We’ll use the INA226_WE library to handle the I2C communication with the INA226 sensor and read the measured current, voltage, and power.

Arduino INA226 Wiring (Connection)

This is a summary of the connections needed between your Arduino board and the INA226 current sensor.

INA226Arduino UNODescription
VCC5VPower supply
GNDGNDGround
SDAA4 (SDA)I2C SDA Line
SCLA5 (SCL)I2C SCL Line
ALED2 (Interrupt 0)Sensor’s Alarm Output (Interrupt Pin) “optional”

Arduino INA226 Library Installation

The library we’ll use in this tutorial is called INA226_WE, and this is how to install it on your system.

Step #1

Open your Arduino IDE > Tools > Manage Libraries > Search For “INA226_WE“.

Step #2

Install the INA226_WE library as shown below.

Arduino INA226 Library (DC Current Sensor) Code Example

And that’s all about it. Now we can use the library as we’ll do in the next example project.

❕ Note

The default I2C address for the INA226 current sensor is 0x40. However, you can modify this default address by soldering the A0 & A1 address control pins on the sensor’s board. The default states for the address control pins are (A0 = 0, and A1 = 0).

In case, you need to use multiple INA226 sensors, just modify the (A0 & A1) pin states, then set the I2C device address of your INA226 in the code according to the following settings:

  • 0x40: A0 = open & A1 = open
  • 0x41: A0 = closed & A1 = open
  • 0x44: A0 = open & A1 = closed
  • 0x45: A0 = closed & A1 = closed

Arduino INA226 DC Current Measurement Example

In this example project, we’ll measure DC current with Arduino + INA226 current sensor. The measured DC current will be displayed on an I2C LCD 16×2 display using the same two (I2C) pins of the Arduino board.

I’ll use a variable DC power supply and an 8Ω load to test the INA226 current sensor. Just make sure the load current is below the maximum allowed value of ±0.8A.

Arduino INA226 Wiring (DC Current Measurement)

Here is the wiring diagram for the Arduino DC current measurement setup I’ve used to test the INA226 sensor.

Arduino INA226 DC Current Sensor Wiring Diagram
The load can also be connected between the screw terminals instead of the connection shown above

Example Code

Here is the full code listing for this example.

The INA226 sensor initialization configurations are set in this line of code:

The getCurrent_mA() function is used to read the measured DC current in (mA) unit.

Testing Results

Here are the results of testing this project code example on my Arduino UNO board using a 6.5digit DMM.

The measurement error percentage is very low in all test cases as you’ve seen in the demo video. The INA226 current sensor has much higher accuracy compared to the INA219 current sensor.

Other Useful Functions in The INA226 Library

Here are some other useful functions that you can use from the INA226 library as well:

You can check the library examples and/or the source code by navigating to the following directory:

Arduino I2C LCD 16x2 Interfacing Tutorial & Library Examples

This tutorial will give you in-depth information about using I2C LCD 16×2 with Arduino boards, and how to install & use the LiquidCrystal_I2C library with multiple demo code examples to learn from. Check it out!


Required Parts List

Here is the full components list for all the parts you’d need to perform the practical LABs mentioned in this tutorial and the whole Arduino Programming series of tutorials found here on our website.

* Please, note that those are affiliate links and we’ll receive a small commission on your purchase at no additional cost to you, and it’d definitely support our work.

QTY.Component NameAmazon.comAliExpresseBay
1INA226 Current SensorAmazonAliExpresseBay
1Arduino UNO KitAmazonAliExpresseBay
1Complete Arduino Sensors/Modules KitAmazonAliExpresseBay
1DC Power SupplyAmazonAliExpresseBay
1BreadBoardAmazonAliExpresseBay
1LEDs KitAmazonAmazonAliExpresseBay
1Resistors KitAmazonAmazonAliExpresseBay
1Capacitors KitAmazonAmazonAliExpress & AliExpresseBay & eBay
1Jumper Wires PackAmazonAmazonAliExpress & AliExpresseBay & eBay
1Push ButtonsAmazonAmazonAliExpresseBay
1PotentiometersAmazonAliExpresseBay

★ Check The Links Below For The Full Course Kit List & LAB Test Equipment Required For Debugging ★

Download Tutorial’s Attachments

You can download all attachment files for this Article/Tutorial (project files, schematics, code, etc..) using the link below. Please consider supporting our work through the various support options listed in the link down below. Every small donation helps to keep this website up and running and ultimately supports the whole community.


More Arduino Current Sensors


Wrap Up

To conclude this tutorial, we’ve covered how to interface an INA226 DC Current Sensor with Arduino, and how to use this sensor to measure DC current, bus voltage, and power with your Arduino board. You can build on top of the provided example projects and use the INA226 current sensor with your Arduino boards.

If you’re just getting started with Arduino, you need to check out the Arduino Getting Started [Ultimate Guide] here.

And follow this Arduino Series of Tutorials to learn more about Arduino Programming.

References:

Share This Page With Your Network!
Join Our +25,000 Newsletter Subscribers!

Stay Updated With All New Content Releases. You Also Get Occasional FREE Coupon Codes For Courses & Other Stuff!

Photo of author
Author
Khaled Magdy
Embedded systems engineer with several years of experience in embedded software and hardware design. I work as an embedded SW engineer in the Automotive & e-Mobility industry. However, I still do Hardware design and SW development for DSP, Control Systems, Robotics, AI/ML, and other fields I'm passionate about.
I love reading, writing, creating projects, and teaching. A reader by day and a writer by night, it's my lifestyle. I believe that the combination of brilliant minds, bold ideas, and a complete disregard for what is possible, can and will change the world! I will be there when it happens, will you?

1 thought on “INA226 With Arduino (DC Current Sensor) | INA226 Library + Code”

  1. “Great tutorial on using the INA226 with Arduino! The detailed explanation of the library functions and the sample code makes it super easy to understand how to implement the DC current sensor. I’m excited to try this out in my next project! Thanks for sharing!”

    Reply

Leave a Comment