Measuring voltage and current of battery

I have built an audio amplifier and i am going to put a raspi there to make the input wireless. The whole system is going to be supplied by a 12V closed type acid battery.

So what i would like to do is use the raspi to log the voltage of the battery and the current that is being drained by the whole system

As far as i understand all i have to do is use a analog to digital converter like mcp3008. However i dont seem to find any circuit on that. Anyone has anything in mind?

Is there going to be a problem if the ground of the system i want to measure is the same with the ground of the raspi?

Please dont refer me to any ready to use board except if its simple and there is a source to copy it.

Thank you.

• The Raspberry Pi is irrelevant to your actual question.
– joan
Jul 6, 2016 at 10:41
• The Pi's not irrelevant if the MCP3008 is being attached to it to measure things. Jul 6, 2016 at 11:11

I'm afraid I only have two partial solutions - you'll need to do some legwork to combine the two for both current and voltage sensing.

There's a decent looking tutorial on monitoring the voltage of a 12V battery here, on lediouris.net. Note that it was written in 2014, and the Pi used had only a 26 pin GPIO header. If you're using a later model Pi with a 40 pin GPIO header you'll need to double check the pin allocations. He used a simple voltage divider to get the 12V down to something usable by the MCP3008/Pi, and wrote some java scripts (available here on Github) to read the values. You can see from the diagram below that all of the grounds in the circuit have been tied together.

For current measurement I would use something based on an ACS712 Hall effect sensor. There are many breakout boards available on Ebay/Sparkfun/etc. - make really sure that you have the right amperage version. The ACS712 apparently comes in 3 varieties - 5A, 20A and 30A. For your application I think I'd suggest the 20A variant - it could damage the sensor if you push more current through it than it can handle. When correctly connected (it's an analogue output, so it'll need to go into an ADC/MCP3008) the breakout board will output a voltage between 0V and 5V which is proportional to the current flowing in the circuit. You'll need to do some initial calibration, i.e. connect the sensor and put a known current value through it so that you can adjust its gain settings appropriately. After that it should be be possible to measure current flow with a reasonable degree of accuracy.

From personal experience making battery powered audio amplifiers, you're going to have an uphill struggle on your hands removing noise from the system if you're planning on charging it and using it simultaneously. With that being the case, the Pi may not be your best choice as a bluetooth audio receiver - the Pi's audio output is notoriously noisy unless you use a relatively expensive add-on board. There are many low power bluetooth audio receivers which are designed for clean audio and are likely to be less problematic than the Pi.

• Ditto on the pi not being a great choice for audio-centric applications, at least if you are intending to use the onboard 3.5mm jack for output. While it works, it may prove very disappointing if that is its primary purpose. Jul 6, 2016 at 14:48