Measuring the voltage of an individual battery or an entire bank of batteries using any microcontroller (arduino, microship pic, Avr, Atmega, Intel, NXP, stm32) is an easy task. You can find many tutorials on the internet on how to do this. But what if we want to measure an individual battery connected to a set of batteries in series or parallel combination? Now it is a difficult task to accomplish. But there are still some smarter ways to do this. In this post, I will list some of the ways in which we can measure individual battery voltage, which is part of a series/array of batteries connected in series or parallel.
|
Basic and popular battery monitoring technique – Voltage Divider Circuit
The basic and most popular technique of individual battery monitoring using microcontrollers in practice is the voltage divider circuit. In the voltage divider circuit, two resistors are connected in series and the voltage from the source (battery) is applied at their ends. The voltage is divided between the two resistors according to the ohmic values of the resistor.
|
Voltage divider voltage divided by two resistors
Why voltage divider?
Microcontrollers work at 5 or 3.3 volts (from here on we will take 5 volts into consideration, the techniques listed below can also be applied to 3.3 volt microcontrollers). Therefore, its pins also work on 5 volt TTL logic. Voltage greater than 5 volts may damage the pin or fry the microcontroller. Solar panel, car, ups, generator and backup batteries typically have 12 volts. The microcontroller cannot measure 12 volts directly. Therefore, voltage divider is used here to divide the voltage into two halves, ensuring that the half voltage cannot increase by 5 volts in any scenario (charging, etc.). This half voltage is fed to the microcontroller to measure the voltage.
Voltage divider circuit with formula
Now let's calculate the values of Rtop and Rbottom. Here we need some important considerations to be taken seriously.
- Low ohm resistors can draw a lot of current and the wires can heat up instantly. Consequently, the wires can melt in seconds. Therefore, always use a sufficient number of resistors for larger amp-hour batteries. I selected a 10k ohm resistor Rbottom.
-
During charging, the battery voltage may increase to 18 volts. For example, 150 watt solar panel produces 17 volts at 6 amps during full sun, the output voltage can even reach above 18 volts . The solar charge controller also produces voltage approximately equal to 15 volts to charge the batteries.
Calculating resistance values
I will measure the voltage at Rbottom and decided that its value will randomly be 10k ohm. We know that Vout can have a maximum of 5 volts, since the nodemcu works and accepts a maximum of 5 volts on its I/O pins. Vin is 18 volts when the battery is charging (worst case scenario). Now we can find Rtop.
Calculation of voltage divider resistance value
Now if 18 volts are on the battery side it will be split between the resistors, 5 volts will fall on the 10k resistor and the remaining 13 volts will fall on the 26k resistor. If the battery is not charging and, say, supplying 12 volts, what will be the voltage drop across the resistors? Let's calculate
Voltage drop against resistances of the voltage divider circuit
It is obvious from the above discussion that the voltage across Rbottom will not exceed 5 volts now. I hope this makes sense to readers about the calculations. The question now is how the 3.33 volts are converted into 12 volts by the nodemcu or how from 3.33 volts we can predict that on the battery side the voltage is 12 volts. Well, a little more math is involved here. Since the resistor values are fixed, we can calculate the voltage ratio between the resistors relative to the source and use this in the code for the actual voltage at the source. The way the ratio is calculated is below.
Voltage Divider Ratio Calculation
Two cases are given above when the source is at 18 volts and when the source is at 12 volts, in both cases the ratio is a constant value. This relationship is used in the code to predict the actual voltage of the source/battery. The ratio is multiplied by the voltage at Rbottom to obtain the actual voltage value.
To do the tutorial on calculating resistance values for a microcontroller with a tolerance of 3.3 volts, visit the tutorial below. A demo project with free project code and circuit diagram is presented in the project.
Battery monitoring with 3.3V tolerant microcontroller
Batteries connected in series
Batteries are connected in series to increase voltage output. For example, two 12 volt batteries are connected in series to generate 24 volts. Now how to measure the voltage of individual batteries connected in series. See the circuit below. Four 12-volt batteries are connected in series to produce 48 volts.
Battery combination voltage monitor in series by microcontroller
In the above circuit, four voltage divider circuits are used to measure the voltage across each battery. The technique consists of first measuring the voltage on the battery with high potential, and not on batteries with lower potential, denying the voltage of subsequent batteries on the one with higher potential. For example, for the above circuit, the voltage measured at battery-1 is 48 V and at battery-2 is 36 V. Negating 48v-36v = 12v gives us the voltage of battery-1. Likewise, if battery 3 is at 23v. Than 36v-23v gives 13v. So battery-2 is supplying 13 volts in series. Other battery voltages can be calculated with the same method.
In the above scenario, for each battery there must be a dedicated analog channel. For larger series of batteries, more analog channels are needed and microcontrollers generally have 8 analog channels at most. Therefore, this method is only viable when batteries in series combination are not more than 4.
Note: For the above circuit, the resistor values should be selected using the same formula given above.
A demonstration project using the above technique is made with Arduino Uno. The project contains free source code and circuit diagram. If you are interested, take the tutorial. The link is below.
Measuring a battery voltage matrix using Arduino
Opto-isolators or Optocouplers
Using optocouplers is another way to accomplish the same task. A linear optocoupler is one that can do the job in the best possible way. It outputs an equivalent voltage to input, but with a drop in voltage rating. Optocouplers also isolate the microcontroller from battery voltage and provide safety against high spikes. The problem with optocouplers is that they are difficult to configure and require more effort than a voltage divider. The circuit may also be messed up. Extra power is also required for some time to power the optocoupler. An amplifier may also be needed at the end to amplify the voltage output. Optocouplers also increase the cost of the circuit. Ultimately, the main disadvantage is that you still need a dedicated microcontroller analog channel to measure each individual battery.
You can find many linear optocouplers with different instrument ratings from Texas and other suppliers online. In the end, the circuit will be difficult to design and configure. A typical example is below. I hope no one has time to spend on this
Optoisolated Battery Monitor with Microcontroller
Relays in battery monitoring
Single double pole through relay
Relays can also be used to measure voltage across batteries. A
Double pole single pass relay is the best choice here. A single-pass bipolar relay has a single coil and dual channels. When the coil is energized, two contacts are made instantly. Since two contacts are made. The positive and negative terminals of the battery can be connected to this relay for input. A typical DPST relay footprint is shown on the right side. Normally both terminals are open and after activation of the coil both poles move and complete the circuit line through which electrical energy can now flow.
Simple bipolar relays with batteries and microcontroller connections are shown below. Take a look, I will discuss the circuit, its pros and cons below the diagram.
Battery monitoring in series with microcontrollers
The circuit appears to have a fairly simple diagram, but there are some serious pros and cons.
Pros
- Only one analog channel of the microcontroller is needed to measure multiple batteries.
Cons
- The digital pins of microcontrollers are required to activate the relay coils and for individual batteries an individual pin is required. Digital pins can be shortened using multiplexers.
- Each relay must be turned on and off correctly one by one. If both relays are accidentally turned on at the same time, there will be a large explosion due to the batteries short circuiting.
- The connected relay increases the voltage monitoring response time.
- Relay drive circuit is required.
I used Arduino Mega to monitor a cluster of 32 batteries with the same relay method. I used the ULN2003 relay driver to drive the relay coils. The UL2003 input is connected to the multiplexer output. Multiplexer 4 to 16 is used to drive 2 ULN2003 drivers. First I short-circuited the 2 batteries and it cost a lot in the end I finally fixed the code and inserted some delays that increased the efficiency of the hardware.
I made a simple DIY project with the same logic as above. Arduino relay is used in the project. Click the button below to do the tutorial.
Series connected Arduino relay battery voltage monitor
Analog multiplexers
Analog multiplexers can also be used instead of relays. Finding a suitable multiplexer and its configuration is as difficult as an optocoupler. I didn't have much experience with analog multiplexers, can I say anything more about them.
Batteries connected in parallel
In parallel combination, batteries are connected to increase the life of the source or increase the time for the power source to provide adequate voltage to the load before needing to be recharged. In parallel combination, the voltage across each battery remains the same. Therefore, we cannot measure individual battery voltage in this case.
These are some of the ways batteries connected in series or parallel can be monitored. If you have any other methods in mind, please let me know.
If you are a DIY circuit maker or an electronics enthusiast, or if you are an electronics student, the project mentioned below is for you. It monitors the car's battery voltage, engine temperature and automatically turns off the headlights. The tutorial link is below.
Automotive automation – Battery monitor, engine temperature, headlight control
I also did an internet of things project about battery voltage monitoring via WiFi. User can see battery status now on smart devices like mobile and desktop computers. Nodemcu esp8266 WiFi module is used in the project. Nodemcu Arduino ide is used to write, compile and download code into nodemcu WiFi module. The project link is provided below.
Battery monitor via WiFi using nodemcu WiFi module