# INA226 - Power monitor

The INA226 is a current shunt and power monitor build into the Aquastorm Hardware Interface. It can be used to monitor various parameter related to power, like

  • Shunt Voltage
  • Bus Voltage
  • Load Voltage
  • Current
  • Bus Power

# How to use the sensor?

To use it in Arduino, we can use a library made by Wolfgang (Wolle) Ewald called INA226_WE.

  1. First, you need to install the INA226_WE library on your Arduino IDE. You can do this by going to Sketch > Include Library > Manage Libraries and searching for INA226_WE. Then, select the latest version and click Install.

  2. Now, you are ready to write some code to use the sensor. You can start by including the library and creating an object for the sensor:

#include <INA226_WE.h> // include the library
#define I2C_ADDRESS 0x4F // define the I2C address of the sensor
INA226_WE ina226(I2C_ADDRESS); // create an object for the sensor
  1. Next, you need to initialize the sensor and set some parameters in the setup() function. You can use the following code as an example:
void setup(){
    Serial.begin(115200); // Start serial communication

    Wire.begin(14,13); // Start I2C communication GPIO14(SDA) and GPIO13(SCL)

    if(!ina226.init()){ // Initialize INA226
        Serial.println("Failed to init INA226. Check your wiring.");
        while(1){}
    }

    ina226.waitUntilConversionCompleted(); //if you comment this line the first data might be zero
}
  1. Finally, you need to read and display the sensor values in the loop() function. You can use the following code as an example:
void loop(){
    // Create value variables
    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; 

    // Get sensor values
    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);


    // Print Values
    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);


    // Check current range overflow
    if(!ina226.overflow){
        Serial.println("Values OK - no overflow");
    }
    else{
        Serial.println("Overflow! Choose higher current range");
    }
    Serial.println();

    delay(3000); // Wait 3 seconds
}

After this you should see an output like this:

Shunt Voltage [mV]: 0.40
Bus Voltage [V]: 11.92
Load Voltage [V]: 11.92
Current[mA]: 3.96
Bus Power [mW]: 0.00
Values OK - no overflow

Shunt Voltage [mV]: 0.37
Bus Voltage [V]: 11.95
Load Voltage [V]: 11.95
Current[mA]: 3.72
Bus Power [mW]: 46.00
Values OK - no overflow

# More Examples

Inside the excelent library of Wolfgang (Wolle) Ewald there are alot of examples on how to do more things with the INA226. Please check those here.