INA219 and Arduino UNO
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- adafruit_support_mike
- Posts: 67454
- Joined: Thu Feb 11, 2010 2:51 pm
Re: INA219 and Arduino UNO
Post a photo of your hardware and we'll see what we can find.
- jc johnson
- Posts: 3
- Joined: Sat Oct 12, 2013 10:32 am
Re: INA219 and Arduino UNO
Sir,adafruit_support_mike wrote:Post a photo of your hardware and we'll see what we can find.
As it turns out, I had the SCL & SDA lines swapped at the Arduino end. Correcting this, the INA219 is now measuring voltage & current levels I expected and that agree with those measured with a VOM meter.
Thanks for the timely reply,
P.S. I found a very useful sketch, I2C Scanner, at Arduino's website, which helped me discover my problem.
- tuckcp
- Posts: 6
- Joined: Sat Apr 19, 2014 10:37 am
Re: INA219 and Arduino UNO
Hi all,
I'm new to the forum so I hope I do this right. : )
- I have an Arduino UNO board and have just bought the INA219 breakout board.
- I've connected the two as shown on the top of the Wiring page for the INA219. The image is attached.
- I have downloaded, extracted and saved the folder in the library.
- The snapshot of the output on the Serial Monitor is also attached.
- What I would like to do is to use the getcurrent code to measure the exact Voltage of the 9V Battery.
Can you please tell me where to connect the +ve and the -ve terminals of the Battery? And if I need any other elements to make it work properly?
Thank you.
I'm new to the forum so I hope I do this right. : )
- I have an Arduino UNO board and have just bought the INA219 breakout board.
- I've connected the two as shown on the top of the Wiring page for the INA219. The image is attached.
- I have downloaded, extracted and saved the folder in the library.
- The snapshot of the output on the Serial Monitor is also attached.
- What I would like to do is to use the getcurrent code to measure the exact Voltage of the 9V Battery.
Can you please tell me where to connect the +ve and the -ve terminals of the Battery? And if I need any other elements to make it work properly?
Thank you.
- Attachments
-
- INA219-and-UNO-Output.jpg (71 KiB) Viewed 2909 times
-
- INA219-and-UNO.jpg (219.27 KiB) Viewed 2909 times
- adafruit_support_mike
- Posts: 67454
- Joined: Thu Feb 11, 2010 2:51 pm
Re: INA219 and Arduino UNO
You need one more piece for things to work properly: a circuit that will provide a load for the battery.
Connect a couple of wires to the terminal blocks on the edge of the INA219 breakout, then connect the battery's positive terminal to Vin+ on the breakout. Connect the battery's negative terminal to GND on the load circuit, and connect Vin- on the breakout to the circuit's VCC rail.
Connect a couple of wires to the terminal blocks on the edge of the INA219 breakout, then connect the battery's positive terminal to Vin+ on the breakout. Connect the battery's negative terminal to GND on the load circuit, and connect Vin- on the breakout to the circuit's VCC rail.
- tuckcp
- Posts: 6
- Joined: Sat Apr 19, 2014 10:37 am
Re: INA219 and Arduino UNO
Hi Mike,
thank you for the quick response!
I followed your advice and connected up the circuit as you said. But to keep it simple, I used one 1MΩ Resistor as my load circuit. The output on the Serial Monitor was:
Bus Voltage: 9.00 V
Shunt Voltage: 137.27 mV
Load Voltage: 9.13 V
Current: 1373.50 mA
Bus Voltage: 8.99 V
Shunt Voltage: 136.72 mV
Load Voltage: 9.13 V
Current: 1369.20 mA
Bus Voltage: 8.99 V
Shunt Voltage: 136.88 mV
Load Voltage: 9.13 V
Current: 1370.20 mA
The 9V Battery was in fact 9.13V so that's great. Does the output look alright to you?
Thank you.
thank you for the quick response!
I followed your advice and connected up the circuit as you said. But to keep it simple, I used one 1MΩ Resistor as my load circuit. The output on the Serial Monitor was:
Bus Voltage: 9.00 V
Shunt Voltage: 137.27 mV
Load Voltage: 9.13 V
Current: 1373.50 mA
Bus Voltage: 8.99 V
Shunt Voltage: 136.72 mV
Load Voltage: 9.13 V
Current: 1369.20 mA
Bus Voltage: 8.99 V
Shunt Voltage: 136.88 mV
Load Voltage: 9.13 V
Current: 1370.20 mA
The 9V Battery was in fact 9.13V so that's great. Does the output look alright to you?
Thank you.
- adafruit_support_mike
- Posts: 67454
- Joined: Thu Feb 11, 2010 2:51 pm
Re: INA219 and Arduino UNO
I think you may have gotten the connections backwards. The load voltage should be lower than the bus voltage, and the current readings you got are far higher than I'd expect from a 1M resistor.
Try it with a 1k load. You should see about 9mA of current and 0.9mV across the shunt resistor.
Try it with a 1k load. You should see about 9mA of current and 0.9mV across the shunt resistor.
- tuckcp
- Posts: 6
- Joined: Sat Apr 19, 2014 10:37 am
Re: INA219 and Arduino UNO
I've replaced the 1M resistor with a 1k and now the output is:
Bus Voltage: 3.12 V
Shunt Voltage: 320.00 mV
Load Voltage: 3.44 V
Current: 3200.00 mA
Bus Voltage: 3.10 V
Shunt Voltage: 320.00 mV
Load Voltage: 3.42 V
Current: 3200.00 mA
Bus Voltage: 2.96 V
Shunt Voltage: 320.00 mV
Load Voltage: 3.28 V
Current: 3200.00 mA
Bus Voltage: 2.98 V
Shunt Voltage: 320.00 mV
Load Voltage: 3.30 V
Current: 3200.00 mA
Please let me know where I am going horribly wrong in the wiring of the circuit. Thanks.
Bus Voltage: 3.12 V
Shunt Voltage: 320.00 mV
Load Voltage: 3.44 V
Current: 3200.00 mA
Bus Voltage: 3.10 V
Shunt Voltage: 320.00 mV
Load Voltage: 3.42 V
Current: 3200.00 mA
Bus Voltage: 2.96 V
Shunt Voltage: 320.00 mV
Load Voltage: 3.28 V
Current: 3200.00 mA
Bus Voltage: 2.98 V
Shunt Voltage: 320.00 mV
Load Voltage: 3.30 V
Current: 3200.00 mA
Please let me know where I am going horribly wrong in the wiring of the circuit. Thanks.
- Attachments
-
- INA219-and-UNO-2.jpg (155.91 KiB) Viewed 2865 times
-
- Posts: 5
- Joined: Mon Apr 28, 2014 10:09 am
Re: INA219 and Arduino UNO
I'm trying to get the sketch to work. I have tried Arduino IDE 1.0.5. and 0023
I load the sketch with libraries too and click Verify. The following error is returned:
Call of overloaded 'send(uint16_t)' is ambiguous.
Any clues?
Thanks in advance.
Dan
I load the sketch with libraries too and click Verify. The following error is returned:
Call of overloaded 'send(uint16_t)' is ambiguous.
Code: Select all
Adafruit_INA219.cpp: In member function 'void Adafruit_INA219::wireWriteRegister(uint8_t, uint16_t)':
Adafruit_INA219.cpp:44: error: call of overloaded 'send(uint16_t)' is ambiguous
/Applications/Arduino 0023.app/Contents/Resources/Java/libraries/Wire/Wire.h:54: note: candidates are: void TwoWire::send(uint8_t)
/Applications/Arduino 0023.app/Contents/Resources/Java/libraries/Wire/Wire.h:56: note: void TwoWire::send(int)
/Applications/Arduino 0023.app/Contents/Resources/Java/libraries/Wire/Wire.h:57: note: void TwoWire::send(char*) <near match>
Adafruit_INA219.cpp:45: error: call of overloaded 'send(unsigned int)' is ambiguous
/Applications/Arduino 0023.app/Contents/Resources/Java/libraries/Wire/Wire.h:54: note: candidates are: void TwoWire::send(uint8_t)
/Applications/Arduino 0023.app/Contents/Resources/Java/libraries/Wire/Wire.h:56: note: void TwoWire::send(int)
/Applications/Arduino 0023.app/Contents/Resources/Java/libraries/Wire/Wire.h:57: note: void TwoWire::send(char*) <near match>
Thanks in advance.
Dan
Last edited by danbates on Wed Apr 30, 2014 9:59 am, edited 1 time in total.
- adafruit_support_mike
- Posts: 67454
- Joined: Thu Feb 11, 2010 2:51 pm
Re: INA219 and Arduino UNO
@danbates: Please start a new thread for your question. Trying to debug two problems in the same thread is a recipe for confusion.
@tuckcp: That wiring looks right. Post the code you're using (between CODE tags please) and we'll see if that gives us any clues.
@tuckcp: That wiring looks right. Post the code you're using (between CODE tags please) and we'll see if that gives us any clues.
- tuckcp
- Posts: 6
- Joined: Sat Apr 19, 2014 10:37 am
Re: INA219 and Arduino UNO
Well actually I haven't changed the code 'getcurrent' adafruit provided, but here it is.
Code: Select all
#include <Wire.h>
#include <Adafruit_INA219.h>
Adafruit_INA219 ina219;
void setup(void)
{
uint32_t currentFrequency;
Serial.begin(115200);
Serial.println("Hello!");
Serial.println("Measuring voltage and current with INA219 ...");
ina219.begin();
}
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);
}
- adafruit_support_mike
- Posts: 67454
- Joined: Thu Feb 11, 2010 2:51 pm
Re: INA219 and Arduino UNO
Okay, if you're running the standard example, your connections are good, and you're getting wonky output, I'm going to say that's a bad sensor.
Send a note to [email protected] with a link to this thread and the folks there will get you a new INA219.
Send a note to [email protected] with a link to this thread and the folks there will get you a new INA219.
- amagro
- Posts: 24
- Joined: Tue Aug 06, 2013 10:50 am
Re: INA219 and Arduino UNO
Hi,
I'm trying to get some readings from a 9v battery but I think to be having problems.
I plugged the INA219 as in tuckcp image, and with the following resistors I got the following values:
1k:
Bus Voltage: 7.16 V
Shunt Voltage: 0.71 mV
Load Voltage: 7.16 V
Current: 7.40 mA
Bus Voltage: 7.14 V
Shunt Voltage: 0.72 mV
Load Voltage: 7.14 V
Current: 7.30 mA
Bus Voltage: 7.13 V
Shunt Voltage: 0.72 mV
Load Voltage: 7.13 V
Current: 7.40 mA
1M:
Bus Voltage: 7.26 V
Shunt Voltage: 0.00 mV
Load Voltage: 7.26 V
Current: -0.10 mA
Bus Voltage: 7.26 V
Shunt Voltage: 0.00 mV
Load Voltage: 7.26 V
Current: 0.20 mA
Bus Voltage: 7.26 V
Shunt Voltage: 0.01 mV
Load Voltage: 7.26 V
Current: -0.30 mA
The voltage is correct (checked with a multimeter) but not the amperage.
Connect a couple of wires to the terminal blocks on the edge of the INA219 breakout, then connect the battery's positive terminal to Vin+ on the breakout. Connect the battery's negative terminal to GND on the load circuit, and connect Vin- on the breakout to the circuit's VCC rail.
Is this right ?
(attachment)
thanks
I'm trying to get some readings from a 9v battery but I think to be having problems.
I plugged the INA219 as in tuckcp image, and with the following resistors I got the following values:
1k:
Bus Voltage: 7.16 V
Shunt Voltage: 0.71 mV
Load Voltage: 7.16 V
Current: 7.40 mA
Bus Voltage: 7.14 V
Shunt Voltage: 0.72 mV
Load Voltage: 7.14 V
Current: 7.30 mA
Bus Voltage: 7.13 V
Shunt Voltage: 0.72 mV
Load Voltage: 7.13 V
Current: 7.40 mA
1M:
Bus Voltage: 7.26 V
Shunt Voltage: 0.00 mV
Load Voltage: 7.26 V
Current: -0.10 mA
Bus Voltage: 7.26 V
Shunt Voltage: 0.00 mV
Load Voltage: 7.26 V
Current: 0.20 mA
Bus Voltage: 7.26 V
Shunt Voltage: 0.01 mV
Load Voltage: 7.26 V
Current: -0.30 mA
The voltage is correct (checked with a multimeter) but not the amperage.
Connect a couple of wires to the terminal blocks on the edge of the INA219 breakout, then connect the battery's positive terminal to Vin+ on the breakout. Connect the battery's negative terminal to GND on the load circuit, and connect Vin- on the breakout to the circuit's VCC rail.
Is this right ?
(attachment)
thanks
- Attachments
-
- INA219-Uno.png (104.91 KiB) Viewed 2831 times
- adafruit_support_mike
- Posts: 67454
- Joined: Thu Feb 11, 2010 2:51 pm
Re: INA219 and Arduino UNO
Connecting things that way could damage your Arduino. In effect, you show the 9v battery wired in parallel with the Arduino's 5v pin.
Don't connect the INA219's Vin- pin to the Arduino at all. Connect it to a resistor that then connects to the battery's GND.
Don't connect the INA219's Vin- pin to the Arduino at all. Connect it to a resistor that then connects to the battery's GND.
- amagro
- Posts: 24
- Joined: Tue Aug 06, 2013 10:50 am
Re: INA219 and Arduino UNO
Hi,
I did not connected as in the Frttzing schem, but through the tuckcp image.
My doubt is about the amperage values do not appear to be correct, the voltage was confirmed with a multimeter, and is correct.
The amperage of a 9V battery should be 500mA and not the values that I'm getting.
thanks
I did not connected as in the Frttzing schem, but through the tuckcp image.
My doubt is about the amperage values do not appear to be correct, the voltage was confirmed with a multimeter, and is correct.
The amperage of a 9V battery should be 500mA and not the values that I'm getting.
thanks
- Attachments
-
- INA219_UNO.jpg (875.47 KiB) Viewed 2819 times
- jc johnson
- Posts: 3
- Joined: Sat Oct 12, 2013 10:32 am
Re: INA219 and Arduino UNO
amagro,amagro wrote:Hi,
I did not connected as in the Frttzing schem, but through the tuckcp image.
My doubt is about the amperage values do not appear to be correct, the voltage was confirmed with a multimeter, and is correct.
The amperage of a 9V battery should be 500mA and not the values that I'm getting.
thanks
As best I can tell from your image and readings, you are trying to measure the load current presented to a 9V battery through a 1K and 1M resistor, respectively. As I see it, the readings in your posting make sense for the 1K load. e.g. 9V/1k = 9ma, but since the average load voltage level of the battery, as displayed, is ~7.0V the load current, should be ~7.0ma. For the 1M resistor the load current, using a fully charged 9V battery, should be ~ .009ma e.g. 9v/1M=.000009A)!
I might be incorrect here, but I believe the problem you are seeing may be due to the limitation in precision in which the "float" statements in the "getcurrent" sketch can measure. According to Arduino Reference, "Floats" have only 6-7 decimal digits of precision. That means the total number of digits, not the number to the right of the decimal point.
So, having said all of that, base on the output you are seeing with a 1K load, I believe your INA219 is working correctly- just not for very small loads, such as .009ma. I suggest you try smaller loads i.e. 2k, 5k, etc to see if things make sense
R/
Please be positive and constructive with your questions and comments.