# Best way to sense battery voltage while charging

#### jim0000

Joined Oct 28, 2020
130
It will be disconnected during discharge

End goal: Ideally I would like to sense the battery in real time while charging, and then send that value (after stepping it down) to a value in the range that a microcontroller can use so 3.3v to 3.6v. The microcontroller ideally would use that sensed voltage in a control loop to change a duty cycle dynamically.

I was looking through different ways to sense battery voltage:
Voltage divider
Input Voltage Detector IC
Op amp configuration

But I wasn't sure which method was best to sense the battery voltage while charging, and I got a little confused when I realized that if I did connect a sensing mechanism across the battery terminals or across the output of my circuit while it is being charge, then that sensed voltage would have to be whatever my charger is providing right? Any common design methods to do this that would work great if I am wanting to sense the voltage and then send that result to a microcontroller for it to process and use?

Last edited:

#### LowQCab

Joined Nov 6, 2012
3,946
It would be much easier to come up with a solution for You,
if You would state the end result that You want to achieve.
.
.
.

Joined Jan 15, 2015
7,453
If I measure across the battery terminals in my truck I see about 12.6 VDC. I start the truck. alternator running, battery charging, my voltage increases to about 13.6 volts. When measuring across battery terminals the voltage will be whatever it is. Normally when measuring a 12 volt battery you would use a voltage divider network to pass a proportional fraction of the measured voltage to a uC.

It would be much easier to come up with a solution for You,
if You would state the end result that You want to achieve.
.
.
.
Then it all comes down to this. What you have and where exactly you want to go in detail.

Ron

#### Ian0

Joined Aug 7, 2020
9,514

But I wasn't sure which method was best to sense the battery voltage while charging, and I got a little confused when I realized that if I did connect a sensing mechanism across the battery terminals or across the output of my circuit while it is being charge, then that sensed voltage would have to be whatever my charger is providing right? Any common design methods to do this that would work great if I am wanting to sense the voltage and then send that result to a microcontroller for it to process and use?
True - if you sense the voltage across the battery terminals, you will be sensing the output voltage from your charger. That's because the two are joined together.
You just need a resistive divider that will give about 3.3V output for 16V input (assuming a 3.3V microcontroller). That gives enough margin for you to tell if the voltage has become too high.
This will work out the values for you.

#### jim0000

Joined Oct 28, 2020
130
It would be much easier to come up with a solution for You,
if You would state the end result that You want to achieve.
.
.
.
Ideally I would like to sense the battery in real time while charging, and then send that value (after stepping it down) to a value in the range that a microcontroller can use so 3.3v to 3.6v. The microcontroller ideally would use that sensed voltage in a control loop to change a duty cycle dynamically.

#### jim0000

Joined Oct 28, 2020
130
If I measure across the battery terminals in my truck I see about 12.6 VDC. I start the truck. alternator running, battery charging, my voltage increases to about 13.6 volts. When measuring across battery terminals the voltage will be whatever it is. Normally when measuring a 12 volt battery you would use a voltage divider network to pass a proportional fraction of the measured voltage to a uC.

Then it all comes down to this. What you have and where exactly you want to go in detail.

Ron
Awesome that seems simple enough. I updated the post to include an 'end goal'

#### jim0000

Joined Oct 28, 2020
130
True - if you sense the voltage across the battery terminals, you will be sensing the output voltage from your charger. That's because the two are joined together.
You just need a resistive divider that will give about 3.3V output for 16V input (assuming a 3.3V microcontroller). That gives enough margin for you to tell if the voltage has become too high.
This will work out the values for you.
Thank you that is really helpful! What did you mean by 'That gives enough margin for you to tell if the voltage has become too high.'? I am pretty new to sensing voltages accurately and then using the values that are sensed so I appreciate it.

#### Ian0

Joined Aug 7, 2020
9,514
What did you mean by 'That gives enough margin for you to tell if the voltage has become too high.'?
If the maximum that you want is 14.7V, and the maximum that you can read is also 14.7V, you will never know if the voltage has exceeded 14.7V.
If the maximum you can read is 16V, then you will know if you have exceeded the target.

Joined Jan 15, 2015
7,453
It will be disconnected during discharge

End goal: Ideally I would like to sense the battery in real time while charging, and then send that value (after stepping it down) to a value in the range that a microcontroller can use so 3.3v to 3.6v. The microcontroller ideally would use that sensed voltage in a control loop to change a duty cycle dynamically.

I was looking through different ways to sense battery voltage:
Voltage divider
Input Voltage Detector IC
Op amp configuration

But I wasn't sure which method was best to sense the battery voltage while charging, and I got a little confused when I realized that if I did connect a sensing mechanism across the battery terminals or across the output of my circuit while it is being charge, then that sensed voltage would have to be whatever my charger is providing right? Any common design methods to do this that would work great if I am wanting to sense the voltage and then send that result to a microcontroller for it to process and use?
Well alrighty then. Speaking for myself and only myself there are a few ways I would go about this. You mention using a uC. Some allow 5.0 volt input and some allow a 3.3 volt input. Something to consider when collecting data is once you have it where to put it. The more you collect the more space you need to put the data in. There are some inexpensive data acquisition units out there such as Dataq and Measurement Computing starter kits. There are also uC (micro-controllers) such as Arduino which also has Ethernet Shield devices which can be piggyback right to the Arduino boards and use SD cards for storage. So just a matter of how often you sample as to how much data you get. If I wanted to monitor charging a battery I would likely look at two values, voltage and current. Both depend on the battery you are charging. Using for example and only an example Using and Arduino Uno which is a 5 volt uC I would likely add a ADS1115 module and use the I2C for communication with my Arduino. Nice feature of the ADS1115 is it affords 4 analog channels single ended or it affords 2 channels differential input and I like the latter. It also allows programmable gain which is a real nice to have. With an expected 12 volts system I would likely use a 3:1 voltage divider so 0 to 15 volts becomes 0 to 5 volts and scale your code accordingly. The current sensor can be done with any number of inexpensive current sensors chosen based on anticipated maximum charge current. With a PC involved the data could be dumped into for example an Excel or Calc (Open Office) spread sheet and charted. Depends on what you figure is enough. The mentioned ADS1115 could be eliminated but I like the 15 bit feature verse the basic 10 bit in an Arduino. Rather than an Arduino a ESP8266 module could be used and send the data to Internet so you could have it available on your home wireless network. All a matter of what you want.

Finally what I am suggesting is based on using off the shelf inexpensive hobby parts. Had this been for a commercial application all my suggestions would have been different and have required much deeper pockets.

Ron