Measuring voltage of your solar panel, ups and other daily use batteries consumes a lot of time. Grabbing multi-meter, opening the battery boxes and touching both the multi-meter leads to terminals of battery takes some effort. How about developing an efficient IOT system through which you can see the status of your battery on your desktop and mobile web browsers. Lets start and make this diy project. Since we are going to develop and IOT system which can monitor battery status and update us on our browser. We need some circuit/device/controller which can effectively measure voltage. A WiFi device which can connect to our local home WiFi, takes voltage reading from controller and updates the end user about the current battery level. For this purpose i decided to use nodemcu WiFi module in the project. It can not only work as controller but also it can connect it self to a WiFi network as server or client. Battery monitoring circuit is a traditional voltage divider circuit. I am going to measure 12 volt batteries. Circuit can be modified to measure 24 volt batteries and even more 48 volts parallel battery cluster.
Voltage divider working and calculations
Nodemcu is a tiny device, it works on 3.3 volts. Since it is working on 3.3 volts its pins can source and sunk 3.3 volts only. Voltage greater than 5 volt may blow the pin or fry the nodemcu. In our case we want to measure 12 volt battery and nodemcu adc(analog to digital channel)can only accept 3.3 volts. We need to play smartly here. What we will do is divide the voltage between two resistors and measure only voltage across one resistor and remaining resistor voltage will be calculated mathematically. Typical voltage divider circuit and formula is given below.
Now lets calculate the values for Rtop and Rbottom. Here we need some important considerations to be taken seriously.
- Low ohm resistors can sunk much current and wires could be heated instantly. Consequently wires can melt down in seconds. So always use sufficient amount of resistors for bigger ampere hour batteries. I selected one resistor Rbottom to be 10k ohm.
- During charging battery voltage can increase to 18 volts. For example150 watt solar panel outputs 17 volts at 6 amperes during full sun, output voltage can even reach above 18 volts. Solar charge controller also output voltage approximately equal to 15 volts to charge the batteries.
Formula Calculations
I am going to measure voltage across Rbottom and i decided its value randomly to be 10k ohm. We know Vout can be up to maximum 3.3 volts since nodemcu works and accepts maximum 3.3 volts at its I/O pins. Vin is 18 volts when the battery is charging. Now we can find Rtop.
Now if 18 volts are at battery side it will be divided across resistors, 3.3 volts drops at 10k resistor and remaining 14.7 volts drops at 44.54 k resistor. 44.54 k ohm resistor is not available in market i am going to use the one above this rating and easily can be find from any electronics shop 47 k ohm resistor. If battery is not charging and say supplying 12 volts what will be the voltage drop across resistors? Lets calculate it
Its obvious from the above discussion that the voltage across Rbottom will not exceed 3.3 volts now. I hope it makes sense to readers about the calculations. The question now is how the 3.33 volts is converted to 12 volt by nodemcu or how from 3.33 volts we can predict that at the battery side the voltage is 12 volts. Well a little more mathematics is involved here. Since the resistor values are fixed we can calculate the voltage ratio across the resistors with respect to the source and use it in code for actual voltage at source. How ratio is calculated is below.
Two cases are given above when source is at 18 volt and when source is at 12 volt in both the cases the ratio comes out to be constant value. This ratio is utilized in code for predicting the actual source/battery voltage. Ratio is multiplied with voltage at Rbottom for actual voltage value.
Project circuit diagram is given below. I am using ADC0 channel of nodemcu to measure the battery voltage. Both the battery and nodemcu power must be grounded together in order to complete the circuit. Its a most common mistake will measuring the voltage that both grounds are not grounded together. If the nodemcu ground is not taped with the battery ground the adc0 pin will become a floating pin and it starts reading floating values.
Project circuit diagram is given below. I am using ADC0 channel of nodemcu to measure the battery voltage. Both the battery and nodemcu power must be grounded together in order to complete the circuit. Its a most common mistake will measuring the voltage that both grounds are not grounded together. If the nodemcu ground is not taped with the battery ground the adc0 pin will become a floating pin and it starts reading floating values.
After you completed the circuit its time to move on to code. Code is written in arduino IDE. I used ESP8266WiFi.h library in the code so first please make sure you installed this library in your arduino library folder. If its not present download it from github and install it first. Then enter the SSID and password of the WiFi network to which you want your nodemcu to be connected to. Most probably it will be your home WiFi. So just enter the ssid and password. Now upload the code in nodemcu. Before uploading make sure you selected the right board from arduino boards. If nodemcu is not appearing in your boards drop down menu than import its link from boards manager and install its necessary files. You can find many tutorials on internet about how to install nodemcu support for arduino IDE.
After uploading code you have to do a little one time complex work. Open arduino serial monitor. As soon as you open it you will see nodemcu server starting and your WiFi assigning an IP to your nodemcu. This IP is very important. You have to enter this IP in your mobile or desktop browser to see the battery status. If you do not see any message on serial monitor. Check for serial monitor communication speed it must be 9600 bps. Change it to 9600. If still you do not see any thing than might be code is not uploaded correctly or board is disconnected. Check for the possible errors. Once the IP is allotted by your router to nodemcu it will remain same all the time. I hope so ????
|
As soon as you hit the assigned IP in your browser you will see the page displaying battery status and a button. Press this button to get the updated temperature when ever you want.
Note: Nodemcu and your client mobile or desktop on which you want to view the voltage must be connected to same WiFi. If your server-nodemcu and client-mobile or computer, laptop etc are connected to different networks you can not view any thing after hitting the IP. |
This is a base project. Further more developments can be made to project. Like data can be send to remote web site to be displayed real time on we pages. An alert can be generated when voltage is low. Leds or lcd can be connected to nodemcu for on spot status view.
In order to learn about other ways to measure battery voltage take the below tutorial. Tutorial is about measuring batteries when they are connected in series and parallel combination.
Download the project code. Folder contains project .ino file. Please provide us your feed back on the project. If you have any queries or questions write them below in the comments section.