Home

Awesome

Erriez INA219 I2C/SMB Voltage/Current/Power Monitor library for Arduino

Build Status

This is an INA219 I2C/SMB DC Voltage/Current/Power sensor library for Arduino.

INA219

Library features

Hardware

Any Arduino hardware with a TWI interface and Wire.h support.

Pins board - INA219VCCGNDSDASCL
Arduino UNO (ATMega328 boards)5VGNDA4A5
Arduino Mega25605VGNDD20D21
Arduino Leonardo5VGNDD2D3
Arduino DUE (ATSAM3X8E)3V3GND2021
ESP82663V3GNDGPIO4 (D2)GPIO5 (D1)
ESP323V3GNDGPIO21GPIO22

Examples

Documentation

Library dependencies

Getting started

#include <Arduino.h>
#include <Wire.h>

#include <ErriezINA219.h>

// Default I2C Address 0x40
#define INA219_I2C_ADDRESS      0x40

// 0.1 Ohm shunt resistor
#define INA219_SHUNT_RESISTOR   0.1

// Create INA219 sensor object
INA219 ina219 = INA219(INA219_I2C_ADDRESS, INA219_SHUNT_RESISTOR);


void setup()
{
    // Initialize serial port
    Serial.begin(115200);
    while (!Serial) {
        ;
    }
    Serial.println(F("\nErriez INA219 voltage, current and power sensor example\n"));

    // Initialize I2C
    Wire.begin();
    Wire.setClock(400000);

    // Initialize INA219
    while (!ina219.begin()) {
        Serial.println(F("Error: INA219 not detected"));
        delay(3000);
    }
}

void loop()
{
    // Read from sensor
    if (!ina219.read()) {
        Serial.println(F("Error: INA219 read failed"));
        return;
    }

    // Check valid conversion
    if (!ina219.available) {
        Serial.println(F("Error: INA219 not available"));
        return;
    }

    // Print result
    Serial.println(F("INA219:"));

    Serial.print(F("  Bus voltage:   "));
    Serial.print(ina219.busVoltage, 2);
    Serial.println(F(" V"));

    Serial.print(F("  Shunt voltage: "));
    Serial.print(ina219.shuntVoltage / 1000, 1);
    Serial.println(F(" V"));

    Serial.print(F("  Current:       "));
    Serial.print(ina219.current / 1000, 1);
    Serial.println(F(" A"));

    Serial.print(F("  Power:         "));
    Serial.print(ina219.power / 1000, 1);
    Serial.println(F(" W"));

    // Wait some time
    delay(1000);
}

Library installation

Please refer to the Wiki page.

Other Arduino Libraries and Sketches from Erriez