Engineers Garage

  • Projects and Tutorials
    • Circuit Design
    • Electronic Projects
      • 8051
      • Arduino
      • ARM
      • AVR
      • PIC
      • Raspberry pi
      • STM32
    • Tutorials
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • EE Design News
    • DIY Reviews
    • Guest Post
    • Sponsored Content
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • EE Resources
    • DesignFast
    • LEAP Awards
    • Oscilloscope Product Finder
    • Video
    • White Papers
    • Webinars
  • EE Learning Center
  • Women in Engineering

Battery voltage monitor with nodemcu Esp8266-12E WiFi module

March 30, 2021 By EG Projects

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.

Voltage divider with battery circuit

Voltage divider with battery circuit

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. 

Voltage divider resistance value calculation

Voltage divider resistance value calculation
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

Voltage drop across voltage divider resistors

Voltage drop across resistance of voltage divider circuit
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.

Voltage divider ration calculation

Voltage divider ratio calculation
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.

Battery voltage monitoring with nodemcu

Battery voltage monitoring with nodemcu
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 😀 

Picture

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.

battery voltage monitor over WiFi

battery voltage monitor over WiFi
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. 

Battery voltage monitoring methods

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.
Battery voltage monitor with node mcu.ino

Related Articles Read More >

Cheap Robotic Arm
Arduino-based fall/collision detection alarm using KY-031 knock sensor
DC motor controller using rotary encoder
Raspberry Pi based Smart Home Security System

HAVE A QUESTION?

Have a technical question about an article or other engineering questions? Check out our engineering forums EDABoard.com and Electro-Tech-Online.com where you can get those questions asked and answered by your peers!


Featured Tutorials

  • Introduction to Wireless Modules
  • ADC with NRF24LE1 (Part 2/14)
  • Interrupts with NRF24LE1 (Part 3/14)
  • Power Failure Indicator in NRF24LE1 (Part 4/14)
  • Using EEPROM of NRF24LE1 (Part 5/14)
  • PWM with NRF24LE1 (Part 6/14)

Stay Up To Date

Newsletter Signup

EE Training Center Classrooms

“ee

“ee

“ee

“ee

“ee

Recent Articles

  • What are Application Specific ICs?
  • Introduction to LUFA
  • What are the different types of integrated circuits?
  • Introduction to Wireless Modules
  • ADC with NRF24LE1 (Part 2/14)

RSS EDABOARD.com Discussions

  • Inductive Current , High Current Track
  • Mains voltage range in India?
  • Thyristor choice?
  • Inspecting split AC control board not running the fan
  • Trying to repair an RF generator

RSS Electro-Tech-Online.com Discussions

  • Tesla coil progress
  • Two switch forward topology WEIRD waveform and efficiency issue
  • EasyEDA Discovery / Tip
  • Ideas for a homemade tv set?
  • How to breadboard with WSON devices.
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • DesignFast
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • About Us
  • Contact Us
  • Advertise

Copyright © 2021 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy | Advertising | About Us

Search Engineers Garage

  • Projects and Tutorials
    • Circuit Design
    • Electronic Projects
      • 8051
      • Arduino
      • ARM
      • AVR
      • PIC
      • Raspberry pi
      • STM32
    • Tutorials
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • EE Design News
    • DIY Reviews
    • Guest Post
    • Sponsored Content
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • EE Resources
    • DesignFast
    • LEAP Awards
    • Oscilloscope Product Finder
    • Video
    • White Papers
    • Webinars
  • EE Learning Center
  • Women in Engineering