0% found this document useful (0 votes)
134 views1 page

Ina219 - Getcurrent Arduino Sketch

This Arduino sketch initializes an INA219 sensor to measure voltage and current. It begins by including the necessary libraries and declaring the INA219 object. In setup, it initializes serial communication and the INA219 sensor. In loop, it reads the shunt voltage, bus voltage, current, and calculated load voltage from the sensor every 2 seconds and prints the values to the serial monitor.

Uploaded by

Dado Gaudi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
134 views1 page

Ina219 - Getcurrent Arduino Sketch

This Arduino sketch initializes an INA219 sensor to measure voltage and current. It begins by including the necessary libraries and declaring the INA219 object. In setup, it initializes serial communication and the INA219 sensor. In loop, it reads the shunt voltage, bus voltage, current, and calculated load voltage from the sensor every 2 seconds and prints the values to the serial monitor.

Uploaded by

Dado Gaudi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

C:\Users\dntg\Documents\Arduino\ina219_getcurrent\ina219_getcurrent.

ino giovedì 4 gennaio 2018 03:53


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

Adafruit_INA219 ina219;

#if defined(ARDUINO_ARCH_SAMD)
// for Zero, output on USB Serial console, remove line below if using programming port to
program the Zero!
#define Serial SerialUSB
#endif

void setup(void)
{
#ifndef ESP8266
while (!Serial); // will pause Zero, Leonardo, etc until serial console opens
#endif
uint32_t currentFrequency;

Serial.begin(115200);
Serial.println("Hello!");

// Initialize the INA219.


// By default the initialization will use the largest range (32V, 2A). However
// you can call a setCalibration function to change this range (see comments).
ina219.begin();
// To use a slightly lower 32V, 1A range (higher precision on amps):
//ina219.setCalibration_32V_1A();
// Or to use a lower 16V, 400mA range (higher precision on volts and amps):
//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;

shuntvoltage = ina219.getShuntVoltage_mV();
busvoltage = ina219.getBusVoltage_V();
current_mA = ina219.getCurrent_mA();
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.println("");

delay(2000);
}

-1-

You might also like