How do I connect INA219 current sensor breakout to measure W

Breakout boards, sensors, other Adafruit kits, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
deDon
 
Posts: 36
Joined: Fri Aug 22, 2014 2:48 am

How do I connect INA219 current sensor breakout to measure W

Post by deDon »

Hi Adafruit,

I have seen couple of projects done with Adafruit INA219 breakout which are great. My question is, if one need to measure wind turbine power (the power generated by the turbine). In what way can I connect the INA219 to the turbine for the sensor to be able to measure the turbine power. I specifically need to monitor both the current and voltage of the turbine.
I will be glad if you could help me out on this.

Thanks,
Don.

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: How do I connect INA219 current sensor breakout to measu

Post by adafruit_support_bill »

Most turbines have AC output, so you would need to install the current sensor somewhere after the rectifier. How large a turbine is it? What range of current levels do you need to measure?

User avatar
deDon
 
Posts: 36
Joined: Fri Aug 22, 2014 2:48 am

Re: How do I connect INA219 current sensor breakout to measu

Post by deDon »

Hi Adafruit,

Thanks for your quick response. It is a DC turbine - 72W connected to charge a 12V battery. I want to measure range of 6 - 8Amps.

Thanks,
Don.

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: How do I connect INA219 current sensor breakout to measu

Post by adafruit_support_bill »

As shipped, the board will measure up to 3.2A @26v. To measure higher currents, you need to remove the 0.1 ohm current sense resistor and replace it with a lower value resistor. 0.01 ohms will let you measure up to 32A.

User avatar
deDon
 
Posts: 36
Joined: Fri Aug 22, 2014 2:48 am

Re: How do I connect INA219 current sensor breakout to measu

Post by deDon »

Yes, I know about the shunt resistor, I ordered for a 0.04 Ohm resistor, which I will use to replace the 0.1 as you said. My problem is how do I connect it, I want to be aware of that before my order arrives.

Thanks,
Don.

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: How do I connect INA219 current sensor breakout to measu

Post by adafruit_support_bill »

Basic connections are covered in the guide: https://learn.adafruit.com/adafruit-ina ... out/wiring
You will need to connect VIN+ and VIN- on the positive side of your load. The turbine manufacturer should be able to provide you with wiring diagrams for the unit.
You should also make sure that the turbine output voltage is within the measurement range of the sensor.

User avatar
deDon
 
Posts: 36
Joined: Fri Aug 22, 2014 2:48 am

Re: How do I connect INA219 current sensor breakout to measu

Post by deDon »

Hi Adafruit,

Your advice has been so helpful. I have now received the 0.04Ohm resistors, my problem now is how to do the programming because I want to measure battery voltage, wind turbine power and solar panel power, I have just received 2 additional INA219-sensors I ordered. But I don't know how to make the three sensors work using one Arduino. Your help will be much appreciated.

Thanks,
Don.

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: How do I connect INA219 current sensor breakout to measu

Post by adafruit_support_bill »

To connect 3 of these sensors to one Arduino, you need to give each one a unique address. See the section on "Addressing the Boards" here:
https://learn.adafruit.com/adafruit-ina ... t/assembly

Next, you need to define and initialize each of the 3 boards with different names and their assigned addresses in your code:

Code: Select all

#include <Wire.h>
#include <Adafruit_INA219.h>
 
Adafruit_INA219 ina219_A(0x40);
Adafruit_INA219 ina219_B(0x41);
Adafruit_INA219 ina219_C(0x42);
 
 
void setup(void) 
{
  ina219_A.begin();  // Initialize first board (default address 0x40)
  ina219_B.begin();  // Initialize second board with the address 0x41
  ina219_C.begin();  // Initialize second board with the address 0x42
}
To read the current from each sensor, just reference each one by name in your code:

Code: Select all

current_A = ina219_A.getCurrent_mA();
current_B = ina219_B.getCurrent_mA();
current_C = ina219_C.getCurrent_mA();

User avatar
deDon
 
Posts: 36
Joined: Fri Aug 22, 2014 2:48 am

Re: How do I connect INA219 current sensor breakout to measu

Post by deDon »

Hi Adafruit,

I have tried the codes as you instructed but what I got in error report is "no matching function for call to 'Adafruit_INA219::Adafruit_INA219(),
Please help.

Thanks,
Don.

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: How do I connect INA219 current sensor breakout to measu

Post by adafruit_support_bill »

Do you have the library installed in the right location?
The library is here: https://github.com/adafruit/Adafruit_INA219
Installation instructions are here: http://learn.adafruit.com/adafruit-all- ... nstall-use

User avatar
deDon
 
Posts: 36
Joined: Fri Aug 22, 2014 2:48 am

Re: How do I connect INA219 current sensor breakout to measu

Post by deDon »

Yes, I installed the library in the right location, what happen is this, when I remove the 0x40, 0x41 and 0x42 it will compile well but when I add them back it will report the error.

Thanks,
Don.

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: How do I connect INA219 current sensor breakout to measu

Post by adafruit_support_bill »

That is strange. The constructor definition definitely is written to accept an address:

Code: Select all

/**************************************************************************/
/*!
@brief Instantiates a new INA219 class
*/
/**************************************************************************/
Adafruit_INA219::Adafruit_INA219(uint8_t addr) {
ina219_i2caddr = addr;
ina219_currentDivider_mA = 0;
ina219_powerDivider_mW = 0;
}
Can you post the entire error output? Make sure that you scroll up and get the first few lines.

User avatar
deDon
 
Posts: 36
Joined: Fri Aug 22, 2014 2:48 am

Re: How do I connect INA219 current sensor breakout to measu

Post by deDon »

Hi Adafruit,

Please I really need your help in this code debugging, should I send you my full codes for you to check for me?

Thanks,
Don.

User avatar
Franklin97355
 
Posts: 23911
Joined: Mon Apr 21, 2008 2:33 pm

Re: How do I connect INA219 current sensor breakout to measu

Post by Franklin97355 »

should I send you my full codes for you to check for me?
You can post your code here and a description or drawing of your connections between it all?
Please use the code button "</>" or

Code: Select all

 tags when posting code to the forums.
Attachments
Code Button.jpg
Code Button.jpg (4.49 KiB) Viewed 717 times

User avatar
deDon
 
Posts: 36
Joined: Fri Aug 22, 2014 2:48 am

Re: How do I connect INA219 current sensor breakout to measu

Post by deDon »

I connected the sensor just like it was shown in the example. I interconnected all the i2c pins of the three sensors.


This are the codes:

Code: Select all

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

Adafruit_INA219 ina219;
 
Adafruit_INA219 ina219_A;
Adafruit_INA219 ina219_B(0x40);
Adafruit_INA219 ina219_C(0x41);
 
 

// set the LCD address to 0x27 for a 16 chars 2 line display
// Set the pins on the I2C chip used for LCD connections:
//                    addr, en,rw,rs,d4,d5,d6,d7,bl,blpol
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Set the LCD I2C address

 void setup(void) 
{
  uint32_t currentFrequency;
  Serial.begin(9600);
  Serial.println("Hello!");
  Serial.println("Measuring voltage and current with INA219 ...");
 
  ina219_A.begin();  // Initialize first board (default address 0x40)
  ina219_B.begin();  // Initialize second board with the address 0x41
  ina219_C.begin();  // Initialize second board with the address 0x42


  Serial.begin(9600); // Used to type in characters
  lcd.begin(16,2);   // initialize the lcd for 16 chars 2 lines, turn on backlight

// ------- Quick 3 blinks of backlight  -------------
  for(int i = 0; i< 3; i++)
  
    lcd.backlight();
    delay(250);
    lcd.noBacklight();
    delay(250);
  


 //setup the LCD's number of columns and rows
  lcd.begin(16, 2);

  Serial.begin(9600);

 //current sensor A variables
  float shuntvoltage_A = 0;
  float busvoltage_A = 0;
  float current_A = 0;
  float loadvoltage_A = 0;
  float power_A = 0;
  
  //obtain sensor A data
 //Sensor A: Solar Power
 
  shuntvoltage_A = ina219_A.getShuntVoltage_mV();
  busvoltage_A = ina219_A.getBusVoltage_V();
  current_A = ina219_A.getCurrent_mA();
  loadvoltage_A = busvoltage_A + (shuntvoltage_A / 1000);
  power_A = loadvoltage_A*current_A;

   if (current_A == 1.90)
  current_A = 2;
  else
  current_A = current_A;
  power_A = current_A * loadvoltage_A;
  
  //current sensor B variables
  float shuntvoltage_B = 0;
  float busvoltage_B = 0;
  float current_B = 0;
  float loadvoltage_B = 0;
  float power_B = 0;
 
   
  //obtain sensor B data
  
  //Sensor B: Wind power
 
  shuntvoltage_B = ina219_B.getShuntVoltage_mV();
  busvoltage_B = ina219_B.getBusVoltage_V();
  current_B = ina219_B.getCurrent_mA();
  loadvoltage_B = busvoltage_B - (shuntvoltage_B / 1000);
  
  power_B = loadvoltage_B * current_B;
if (current_B == 1.90)
  current_B = 2;
  else
  current_B = current_B;
  power_B = current_B * loadvoltage_B;
  
  //current sensor C variables
  float shuntvoltage_C = 0;
  float busvoltage_C = 0;
  float current_C = 0;
  float loadvoltage_C = 0;
  float battery_voltage_C = 0;
 
  //obtain sensor C data
  //battery voltage

  shuntvoltage_C = ina219_C.getShuntVoltage_mV();
  busvoltage_C = ina219_C.getBusVoltage_V();
  current_C = ina219_C.getCurrent_mA();
  battery_voltage_C = busvoltage_C - (shuntvoltage_C / 1000);  
  
 
  
 LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Set the LCD I2C address
/*-----( Declare Variables )-----*/


  void setup();
  {
  Serial.begin(9600); // Used to type in characters
  lcd.begin(16,2);   // initialize the lcd for 16 chars 2 lines, turn on backlight

// ------- Quick 3 blinks of backlight  -------------
  for(int i = 0; i< 3; i++)
  
    lcd.backlight();
    delay(250);
    lcd.noBacklight();
    delay(250);
  {
     void setup();

 // Open serial communications and wait for port to open:
  Serial.begin(9600);
   while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  
   }
  Serial.print("Bus Voltage_A: "); 
  Serial.print(busvoltage_A); 
  Serial.println(" V");
  Serial.print("Shunt Voltage_A: "); 
  Serial.print(shuntvoltage_A); 
  Serial.println(" mV");
  Serial.print("Load Voltage_A: "); 
  Serial.print(loadvoltage_A); 
  Serial.println(" V");
  Serial.print("Current_A: "); 
  Serial.print(current_A); 
  Serial.println(" mA");
  Serial.print("Power_A: "); 
  Serial.print(power_A);
  Serial.println(" mW");
  Serial.println("");
  delay(1000);
  
 //print sensor B data; 

  Serial.print("BusVoltage_B: "); 
  Serial.print(busvoltage_B); 
  Serial.println(" V");
  Serial.print("Shunt Voltage_B: "); 
  Serial.print(shuntvoltage_B); 
  Serial.println(" mV");
  Serial.print("Load Voltage_B: "); 
  Serial.print(loadvoltage_B); 
  Serial.println(" V");
  Serial.print("Current_B: "); 
  Serial.print(current_B); 
  Serial.println(" mA");
  Serial.print("Power_B: "); 
  Serial.print(power_B);
  Serial.println(" mW");
  Serial.println("");
  delay(1000);

 //print sensor C data;

  Serial.print("Bus Voltage_C: "); 
  Serial.print(busvoltage_C); 
  Serial.println(" V");
  Serial.print("Shunt Voltage_C: "); 
  Serial.print(shuntvoltage_C); 
  Serial.println(" mV");
  Serial.print("battery_V: "); 
  Serial.println(" V");
  Serial.println("");

  }
  { 
  lcd.backlight(); // finish with backlight on  

  
  lcd.setCursor(1,0); // set the cursor at 1st col and 1st row
  lcd.print("Load Voltage_A: ");
  lcd.println(" V");
  lcd.print("current_A: ");
  lcd.println(" mA");
 
  lcd.setCursor(1,1); // set the cursor at 1st col and 2nd row
  lcd.print("power_A: ");
  lcd.println(" mW");
  delay(2000);
  
  
  lcd.setCursor(1,0); // set the cursor at 1st col and 1st row
  lcd.print("current_B: ");
  lcd.println(" mA");
 
  lcd.setCursor(1,1); // set the cursor at 1st col and 2nd row
  lcd.print("current_B: ");
  lcd.println(" mA");
  delay(2000);
  // Wait and then tell user they can start the Serial Monitor and type in characters to
  // Display.
 //-------- Write characters on the display ------------------
// NOTE: Cursor Position: (CHAR, LINE) start at 0  
  lcd.setCursor(1,0); // set the cursor at 1st col and 1st row
  lcd.print("battery_voltage_C: ");
  lcd.println(" V");
  
  delay(2000);
  // Wait and then tell user they can start the Serial Monitor and type in characters to
  // Display. 
  }

Locked
Please be positive and constructive with your questions and comments.

Return to “Other Products from Adafruit”