INA219 Measuring Solar Panel and Battery (Please help !!!)

Hi all, sorry i'm a complete novice so bear with me.

I want to measure the output voltage and current of a 18V solar panel connected to a charge controller and 12V battery. I also want to measure the battery voltage. I have two INA219 sensors able to measure up to 26V and 3.2A to do the job but despite my best efforts to figure it out I am very confused with the circuitry for it and dont want to blow anything up.

I gather current is drawn to charge the battery (ignoring charge controller for a minute)providing the panel voltage is greater than the battery voltage. Here does the battery act as a 'load' ? so can be placed between Vin- and Arduino GND ? as with the example learn adafuit circuit (third website further listed below).

The panel has a blocking diode to prevent flow from battery to panel is battery voltage is greater .

Looking at the circuit diagram at the bottom of Texas Instruments site and for the example in the learn adafruit guide site listed below i was thinking:

To measure solar panel voltage and current:

INA219 Vin+ to + of solar panel
INA219 Vin- to battery +
Battery - to arduino GND
Solar panel - to arduino GND

Is this or anything wright ? (or more likeley wrong)

Also how to measure the battery ?

  1. Adafuit sensors: INA219 High Side DC Current Sensor Breakout - 26V ±3.2A Max [STEMMA QT] : ID 904 : $9.95 : Adafruit Industries, Unique & fun DIY electronics and kits
  2. Texas Instruments data sheet:http://www.ti.com/product/ina219
  3. Wiring | Adafruit INA219 Current Sensor Breakout | Adafruit Learning System

Many Thanks

I want to...

Yes, your wiring is wrong, but we can fix it! Let's break this down into separate items. You want to measure

  1. the output voltage of a 18V solar panel;
  2. the output current of a 18V solar panel; and
  3. the battery voltage.

For 1 and 3, you can use resistor dividers to scale the two voltages down to what the Arduino Analog inputs can take.1 Zener diodes and fuses would also be a really good idea. Really.

For number 2, however, there are a couple of approaches: pass the wire that goes from the panel to the controller through a Current Transformer (and a few other components); put a hall-effect current sensor in series (e.g., ACS712 modules); or put a small resistor in series and measure the voltage drop across the resistor. Because V = IR, and you know R and you measure V, you can calculate I (current). The INA219 device is this latter type.

From the Spec:

The INA219 senses across shunts

A shunt is basically a wire that has a little resistance... enough to measure a voltage drop across when current is flowing through it. You use a shunt resistor that is big enough to produce a measurable voltage for the range of currents it will "shunt" through it. Also, it needs to be as small as possible so it doesn't heat up, nor affect the measurement appreciably.

Because there is a controller between the solar panel and the battery, there are actually two places you can measure it: between the panel and the controller, or between the controller and the battery. If you measure it on the panel side, you will get exactly what the panel is producing. If you measure it on the battery side, you will get exactly what is needed for charging. The difference between those two numbers depends on the efficiency of the controller.2

For measuring the panel current, your connection will be solar+ to INA219 Vin+, and INA219 Vin- to controller+. Controller- will just go back to the solar-. The controller will have two other terminals for bat+ and bat-. As it says in the spec, the Vcc is normally provided by a separate power supply (it can be battery+), but it must be referenced to the solar- as the common "ground". For a small, portable system, the solar- and battery- would connected, and form the common ground for the Arduino and the INA219 module.

  • For permanent installations, using a wall wart and/or inverters off the battery and/or other mains connections, there are many other serious issues to consider. DO NOT try anything like that, as it requires a qualified electrician.

Back to the shunt resistor. The adafruit module comes with a 0.1Ω shunt resistor (R100). If the solar panel can provide 1A to charge a dead battery, then the voltage drop across the shunt would be 1A * 0.1Ω = 0.1V. Is that ok for your panel, though?

We have to start with the power rating for your panel. You don't say what it is, so I'll pick 25Watts. Another formula is P = IV, so 25W = I * 18V. Solving for I, we get 25W/18V = 0.72A. That's "probably" the max current at 18V for a 25W panel.

Solar panels aren't ideal like that, unfortunately. As you use more current from them, the output voltage drops. The minimum current would be using none, like it's disconnected - it might read 20V on a voltmeter (aka "open circuit" or Voc). The maximum current would be like it's connected to a 100W incandescent bulb - it might read 0.1V (aka "short circuit") but it would output 1.5A (aka Isc). That's a dim bulb. :wink:

So you'll be measuring anywhere from 0A to 1.5A. Your module can take up to 3.2A, so let's say 3A and work from there.

The spec tells us that the "full scale current sense" of the INA219 is 40mV. It will output a digital value between 0 and 4095 for a voltage difference of 0 to 0.040V measured across Vin+ and Vin-.

For a current of 3A, we can solve for the shunt resistor maximum value to get 40mV: R = V / I = 0.040V / 3A = 0.01333Ω. If you set the Programmable-Gain Amplifier (PGA) in the INA219 to divide by 8, it can measure up to 320mV. That would require a 0.1067Ω shunt resistor. So we can say that the pre-installed 0.1Ω resistor is in the range for a 25W panel. These are the kinds of calculations you need to make for your panel.

If we pick much smaller resistor than that for a 25W panel, you won't be using the full scale of the INA219... For a current of 1A across a 0.01Ω resistor, you'd get 0.01V, which turns into a reading of 1024. If your panel only outputs currents between 0 and 1A, your digital readings will be 0 to 1024. The upper range will never be used, so the reading are essentially "coarser".

You can write some code to set the PGA up if the readings are above 4000... and set the PGA down if the readings are below 100. This is how they extend the range of currents up to 3.2A.

Small resistors are better, because you really don't want to waste much energy in the resistor. Going back to P = IV, we can see that P = 3A * 0.040V = 0.12W. About 1/8W would have been dissipated by the 0.013Ω resistor, leaving 24 7/8W for the battery. :slight_smile: Well, the controller isn't perfect, so maybe 20W will be left for charging the battery. With the pre-installed 0.1Ω resistor, it will dissipate 3A * 300mV = 0.9W, almost 1 watt, or about 4% of what the panel produces. A little more significant. I'd would have gone with a smaller resistor to keep the dissipation (waste) and its physical size down, but that's assuming a 25W panel.

Dang, that's a long post, but that's what happens when a simple question touches on so many different areas. More questions?

Cheers,
/dev


1 It turns out that the INA219 can also measure the voltage on Vin-, so you would only need one resistor divider for the battery voltage side.

2 You have two modules, so you could measure it on both sides and calculate the controller efficiency from the two readings. That would also give you the battery voltage from the INA219 Vin-, so you wouldn't need a resistor divider for that. The connections would be controller bat+ to Vin+, Vin- to battery+, battery - to Arduino GND and controller bat-.

Wow that is excellent ! Thank you very much clearly a lot of effort went into that !

All the best

Steve

If the charge controller is charging the battery, you will be measuring the controller voltage, not the battery voltage. The actual battery voltage can only be measured when the controller is not charging.

Furthermore, if the charge controller uses pulse width modulation to control the charging current, you will not get a good reading on the battery, either.

Paul