Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey 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
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe

Battery voltage monitor with NodeMCU Esp8266-12E WiFi module

By EG Projects March 30, 2021

Measuring the voltage of your solar panel, UPS, and other daily-use batteries takes a lot of time. Grabbing a multimeter, opening the battery boxes, and touching both the multimeter leads to the battery terminals 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?
Let’s start with this DIY project. We will develop an IoT system that monitors battery status and updates us on our browser. We will need some circuit/device/controller that can effectively measure voltage.
A WiFi device that can connect to our local home WiFi takes voltage readings from the controller and updates the end user about the current battery level. For this purpose, I decided to use the NodeMCU WiFi module in the project. It can not only work as a controller, but also it can connect itself to a WiFi network like a server or client. The battery monitoring circuit is a traditional voltage divider circuit. I am going to measure 12-volt batteries. The circuit can be modified to measure 24-volt batteries and even more 48-volt parallel battery clusters.

Voltage divider working and calculations

NodeMCU is a tiny device that works on 3.3 volts. A voltage greater than 5 volts may blow the pin or fry the NodeMCU. In our case, we want to measure a 12-volt battery, and the NodeMCU ADC (analog to digital converter) can only accept 3.3 volts. We need to play smartly here. We will divide the voltage between two resistors and measure the only voltage across one resistor, and the remaining resistor voltage will be calculated mathematically. A typical voltage divider circuit and formula are given below.

Voltage divider with battery circuit

Voltage divider with battery circuit

Now, let’s calculate the values for Rtop and Rbottom. Here, we need some simple federations to be taken seriously. Resistors can sink much current, and wires can be heated instantly. Consequently, wires can meltdown in seconds. So always use a sufficient amount of resistors for bigger ampere-hour batteries. I selected one resistor, Rbottom, to be 10k ohm.

  • During charging, the battery voltage can increase to 18 volts. For example, 150 watts of a solar panel output 17 volts at 6 amperes during full sun. The output voltage can even reach above 18 volts. The solar charge controller also outputs approximately 15 volts to charge the batteries.

Formula Calculations

I will measure the voltage across Rbottom and randomly decide its value to be 10k ohm. We know Vout can be up to a maximum of 3.3 volts since NodeMCU works and accepts a maximum of 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
If 18 volts are at the battery side, it will be divided across resistors, with 3.3 volts dropping at 10k resistor and the remaining 14.7 volts dropping at 44.54 k resistor. 44.54 k ohm resistor is not available in the market I am going to use the one above this rating and easily can be found from any electronics shop 47 k ohm resistor.  If the battery is not charging and supplying 12 volts, what will the voltage drop across resistors be? Let’s calculate it

Voltage drop across voltage divider resistors

The voltage drop across the resistance of the voltage divider circuit
It’s evident from the above discussion that the voltage across Rbottom will not exceed 3.3 volts now. I hope the calculations make sense to readers. The question now is how the 3.33 volts is converted to 12 volts 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 concerning the source and use it in code for actual voltage at the source. How the ratio is calculated is below.

Voltage divider ration calculation

Voltage divider ratio calculation
Two cases are given above when the source is at 18 volts and when the source is at 12 volts. The ratio is multiplied by the voltage at Rbottom for the actual voltage value.

The project circuit diagram is given below. I am using the ADC0 channel of NodeMCU to measure the battery voltage. The battery and NodeMCU power must be grounded to complete the circuit. Its most common mistake is measuring the voltage in which neither ground is grounded. If the NodeMCU ground is not taped with the battery ground, the adc0 pin will become a floating pin and start reading floating values.

Battery voltage monitoring with nodemcu

Battery voltage monitoring with NodeMCU
After you complete the circuit, it’s time to move on to code. The code is written in Arduino IDE. I used the ESP8266WiFi.h library in the code, so first, please make sure you installed this library in your Arduino library folder. If it’s 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. Most probably, it will be your home WiFi. So, 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 does not appear in your board’s drop-down menu, import its link from its manager and install the necessary files. You can find many online tutorials about installing NodeMCU support for Arduino IDE.  
After uploading the code, you have to do a bit one-time complex work. Open Arduino serial monitor. When you open it, you will see the NodeMCU server starting and your WiFi assigning an IP to your NodeMCU. This IP is essential. To see the battery status, you must enter this IP in your mobile or desktop browser. Suppose you do not see any message on the serial monitor. Check for serial monitor communication speed. It must be 9600 bps. Could you change it to 9600? If you still do not see anything, the code might not be uploaded correctly, or the board is disconnected. Check for possible errors. Once your router allows the IP to the NodeMCU, it will always remain the same. I hope so 😀 

Picture

When you hit the assigned IP in your browser, you will see the battery status page and a button. Press this button to get the updated temperature whenever you want.
Note: The Nodemcu and your client’s mobile or desktop on which you want to view the voltage must be connected to the same WiFi. If your server-nodemcu and, server nodemcu and client mobile are connected to different networks, you can not view anything after hitting the IP.

battery voltage monitor over WiFi

battery voltage monitor over WiFi
This is a base project. Furthermore, the project can be developed, and data can be sent to the remote website to be displayed in real-time on web pages. An alert can be generated when the voltage is low. LEDs or LCDs can be connected to NodeMCU for an on-spot status view.
To learn about other ways to measure battery voltage, take the below tutor, take the tutorial below to measure batteries when they are connected in series and parallel combinations. 

Battery voltage monitoring methods

Download the project code. The folder contains the project .ino file. Please provide us with your feedback on the project. If you have any queries or questions, write them below in the comments section.
Battery voltage monitor with node MCU.ino

You may also like:


  • What are the top development boards for AI and ML?

  • How does LoRa modulation enable long-range communication?

  • What battery chemistries are used in electric vehicles?

  • What types of motors are used in electric vehicles?

  • What is Wireless Electric Vehicle Charging System (WEVCS)?

  • What drone parts you need to build a quadcopter?

Filed Under: Electronic Projects, ESP8266

 

Next Article

← Previous Article
Next Article →

Comments

  1. [email protected] says

    February 1, 2024 at 8:00 pm

    Your article, “Battery voltage monitor with NodeMCU Esp8266-12E WiFi module” gives a very good explanation and exactly what I was looking for.

    I’m running my ESP8266 in deepsleep mode for 30 minutes at a time, from a 9Volt battery and monitoring the battery voltage decay over time to see how long it will last.
    Rbot is 1M ohm Rtop is 2M ohm.

    Can you explain what the parameter “Rvalue=(float)(Vvalue/1024.0)*5; //Convert Voltage in 5v factor” is, how did you arrive at the “*5” 5v factor?

    Since I’m running from a 9volt battery, for my application, I changed it to, “*10” 10v factor.
    My highrange is 9 volts, midrange is 7 volts, low range is 5 volts.

    Thank you for your reply.

    Log in to Reply
    • Bijal Parikh says

      July 23, 2024 at 3:26 am

      Hi, Thanks for reading article on engineersgarage.com. If you have any technical questions or need more information please visit our forums https://www.edaboard.com/ or https://www.electro-tech-online.com/. You can read more articles on http://www.engineersgarage.com
      Have a great day

      Log in to Reply

Questions related to this article?
👉Ask and discuss on Electro-Tech-Online.com and EDAboard.com forums.



Tell Us What You Think!! Cancel reply

You must be logged in to post a comment.

EE TECH TOOLBOX

“ee
Tech Toolbox: Internet of Things
Explore practical strategies for minimizing attack surfaces, managing memory efficiently, and securing firmware. Download now to ensure your IoT implementations remain secure, efficient, and future-ready.

EE Learning Center

EE Learning Center
“engineers
EXPAND YOUR KNOWLEDGE AND STAY CONNECTED
Get the latest info on technologies, tools and strategies for EE professionals.

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!


RSS EDABOARD.com Discussions

  • Voltage mode pushpull is a nonsense SMPS?
  • Input impedance matching network
  • High Side current sensing
  • The comparison of different Tcl script checkers
  • Reducing "shoot-through" in offline Full Bridge SMPS?

RSS Electro-Tech-Online.com Discussions

  • Is AI making embedded software developers more productive?
  • Back to the old BASIC days
  • Parts required for a personal project
  • PIC KIT 3 not able to program dsPIC
  • Failure of polypropylene motor-run capacitors

Featured – RPi Python Programming (27 Part)

  • RPi Python Programming 21: The SIM900A AT commands
  • RPi Python Programming 22: Calls & SMS using a SIM900A GSM-GPRS modem
  • RPi Python Programming 23: Interfacing a NEO-6MV2 GPS module with Raspberry Pi
  • RPi Python Programming 24: I2C explained
  • RPi Python Programming 25 – Synchronous serial communication in Raspberry Pi using I2C protocol
  • RPi Python Programming 26 – Interfacing ADXL345 accelerometer sensor with Raspberry Pi

Recent Articles

  • What is AWS IoT Core and when should you use it?
  • AC-DC power supply extends voltage range to 800 V DC
  • Infineon’s inductive sensor integrates coil system driver, signal conditioning circuits and DSP
  • Arm Cortex-M23 MCU delivers 87.5 µA/MHz active mode
  • STMicroelectronics releases automotive amplifiers with in-play open-load detection

EE ENGINEERING TRAINING DAYS

engineering

Submit a Guest Post

submit a guest post
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • Battery Power Tips
  • DesignFast
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • EV Engineering
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • Subscribe to our newsletter
  • About Us
  • Contact Us
  • Advertise

Copyright © 2025 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

Search Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey 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
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe