Overview
In this tutorial, we will learn how to interface the INA226 DC Current Sensor Module with an Arduino. The INA226, like its predecessor the INA219, is a device that can measure current, voltage, and power. However, it has an extended range, capable of measuring voltages up to 36V and current up to 20A. Thus you can make DC Energy Meter project using this sensor or a 12V Battery Monitoring System project and also the Solar Panel Monitoring System project.
The INA226 is a shunt and bus voltage monitor introduced by Texas Instruments. It offers an integrated, zero-drift, bi-directional interface that monitors shunt voltage, bus voltage, current, and power. The INA226 communicates with microcontrollers through an I2C interface, allowing for easy data transfer and interpretation.
One of the unique features of the INA226 is its configurable averaging and conversion times for both the shunt voltage and bus voltage measurements. This provides a means to optimize the device for various applications and system requirements. Furthermore, it also includes a programmable threshold and alert functionality for these measurements which can be used for system-level optimizations such as power saving and event-driven interrupt programming.
The INA226 Current Sensor Module is versatile, finding its utility in server power management, telecommunications, power supply equipment, and battery management systems. Essentially, any system requiring high-accuracy, cost-effective power and current monitoring can significantly benefit from this module.
Bill of Materials
To interface INA226 DC Current Sensor Module with Arduino, we need following components. You can purchase all of them from the given links:
| S.N. | Components | Quantity | Purchase Link |
|---|---|---|---|
| 1 | Arduino Nano | 1 | Amazon | AliExpress | SunFounder |
| 2 | INA226 Current Sensor | 1 | Amazon | AliExpress |
| 3 | Battery 3.7V | 1 | Amazon | AliExpress |
| 4 | DC Motor | 1 | Amazon | AliExpress | SunFounder |
| 5 | Jumper Wires | 10 | Amazon | AliExpress | SunFounder |
| 6 | Breadboard | 1 | Amazon | AliExpress | SunFounder |
INA226 DC Current Sensor Module
The INA226 is an advanced, high-side current shunt and power monitor IC developed by Texas Instruments. It operates over an I2C-compatible or SMBus-compatible interface, offering direct digital communication with a microcontroller. It provides more extensive capabilities than the INA219, including better accuracy, more extensive voltage and current range, as well as integrated math functions that directly report power in watts.
Download INA226 Datasheet: INA226 Datasheet
INA226 Board Circuit & Schematic
The INA226 module is built with an INA226 chip, a few resistors, and a capacitor that helps reduce noise, or unwanted electrical signals.
Features & Specifications of INA226
- Operational Voltage (2.7 – 5.5 Volts): The INA226 operates between 2.7 to 5.5 volts. This widens its compatibility with systems that run at different voltage levels. This trait is beneficial in accommodating an extensive range of circuit designs.
- Bus Voltage Range (0 – 36 Volts): The INA226 can monitor power supplies up to 36 volts, expanding the device’s applicability to various power supplies.
- Current Sensing Range (± 500mA to ± 50A): Depending on the value of the shunt resistor, INA226 can monitor a wide range of currents, thus catering to a myriad of applications including power management, battery chargers, and DC motor control.
- Power consumption: Continuous mode: 0.35 mA; Power-Down Mode: 2.3.µA
- Measurement modes:: continuous or on-demand (“triggered”)
- Averaging of 1, 4, 64, 128, 256, 512 or 1024 individual measurements
- A/D conversion time adjustable in eight levels: 0.14 to 8.2 ms
- Higher Precision: The INA226 provides increased precision through its 16-bit ADC, resulting in more accurate measurements.
- Programmable alarm pin for limit violations and available data
Pinout of INA226
The INA226 sensor module typically has 8 pins, which are as follows:
- VCC: It accepts an input voltage from 2.7V to 5.5V.
- GND: Ground pin, connected to the ground of the power supply.
- SDA: Serial Data line for the I2C interface. It’s used for the bidirectional transfer of data.
- SCL: Serial Clock line for the I2C interface. It’s used for synchronization during data transfer.
- ALE: This is the Alert pin. It’s an open-drain output that requires a pull-up resistor. This pin can be used for various alerts or as a conversion-ready signal.
- VBUS: This pin is used to measure the supply voltage. It can measure the supply voltage up to 36V.
- IN-: This pin connects to the Load. This is where the shunt resistor is placed for current sensing.
- IN+: This pin connects to the Power Source.
Current Sensing Resistor Selection
The maximum current that the INA226 can measure is not determined directly by the chip itself, but rather by the value of the shunt resistor used in conjunction with it.
The INA226 measures the voltage drop across a shunt resistor, and from that calculates the current using Ohm’s law (I = V/R). Since the INA226 can measure a maximum shunt voltage of 81.92mV (with a resolution of 2.5µV), the maximum current is dependent on the resistance of the shunt.
Below is a table of suggested shunts.
| Shunt Resistance | Max Current (A) | Part Size | Part Number | Power Rating (W) | Max Power (W) |
| 0.003 | 27.31 | 2512 | ERJMS4SF3M0U | 3 | 2.24 |
| 0.004 | 20.48 | 2512 | ERJMS4SF4M0U | 3 | 1.68 |
| 0.005 | 16.38 | 2512 | ERJMS4HF5M0U | 3 | 1.34 |
| 0.006 | 13.65 | 2512 | ERJMS4HF6M0U | 3 | 1.12 |
| 0.007 | 11.70 | 2512 | ERJMS4HF7M0U | 2 | 0.96 |
| 0.008 | 10.24 | 2512 | ERJMS4HF8M0U | 2 | 0.84 |
| 0.009 | 9.10 | 2512 | ERJMS4HF9M0U | 2 | 0.75 |
| 0.010 | 8.19 | 2512 | ERJMS4HF10MU | 2 | 0.67 |
ADC Resolution
The bus voltage register of the INA226, a 16-bit signed entity, features a least significant bit (LSB), or resolution, of 1.25mV. This permits a full-scale voltage measurement range of +/-40.96V.
The INA226’s analog input designed for the shunt resistor is capable of accepting a maximum (full scale) voltage of 81.92mV. When paired with a shunt resistor of 4mOhm, it enables the measurement of a current up to +/-20.48A with a resolution as precise as 625µA.
I2C Address
Similar to INA219, the INA226 uses the I2C protocol to communicate with microcontrollers. The default I2C address for the INA226 is 0x40. This address can be changed to facilitate the use of multiple INA226 sensors on the same I2C bus. The INA226 allows up to 16 different I2C addresses, from 0x40 to 0x4F. You can change the I2C address by modifying the connections of the A0 and A1 pins.
Register Address & Values Calculations
The INA226 also has internal registers which are accessed via the I2C interface. Some of the essential ones are:
- Configuration Register (Address = 00h): Similar to INA219, this register is used to control various aspects of the INA226.
- Shunt Voltage Register (Address = 01h): This register holds the raw measurement for the shunt voltage.
Shunt Voltage (V) = Shunt Voltage Register Value * 2.5 µV - Bus Voltage Register (Address = 02h): This register holds the raw measurement for the bus voltage.
Bus Voltage (V) = Bus Voltage Register Value * 1.25 mV - Power Register (Address = 03h): This register holds the calculated power value.
Power (W) = Power Register Value * Power_LSB - Current Register (Address = 04h): This register holds the calculated current value.
Current (A) = Current Register Value * Current_LSB - Calibration Register (Address = 05h): This register is used to set the calibration value for the current and power calculations.
How to use INA226 DC Current Sensor with Arduino
Now let us interface the INA226 DC Current Sensor Module with Arduino. The hardware interfacing is very simple.
Here is a simple connection diagram that can be used to interface INA226 Current sensor with Arduino along with external load and power source.
Connect the VCC, GND, SCL & SDA pin of INA219 to 5V, GND, A5 & A4 of Arduino respectively. The Vin+ pin should be connected to power source and the Vin- to the load as shown in the image above. The INA226 Sensor has VBus Pin, which is used to measure the source Voltage. Connect the VBus pin to Vin- pin.
For test, I used 3.7V and 9V Battery as a Power Source. As a load, I used a DC Motor for this circuit.
The Vin+ pin can accept input voltage upto 36V. The device is rated to 36V (40V absolute maximum) on the input pins. Therefore, do not supply anything above 36V.
You may need to desolder the shunt resistor and replace it with above mentioned resistor in case, you want to measure higher current.
INA226 Arduino Library
There are many versions of INA226 library available for use. I tested most of them. I found the library from Wollewald as accurate one.
You can download the library from GitHub or install it directly with the Library Manager of the Arduino IDE.
There is a total of seven example sketches used to present the functions of the library. I have used the example of continuous mode. Many of the functions are used in all sketches and therefore only need to be explained once.
Source Code/Program
Copy the following code and paste it on your Arduino IDE editor window. Before you upload the code, you may need to make some modifications.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
#include <Wire.h> #include <INA226_WE.h> #define I2C_ADDRESS 0x40 INA226_WE ina226 = INA226_WE(I2C_ADDRESS); void setup() { Serial.begin(9600); while (!Serial); // wait until serial comes up on Arduino Leonardo or MKR WiFi 1010 Wire.begin(); ina226.init(); /* Set Number of measurements for shunt and bus voltage which shall be averaged Mode * * Number of samples AVERAGE_1 1 (default) AVERAGE_4 4 AVERAGE_16 16 AVERAGE_64 64 AVERAGE_128 128 AVERAGE_256 256 AVERAGE_512 512 AVERAGE_1024 1024*/ //ina226.setAverage(AVERAGE_16); // choose mode and uncomment for change of default /* Set conversion time in microseconds One set of shunt and bus voltage conversion will take: number of samples to be averaged x conversion time x 2 Mode * * conversion time CONV_TIME_140 140 µs CONV_TIME_204 204 µs CONV_TIME_332 332 µs CONV_TIME_588 588 µs CONV_TIME_1100 1.1 ms (default) CONV_TIME_2116 2.116 ms CONV_TIME_4156 4.156 ms CONV_TIME_8244 8.244 ms */ //ina226.setConversionTime(CONV_TIME_1100); //choose conversion time and uncomment for change of default /* Set measure mode POWER_DOWN - INA226 switched off TRIGGERED - measurement on demand CONTINUOUS - continuous measurements (default)*/ //ina226.setMeasureMode(CONTINUOUS); // choose mode and uncomment for change of default /* Set Resistor and Current Range if resistor is 5.0 mOhm, current range is up to 10.0 A default is 100 mOhm and about 1.3 A*/ ina226.setResistorRange(0.1, 1.3); // choose resistor 0.1 Ohm and gain range up to 1.3A /* If the current values delivered by the INA226 differ by a constant factor from values obtained with calibrated equipment you can define a correction factor. Correction factor = current delivered from calibrated equipment / current delivered by INA226*/ ina226.setCorrectionFactor(0.93); Serial.println("INA226 Current Sensor Example Sketch - Continuous"); ina226.waitUntilConversionCompleted(); //if you comment this line the first data might be zero } void loop() { float shuntVoltage_mV = 0.0; float loadVoltage_V = 0.0; float busVoltage_V = 0.0; float current_mA = 0.0; float power_mW = 0.0; ina226.readAndClearFlags(); shuntVoltage_mV = ina226.getShuntVoltage_mV(); busVoltage_V = ina226.getBusVoltage_V(); current_mA = ina226.getCurrent_mA(); power_mW = ina226.getBusPower(); loadVoltage_V = busVoltage_V + (shuntVoltage_mV / 1000); Serial.print("Shunt Voltage [mV]: "); Serial.println(shuntVoltage_mV); Serial.print("Bus Voltage [V]: "); Serial.println(busVoltage_V); Serial.print("Load Voltage [V]: "); Serial.println(loadVoltage_V); Serial.print("Current[mA]: "); Serial.println(current_mA); Serial.print("Bus Power [mW]: "); Serial.println(power_mW); if (!ina226.overflow) { Serial.println("Values OK - no overflow"); } else { Serial.println("Overflow! Choose higher current range"); } Serial.println(); delay(3000); } |
Code Modifications & Setup
From this code, you need make some modifications in order to get the result accurately.
|
1 |
ina226.setResistorRange(0.1, 1.3); |
This line set Resistor and Current Range. If resistor is 5.0 mOhm, current range is up to 10A. By deefault is 100 mOhm and about 1.3A.
|
1 |
ina226.setCorrectionFactor(0.93); |
If the current values delivered by the INA226 differ by a constant factor from values obtained with calibrated equipment you can define a correction factor.
You may connect a multimeter in Series with Vin- and measure the current and verify with the value in Serial Monitor.
Some of the other fucntionalities and setup required are as follows:
- Set the number of individual measurements for the shunt and bus voltage conversion with
setAverage()- 1, 4, 16, 64, 128, 256, 512, or 1024 individual measurements are averaged
- Set the A/D conversion time for the shunt and bus voltage with
setConvTime()- 8 levels adjustable between 140 µs and 8.244 ms
- Note: obtaining a data set of shunt and bus voltage takes twice the time
- Set the measurement mode with
setMeasureMode()- CONTINUOUS – continuous measurement
- TRIGGERED – “on request”: I explain in the next example.
- POWER_DOWN – turns off the INA226. But better use the more comfortable
powerDown()function, which is explained below. - The INA226 actually allows determining shunt or bus voltages – but I did not implement that. Using my library, the measurements are only available in a double pack.
- Set the current range with
setCurrentRange()- You can set 400 or 800 mA as the maximum current. The smaller the current range, the higher the resolution for the current and the power.
Test Results
After you upload the code to the Arduino board, you can start testing the setup.
First connect 3.7V Lithium-ion Battery to the Vin+ Pin and a DC motor to Vin- Pin. The DC motor will start rotating.
Now open the Serial Monitor and you will see the following results for 3.7V Source.
Remove the 3.7V Battery and connect the 9V Battery.
The same circuit when tested with 9V DC source gives following results.
Conclusion
In conclusion, the INA226 DC Current Sensor Module is a highly versatile and capable device, perfect for a wide variety of applications where precise power, current, and voltage monitoring is needed. It has an extended range compared to its predecessor, the INA219, enabling the measurement of up to 36V in voltage and 20A in current.
Interfacing this INA226 Current Sensor module with an Arduino allows us to leverage its advanced capabilities in a straightforward manner, making it an invaluable tool for those seeking high-accuracy and cost-effective monitoring solutions. Thus, by mastering the interfacing of the INA226 with an Arduino, we can significantly enhance our capacity to monitor and manage power within electronic systems.



















3 Comments
None of the links i can find are clear on what you are actually supposed to do to change the address? Are you supposed to shunt/short the a0 and/or a1 pads to one of the other pins as specified in the table or is this some kind of software configuration somehow?
The INA226 has address pins A0 and A1 to set the I2C address. To change the address:
The A0 and A1 pins can be connected to one of three voltage levels: GND, VS (supply voltage), or left floating (ADDR).
Depending on how these pins are connected, the I2C address of the INA226 will change. This is a hardware configuration, not software. You physically connect these pins to set the desired address as per the datasheet’s table.
To answer your question: Yes, you are supposed to connect the A0 and/or A1 pads to the specific pins (GND, VS, or left floating) to set the address as per the datasheet’s table.
Does anyone use DONGKER INA226 or INA228 modules?