Chimneyfactory
Posts: 44
Joined: Sun May 19, 2019 1:30 pm

How best to log 12 volt lead acid battery voltage with a Raspberry Pi?

Thu Jan 30, 2020 12:26 am

I've got some solar panels that charge a lead acid battery via a cheap solar charge controller. This battery then runs some low voltage items in the house, such as the router, a Pi based NAS and soon a few lights.

I've also got an emergency backup that cuts in if the battery voltage drops below 11.5 volts, to charge the lead acid battery by mains until it reaches 11.9 volts. This prevents battery damage by over-discharge and avoids things cutting out due to under voltage.

This is all done with cheap module circuits from ebay, and works well. Uptime is close to 100% even through winter. But I notice that the backup system is constantly switching on because the battery voltage is low.

As part of monitoring and diagnosis, I'd like to log the battery voltage over time.

Is there a module, or simple circuit I might build, that will reliably and safely measure the voltage of a lead acid battery (9 - 15 volt range in extremis) so that I might read the voltage in a simple bash or python script that might sample every 5, 10, 30 minutes etc?

A bonus would be if it could measure the current flowing into and out of the battery, but that may well over complicate what I want to know

Thanks

Ian

markkuk
Posts: 201
Joined: Thu Mar 22, 2018 1:02 pm
Location: Finland

Re: How best to log 12 volt lead acid battery voltage with a Raspberry Pi?

Thu Jan 30, 2020 7:16 am

I think the simplest solution would be using an integrated voltage/current/power monitoring chip such as INA226. You can get breakout boards from the usual sources, just check that the shunt resistor is suitable for your maximum current. Code examples for reading the chip on a RPi: https://github.com/MarioAriasGa/raspberry-pi-ina226, https://github.com/neutronstriker/INA226_Driver_Python

JohnsUPS
Posts: 169
Joined: Fri Jul 06, 2018 2:13 am
Location: USA

Re: How best to log 12 volt lead acid battery voltage with a Raspberry Pi?

Fri Jan 31, 2020 12:10 am

markkuk wrote:
Thu Jan 30, 2020 7:16 am
I think the simplest solution would be using an integrated voltage/current/power monitoring chip such as INA226. You can get breakout boards from the usual sources, just check that the shunt resistor is suitable for your maximum current. Code examples for reading the chip on a RPi: https://github.com/MarioAriasGa/raspberry-pi-ina226, https://github.com/neutronstriker/INA226_Driver_Python
+1

Also, don't overlook the INA260. The main difference between the INA226 and the INA260 is that the 226 needs an external shunt, and the 260 has one built in.

User avatar
Gavinmc42
Posts: 4502
Joined: Wed Aug 28, 2013 3:31 am

Re: How best to log 12 volt lead acid battery voltage with a Raspberry Pi?

Fri Jan 31, 2020 3:44 am

I'm using the INA226 for voltage, current and a TMP112 for Li-Ion battery temperature monitoring.
Wish I had known about the 260 ;)

I checked , it has been 3 1/2 years since I started using Ultibo to log and plot i2c sensor data.
Time flies.
Hmm I did webserver versions, how hard to do a wifi one with a Pi Zero?
https://ultibo.org/forum/viewtopic.php? ... erver#p373
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

miketr3
Posts: 44
Joined: Thu Jan 26, 2017 9:02 am

Re: How best to log 12 volt lead acid battery voltage with a Raspberry Pi?

Thu Feb 20, 2020 6:01 pm

Chimney, did you solve this.
I'm looking for the same thing.
Thanks.

Chimneyfactory
Posts: 44
Joined: Sun May 19, 2019 1:30 pm

Re: How best to log 12 volt lead acid battery voltage with a Raspberry Pi?

Sat Feb 22, 2020 9:48 am

Many thanks for the replies, the INA226 sounds exactly what I want, especially with the code examples to work from.

I've not yet tried this out - been busy with other things - but want to test it soon. Will post back here when I've done so

Thanks

wpballa1
Posts: 70
Joined: Sat Jun 27, 2015 12:49 am

Re: How best to log 12 volt lead acid battery voltage with a Raspberry Pi?

Sun Feb 23, 2020 1:50 am

Check out the Adafruit INA260 version easy to set up for Raspberry Pi usage and only $9.95.

https://www.adafruit.com/product/4226

Return to “Advanced users”