tusabez
Posts: 4
Joined: Mon Jun 28, 2021 4:30 am

Using resistors with ADS1115 to measure 12v battery

Mon Jun 28, 2021 5:02 am

Hi all,

I've been scouring the internet on different ways to bring the voltage down from 12v to 5v so the ADS1115 I have connected to my RPI4 can take readings. I built a portable Retropie system with a 14" screen that requires 12v. I'm also using a 5v step down converter to power the RPI4 using the same battery. I basically want to keep track of the battery charge so I don't get unexpected power loss. From what I gather, I need to add 14k and 10k resistors for a voltage divider that will bring the input into the ADC within an acceptable range using this calculator [/url]https://ohmslawcalculator.com/voltage-d ... calculator[/url] . I used a multimeter to check output on the battery which read 11.83. However, after adding the resistors and checking the output from the positive and negative lines, I get a reading of 11.54. I probably did something wrong or I'm not understanding the process correctly. Also, could I just add another 5v step down or wire from the current 5v step down converter into the ADC to get readings or would that not be recommended? I'm a novice when it comes to all of this and I'm just learning as I go. I appreciate any guidance I can get. Thanks

gordon77
Posts: 5933
Joined: Sun Aug 05, 2012 3:12 pm

Re: Using resistors with ADS1115 to measure 12v battery

Mon Jun 28, 2021 9:45 am

The ADC circuit will have an input impedance which is across (in parallel with) R2 lowering its value. Try increasing R2 slightly.
Last edited by gordon77 on Mon Jun 28, 2021 1:50 pm, edited 1 time in total.

ghp
Posts: 2025
Joined: Wed Jun 12, 2013 12:41 pm
Location: Stuttgart Germany
Contact: Website

Re: Using resistors with ADS1115 to measure 12v battery

Mon Jun 28, 2021 12:04 pm

When the ADS1115 is connected to the PI, you most probably power the ADC with 3.3V. Then the max allowed input voltage for the ADC input is 3.3V.
So you need to bring down the 12V to 3.3V max. Better to have a slight margin for resistor value tolerances.
voltage_divider.png
voltage_divider.png (60.62 KiB) Viewed 837 times
Most batteries have a higher voltage if fully charged than the nominal voltage printed on the box. So R2 with 9k1 allows input voltages up to prox 13.3V.

My proposal of prox 12k sum resistance to the divider results in 1mA current taken from the battery. If this is too high, then multiply the resistors by 10. Rule of thumb: current through voltage divider should by 100 times larger than current needed for the ADC input. ( If current is still too high, consider to switch on/off the divider, but this is a different story. This also may apply if you leave the battery connected while pi is shut down.)

Doublecheck the resistor R1 is connected to GND // to R2. It sometimes happens on breadboards that contacts are failing. Which in this case could lead to have 12V voltage to the AIN0-Input. The chip would not like this... Setup the divider without connecting to ADC, measure voltage in the middle tap. If ok, then connect to the ADC input.

g4bch
Posts: 23
Joined: Mon Oct 01, 2012 12:06 pm

Re: Using resistors with ADS1115 to measure 12v battery

Mon Jun 28, 2021 1:08 pm

If you want to measure a 12V supply voltage do not scale the 12V to the maximum voltage that the ADC can handle; in this case the nomial 3V of the RPi input pins. I would scale the maximum input voltage to a minimum of 15V. Somewhere around 18V would allow for charging voltage with a asfety margin. for 15V increase R2 in the diagram above to 12k, and for 18V to 15k. The ADS1115 has more than enough resolution for battery monitoring.
For additional protetio of the ADC input place a diode between the junction of R1 & 2 and the ADCs VCC pin, then if anything happens to R1 or its connection the diode will be forward baised and the inpt pin will not see any more than the diode forward voltage above VCC.

tusabez
Posts: 4
Joined: Mon Jun 28, 2021 4:30 am

Re: Using resistors with ADS1115 to measure 12v battery

Mon Jun 28, 2021 3:16 pm

Thanks for the replies and suggestions guys. I was using the 5v GPIO pin to supply power to the ADC but it sounds like I should use 3.3v instead. When I fully charged the battery, I got a reading of 12.65V so I need to change my resistor values to above 13v as suggested. As far as a diode goes, what is the recommended value for one? Also, when I shutdown the Pi through software, the battery will still be connected. Is it safe to assume that power will still be supplied through the 3.3v pin on the Pi to the ADC? Or will there be any issues with voltage still being supplied to A0 since the ADC is also connected to the same battery? Thanks again.

ghp
Posts: 2025
Joined: Wed Jun 12, 2013 12:41 pm
Location: Stuttgart Germany
Contact: Website

Re: Using resistors with ADS1115 to measure 12v battery

Mon Jun 28, 2021 6:10 pm

You can switch on/off the voltage divider with a high side switch.
Example: see https://www.vishay.com/docs/70611/70611.pdf, Figure 3
When Pi is off the voltage divider will not consume current from the battery. Of course you need a GPIO pin to control this.

For a protective diode use a schottky e.g. BAT43

tusabez
Posts: 4
Joined: Mon Jun 28, 2021 4:30 am

Re: Using resistors with ADS1115 to measure 12v battery

Fri Jul 30, 2021 4:27 am

ghp wrote:
Mon Jun 28, 2021 6:10 pm
You can switch on/off the voltage divider with a high side switch.
Example: see https://www.vishay.com/docs/70611/70611.pdf, Figure 3
When Pi is off the voltage divider will not consume current from the battery. Of course you need a GPIO pin to control this.

For a protective diode use a schottky e.g. BAT43
I finally had some time over the past week to work on my project. @ghp You were right about my connections. After checking the resistors I was able to drop voltage output that was acceptable for the sensor. I took your suggestion about adding a P channel MOSFET to cut power going to the sensor when the Pi is off but I'm having difficulty understanding on how to implement one when it comes to the correct wiring. I looked at some examples online but wasn't able to completely figure it out. Would it be too much to ask if you could add it to the diagram you has posted previously? I'd really appreciate it. Thank you.

trejan
Posts: 3618
Joined: Tue Jul 02, 2019 2:28 pm

Re: Using resistors with ADS1115 to measure 12v battery

Fri Jul 30, 2021 4:54 am

Presumably this 12V battery is some kind of Lithium based pack? Are you trying to tell when the battery is about to go flat or are you trying to get a battery gauge? Does your battery pack have protection circuitry?

tusabez
Posts: 4
Joined: Mon Jun 28, 2021 4:30 am

Re: Using resistors with ADS1115 to measure 12v battery

Fri Jul 30, 2021 5:15 am

trejan wrote:
Fri Jul 30, 2021 4:54 am
Presumably this 12V battery is some kind of Lithium based pack? Are you trying to tell when the battery is about to go flat or are you trying to get a battery gauge? Does your battery pack have protection circuitry?
Yes it's Lithium based and it does have protection circuitry. The reason I have a sensor connected to it is so the Raspberry Pi can do a safe shutdown automatically when the battery is low. I want to make sure the microSD card doesn't corrupt at a sudden loss of power.

Return to “Automation, sensing and robotics”