Project Report
Project Report
A Project Report
Submitted to the APJ Abdul Kalam Technological University
in partial fulfillment of requirements for the award of degree
◦
in
Electrical and Electronics Engineering
by
K C NEELIMA (PKD21EE033)
RITHIN V(PKD21EE045)
SWATHI K S(PKD21EE051)
BHARATH B(LPKD21EE066)
Deepak M
Assistant Professor, Dept of EEE
CERTIFICATE
30 March 2025
This is to certify that the report entitled WEB SERVER BASED BATTERY MANAGE-
MENT SYSTEM submitted by K C NEELIMA (PKD21EE033) RITHIN V (PKD21EE045),
SWATHI K S(PKD21EE051), BHARATH B (LPKD21EE066) to the APJ Abdul Kalam Tech-
nological University in partial fulfillment of the B.Tech. degree in Electrical and Electronics
Engineering is a bonafide record of the Project Phase I carried out by them under our guidance
and supervision. This report in any form has not been submitted to any other University or
Institute for any purpose.
Dr.Lisy E.R
Head of Department
Dept.of EEE
ACKNOWLEDGEMENT
We would like to express our deepest appreciation to all those who provided me the
possibility to complete this report. First and foremost, we express our deepest appreciation
to our esteemed project guide, Asst Prof. Deepak M . His exceptional guidance, unwavering
support, and profound expertise have been invaluable throughout the entire project process.
Their dedication to our academic growth has been a source of inspiration and motivation. We
are also deeply indebted to our project co-ordinator, Asst Prof Abdul Kareem Puthiyaveettil
and Prof Dr Vinita Chellappan for their insightful feedback, constructive criticism, and
valuable suggestions. Their willingness to share their knowledge and expertise has greatly
enhanced the quality of our project work. Their contributions have significantly enriched the
learning experience and have propelled us to a higher level of understanding. We are also
grateful to the HOD, Dr. Lisy E R and all the faculty members of the Electrical Department
for giving us this wonderful opportunity to learn and present the project before the class. We
are immensely indebted to all the people who helped and encouraged us throughout the process
without which the work would not have been possible.
i
ABSTRACT
ii
Contents
Acknowledgement i
Abstract ii
List of Figures vi
3 Introduction 1
3.1 Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
3.2 Problem Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
3.3 Literature Review . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
3.4 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
4 System Design 4
4.1 System Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
4.1.1 Block Diagram-Discharging . . . . . . . . . . . . . . . . . . . . . . . 4
4.1.2 Block Diagram-Charging . . . . . . . . . . . . . . . . . . . . . . . . . 6
4.2 Closed Loop Boost Converter Design . . . . . . . . . . . . . . . . . . . . . . . 7
4.2.1 Working Principle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
4.2.2 Closed-Loop Control for Voltage Regulation . . . . . . . . . . . . . . . 8
4.2.3 Tuning of PID Parameters . . . . . . . . . . . . . . . . . . . . . . . . 8
iii
4.2.4 Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
4.3 Battery Bypass Circuit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
5 Simulation Studies 11
5.1 Case 1: Battery Pack Output When Battery 2 and Battery 3 Are Bypassed . . . 11
5.2 Case 2: Boost Converter Output When Battery 2 and Battery 3 Are Bypassed . 12
5.3 Case 3: Battery Pack Output When 3 batteries are Bypassed . . . . . . . . . . . 13
5.4 Case 4: Boost Converter Output When 3 Batteries are Bypassed . . . . . . . . 13
7 Hardware Components 19
7.1 Lithium-ion Battery . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
7.2 Temperature Sensor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
7.3 Voltage Sensor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
7.4 Current Sensor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
7.5 4-Channel SPDT Relay . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
7.6 Inductor (L) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
7.7 Resistor (R) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
7.8 Capacitor (C) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
7.9 MOSFET (N-Channel MOSFET - IRF540N) . . . . . . . . . . . . . . . . . . 23
7.10 Diode (Schottky Diode - SS34) . . . . . . . . . . . . . . . . . . . . . . . . . . 24
7.11 Transformer(230/12V) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
7.12 4S LiFePO4 BMS with Passive Balancing . . . . . . . . . . . . . . . . . . . . 24
8 Hardware Implementation 26
8.1 Closed Loop Boost Converter Implementation . . . . . . . . . . . . . . . . . . 26
8.2 Overall Hardware Setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
8.3 Web Server Integration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
9 Appendix 29
9.1 ESP32 Source Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
iv
9.1.1 Main Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
9.1.2 Sensor Reading and Relay Control . . . . . . . . . . . . . . . . . . . . 32
9.1.3 Web Server Handler . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
10 Conclusion 37
References 38
v
List of Figures
4.1 Blockdiagram-Discharging . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
4.2 Block Diagram-Charging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
4.3 Closed Loop Boost Converter . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
4.4 Bypassing Circuit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
vi
List of Tables
vii
Chapter 1
List of Symbols
µF Microfarad (Capacitance)
µH Microhenry (Inductance)
Ω Ohm (Resistance)
V Battery pack voltage
SOC State of Charge of battery
T Battery temperature
P Bypass control signals for batteries
S SOC status signals of each battery
viii
Chapter 2
ix
Chapter 3
Introduction
1
3.1 Objectives
• Implement a balancing mechanism for the 4S lithium-ion battery pack to prevent voltage
imbalances.
• Integrate overvoltage, overcurrent, and thermal protection strategies to protect the battery
pack from hazardous conditions.
• Establish a web server interface for remote tracking of key battery parameters.
• Efficiency and Lifespan Issues: Cell imbalance causes voltage inconsistencies and
reduced battery lifespan.
2
[2]. Thermal management is also a critical area, as maintaining optimal temperature prevents
battery degradation and hazards. Recent studies highlight the importance of cell balancing
and explore hybrid models that combine electro-thermal simulations with machine learning to
improve SOC and SOH predictions [3]. While significant advances have been made, challenges
remain in achieving real-time accuracy under varying conditions, pointing to ongoing research
in predictive algorithms and adaptive BMS solutions for sustainable EV deployment [1][3].
3.4 Summary
The project focuses on the development of a Battery Management System (BMS) designed
for lithium-ion batteries.The BMS is essential for ensuring battery safety, reliability, and
performance by managing critical parameters such as voltage, current, temperature, and State of
Charge (SOC). The project objectives include achieving cell balancing for a 4-cell (4s) battery
pack by combination of switched shunt resistor method and bypassing method,implementing
SOC estimation techniques, and providing over-voltage, under-voltage, and over-discharge
protection to extend battery life and prevent hazards. The system design incorporates various
hardware components such as an ESP32 microcontroller for remote monitoring, temperature
sensors, current and voltage sensors, and MATLAB-based simulations to model and control
battery behavior. Core functionalities of the BMS include real-time monitoring, SOC
estimation through Coulomb counting, and temperature regulation. Additionally, the BMS
algorithm balances the battery cells by identifying and compensating for the cell with the lowest
charge. The project ultimately aims to demonstrate the effectiveness of BMS in enhancing
battery safety, supporting energy efficiency, and promoting sustainability in electric vehicle
applications.
3
Chapter 4
System Design
The block diagram (Figure 2.1) represents the system architecture during the discharging
phase of the 4-series (4s) lithium-ion battery pack. It highlights the flow of power, data,
and control signals among the key components, ensuring efficient power delivery to the load
4
Figure 4.1: Blockdiagram-Discharging
while maintaining safety and real-time monitoring. Below is a detailed explanation of each
component and its role in the system:
4S Battery Pack:
• Comprises four lithium-ion cells connected in series, providing a higher voltage output.
Microcontroller:
• Serves as the central processing unit, responsible for monitoring battery parameters such
as voltage, SOC, and temperature.
• Controls the relay-based bypass mechanism to remove faulty or discharged cells from
the circuit.
• Adjusts the PWM (Pulse Width Modulation) signals to the boost converter, ensuring a
stable output voltage.
• Sends real-time data to the web server for remote monitoring and predictive maintenance.
• Used to isolate and bypass any battery cell if it reaches a critical state.
5
• Prevents damage to the entire battery pack while ensuring that power delivery to the load
remains unaffected.
Load:
• Represents the device or system consuming power from the battery pack.
Web Server:
• Enables remote monitoring of battery parameters, such as voltage, SOC, and temperature,
ensuring users are always aware of battery health.
The given block diagram represents the charging system for a lithium-ion battery pack,
ensuring controlled and efficient power conversion from an AC supply to a regulated DC output
suitable for charging. The system incorporates various power conversion stages to provide the
required voltage and current for safe and efficient battery charging.
AC Supply:
• The system operates from a standard 230V AC supply, which is converted to a lower
voltage suitable for charging the battery pack.
Rectifier:
• Converts the 12V AC output of the transformer into pulsating DC voltage using a bridge
rectifier.
Filter:
• Smoothens the pulsating DC from the rectifier using capacitors or inductors, reducing
ripples and providing a steady DC voltage.
6
Figure 4.2: Block Diagram-Charging
• Steps up the filtered 12V DC voltage to a range of 12V - 16.8V to match the required
charging voltage for the 4S lithium-ion battery pack.
Charger Module:
• Regulates the charging process by controlling the voltage and current delivered to the
battery pack.
Battery Pack:
7
Figure 4.3: Closed Loop Boost Converter
The boost converter operates based on energy storage in an inductor (249µH). When the
MOSFET (S) is turned ON, current flows through the inductor, storing energy in the form of
a magnetic field. When the MOSFET is turned OFF, the inductor releases this stored energy,
which, in combination with the input voltage, results in a higher voltage at the output. A diode
ensures unidirectional current flow, while a capacitor (220µF) smooths the output voltage by
reducing ripples.
The efficiency and performance of the closed-loop system depend on the appropriate tuning
of the PID controller parameters: Proportional gain (Kp), Integral gain (Ki), and Derivative gain
(Kd). These parameters are optimized using a trial-and-error method to minimize overshoot,
enhance stability, and reduce response time. Proper tuning ensures a smooth and accurate
voltage regulation process.
8
4.2.4 Design
Vs
DutyCycle, D = 1 − (4.4)
Vo
Vo
Outputcurrent, Io = = 0.125 (4.7)
R
Vs · D
Inductor, L = = 249 µH (4.9)
f · ∆IL
Io · D
Capacitor, C = = 220 µF (4.10)
f · ∆Vc
9
Figure 4.4: Bypassing Circuit
microcontroller and Arduino Uno, which process the sensor data and activate bypassing relays
accordingly.
10
Chapter 5
Simulation Studies
In this section, the simulation results of the proposed Battery Management System (BMS)
for a four-cell lithium-ion battery pack are presented. The simulation was conducted using
MATLAB/Simulink to analyze battery behavior, boost converter performance, and bypass
operation under various conditions
• In this scenario, Battery 2 and Battery 3 are bypassed due to either a low state of charge
(SOC), overtemperature, or another fault condition.
• The system detects that these batteries are below the safe operating threshold and
activates the corresponding bypass switches (SPDT switches).
• As a result, only Battery 1 and Battery 4 remain in operation, forming a reduced series
connection.
• The total pack voltage decreases since only two batteries are contributing to the output.
• The current distribution shifts accordingly, ensuring that the load still receives power
from the available batteries.
11
Figure 5.1: Two Battery Bypassed
• With two batteries bypassed, the input voltage to the boost converter is lower than the
nominal full-pack voltage.
• The boost converter compensates for this reduction by increasing its duty cycle to
maintain a stable output voltage for the load.
• The waveform in the figure shows how the converter adjusts to the new input voltage and
stabilizes the output.
• The steady output voltage confirms that the power management strategy effectively
maintains system performance despite bypassing two batteries.
12
Figure 5.2: Boost Converter output when Two batteries bypassed
• In this case, only Battery 3 is removed from the circuit due to a fault condition.
• The remaining batteries (Battery 1, Battery 2, and Battery 4) continue to supply power to
the system.
• The total pack voltage reduces slightly, but not as much as when two batteries are
bypassed.
• The dynamic switching mechanism in the BMS ensures a smooth transition without
affecting system performance.
13
Figure 5.3: Battery Pack output when three batteries bypassed
• The boost converter receives a slightly reduced input voltage compared to the full pack
scenario.
• It adjusts its duty cycle accordingly to maintain a steady and regulated output voltage.
• The waveform indicates minimal fluctuations, proving that the converter effectively
compensates for the loss of one battery.
• If 3 batteries was removed due to overheating, the system prevents excessive load on the
remaining batteries by balancing the current distribution.
14
Figure 5.4: Boost Converter output when 3 batteries bypassed
15
Chapter 6
16
Figure 6.1: OCV-SOC Curve
By measuring the OCV of the battery at various states of charge, we can infer the SOC
using a pre-established model. OCV-SOC Relationship illustrates this dependency, showing
a characteristic curve derived from experimental or reference data for the 18650 lithium-ion
cells used (2000 mAh capacity). The curve highlights how OCV varies from approximately
3.0 V at low SOC to over 4.1 V at full charge, with distinct regions of behavior that require
careful analysis.
To improve the accuracy of SOC estimation across the full range of battery operation,
a piecewise linear modeling approach was developed. The non-linear OCV-SOC curve was
segmented into five distinct voltage ranges, each approximated by a linear equation of the form
y = mx + C, where y is the OCV (in volts), x is the SOC (in percentage), m is the slope, and c
is the intercept. This method simplifies computation while maintaining sufficient precision for
real-time applications.
Figure 6.2 visually represents this segmentation, showing how the curve is divided into
linear sections. The specific equations for each range are derived from experimental data.
The piecewise model was implemented in the BMS to calculate SOC based on real-time OCV
measurements from the voltage sensors (0–25 V range). For a given OCV value, the system
17
Figure 6.2: Piecewise modeling of OCV-SOC Curve
identifies the corresponding voltage range and applies the appropriate equation to estimate
SOC. This approach balances computational simplicity with accuracy.
18
Chapter 7
Hardware Components
• Quantity: 4
• Description: The lithium-ion battery used is an 18650 cylindrical cell with a capacity
of 2000 mAh (milliampere-hours). These batteries are widely adopted due to their
high energy density (150–250 Wh/kg), fast charge/discharge rates (1C–5C for charging
and 5C–20C for discharging), and long cycle life (1000–3000 cycles). In this project,
four such batteries are configured in a 4-series (4S) arrangement to achieve the required
voltage level for the system. The BMS monitors these batteries for voltage, temperature,
and State of Charge (SOC) to ensure safety and optimal performance during discharging.
• Role: Serves as the primary energy storage unit, providing power to the load while being
monitored and managed by the BMS.
19
Figure 7.1: Li-ion Battery
• Quantity: 4
• Role: Ensures battery safety by providing real-time temperature data to the BMS,
triggering protective actions (e.g., bypassing a faulty battery) if thresholds are exceeded.
• Quantity: 4
20
Figure 7.3: Voltage Sensor
• Role: Provides precise voltage data for cell balancing, SOC estimation, and fault
detection, ensuring uniform performance across the battery pack.
• Quantity: 1
• Description: The current sensor measures the total current flowing through the battery
pack during charging and discharging, with a capacity of up to 20 A. This range
supports high-power applications where lithium-ion batteries may deliver discharge rates
of 5C–20C (e.g., 10–40 A for a 2000 mAh battery at higher C-rates). A single sensor is
sufficient to monitor the cumulative current of the 4S configuration, providing data for
SOC estimation and power management.
21
Figure 7.4: Current Sensor
• Quantity: 1
• Description: The 4-channel Single Pole Double Throw (SPDT) relay operates at 5 V and
is used to control the connection or bypassing of individual batteries in the 4S pack. Each
channel corresponds to one battery, allowing the BMS to isolate faulty cells (e.g., due to
overvoltage, undervoltage, or overheating) while maintaining system operation with the
remaining cells. The relay’s 5 V operation is compatible with standard microcontroller
outputs used in the BMS.
• Role: Facilitates battery protection and cell balancing by enabling dynamic bypassing of
faulty batteries, ensuring uninterrupted operation and enhanced safety.
22
Figure 7.5: 4 Channel SPDT Relay
it during the OFF phase, ensuring efficient power transfer. Its value was calculated based on a
30 kHz switching frequency and a ripple current of 0.1 times the output current.
23
Figure 7.6: 230/12V Transformer
when needed. Its low on-resistance and high efficiency make it ideal for power electronics
applications.
7.11 Transformer(230/12V)
The transformer in the battery charging system is a 230V/12V, 1.5A step-down unit that
converts the 230V AC mains supply to a safer 12V AC output. With a power rating of 18W, it
feeds the rectifier stage, which then processes the voltage for charging the battery pack. Likely
a linear transformer operating at 50/60 Hz, it features a turns ratio of approximately 19.17:1
and is constructed with primary and secondary windings on a laminated iron core to minimize
losses.
24
Figure 7.7: 4S BMS used for charging
ensuring overcharge protection, over-discharge prevention, and short-circuit safety. The passive
balancing feature helps equalize voltage levels across all cells by dissipating excess energy from
higher-charged cells, enhancing battery performance and lifespan.
25
Chapter 8
Hardware Implementation
26
Figure 8.2: Web Server
27
Figure 8.3: Overall Hardware Setup
28
Chapter 9
Appendix
The main program initializes the Wi-Fi connection, sensors, and web server, then continu-
ously monitors and updates the system state.
# i n c l u d e <WiFi . h>
# i n c l u d e <WebServer . h>
# i n c l u d e ”DHT . h ”
/ / WiFi c r e d e n t i a l s
const char * s s i d = ” Virus I n f e c t e d ”;
c o n s t c h a r * p a s s w o r d = ” Th1ad2ag3at4ha5n@ ” ;
/ / C r e a t e a web s e r v e r on p o r t 80
WebServer s e r v e r ( 8 0 ) ;
/ / DHT11 t e m p e r a t u r e s e n s o r p i n s and s e t u p
# d e f i n e DHTPIN1 4 // F i r s t s e n s o r on GPIO4
29
# d e f i n e DHTPIN2 5 / / Second s e n s o r on GPIO5
# d e f i n e DHTPIN3 12 / / T h i r d s e n s o r on GPIO12
# d e f i n e DHTPIN4 13 / / F o u r t h s e n s o r on GPIO13
# d e f i n e DHTTYPE DHT11 / / DHT11 t y p e f o r a l l s e n s o r s
// Initialize a l l f o u r DHT s e n s o r s
DHT d h t 1 ( DHTPIN1 , DHTTYPE ) ;
DHT d h t 2 ( DHTPIN2 , DHTTYPE ) ;
DHT d h t 3 ( DHTPIN3 , DHTTYPE ) ;
DHT d h t 4 ( DHTPIN4 , DHTTYPE ) ;
/ / Relay d i g i t a l o u t p u t s
# d e f i n e RELAY1 23
# d e f i n e RELAY2 22
# d e f i n e RELAY3 19
# d e f i n e RELAY4 18
/ / Temperature t h r e s h o l d for s a f e t y c u t o f f
# d e f i n e MAX SAFE TEMP 4 5 . 0
/ / ADC and v o l t a g e c a l c u l a t i o n p a r a m e t e r s
f l o a t R1 = 3 0 0 0 0 . 0 , R2 = 7 5 0 0 . 0 ;
float ref voltage = 3.3; / / ESP32 r e f e r e n c e v o l t a g e
f l o a t BV1 , BV2 , BV3 , BV4 , SOC1 , SOC2 , SOC3 , SOC4 ;
f l o a t temp1 , temp2 , temp3 , temp4 ;
30
void setup ( ) {
S e r i a l . begin (115200);
S e r i a l . p r i n t l n ( ” \ n \ n==== ESP32 B a t t e r y M o n i t o r i n g System ====”);
Serial . p r i n t l n (” I n i t i a l i z i n g . . . ” ) ;
// I n i t i a l i z e DHT s e n s o r s
dht1 . begin ( ) ;
dht2 . begin ( ) ;
dht3 . begin ( ) ;
dht4 . begin ( ) ;
d i g i t a l W r i t e ( RELAY1 , LOW) ;
d i g i t a l W r i t e ( RELAY2 , LOW) ;
d i g i t a l W r i t e ( RELAY3 , LOW) ;
d i g i t a l W r i t e ( RELAY4 , LOW) ;
/ / C o n n e c t t o Wi− F i
S e r i a l . p r i n t ( ” C o n n e c t i n g t o Wi− F i n e t w o r k : ” ) ;
Serial . println ( ssid );
WiFi . b e g i n ( s s i d , p a s s w o r d ) ;
w h i l e ( WiFi . s t a t u s ( ) != WL CONNECTED) {
delay (500);
Serial . print (”.”);
}
S e r i a l . p r i n t l n ( ” \ nWiFi C o n n e c t e d S u c c e s s f u l l y ! ” ) ;
S e r i a l . p r i n t ( ” IP Address : ” ) ;
S e r i a l . p r i n t l n ( WiFi . l o c a l I P ( ) ) ; / / P r i n t ESP32 I P a d d r e s s
31
/ / D e f i n e Web S e r v e r R o u t e
s e r v e r . on ( ” / ” , h a n d l e R o o t ) ;
server . begin ( ) ;
S e r i a l . p r i n t l n ( ” Web S e r v e r S t a r t e d ! ” ) ;
S e r i a l . p r i n t l n ( ” System Ready ! ” ) ;
printSerialHeader ();
}
void loop ( ) {
readSensors ( ) ;
controlRelays ( ) ;
printSerialData ();
server . handleClient ( ) ;
delay (2000); / / DHT11 n e e d s a t l e a s t 1 s b e t w e e n r e a d i n g s
}
This section reads sensor data and controls the relays based on voltage and temperature
thresholds.
void readSensors ( ) {
/ / Read t e m p e r a t u r e s from DHT11 s e n s o r s
temp1 = d h t 1 . r e a d T e m p e r a t u r e ( ) ;
temp2 = d h t 2 . r e a d T e m p e r a t u r e ( ) ;
temp3 = d h t 3 . r e a d T e m p e r a t u r e ( ) ;
temp4 = d h t 4 . r e a d T e m p e r a t u r e ( ) ;
/ / H a n d l e NaN v a l u e s i f s e n s o r s f a i l t o r e a d
i f ( i s n a n ( temp1 ) ) temp1 = 0 . 0 ;
i f ( i s n a n ( temp2 ) ) temp2 = 0 . 0 ;
32
i f ( i s n a n ( temp3 ) ) temp3 = 0 . 0 ;
i f ( i s n a n ( temp4 ) ) temp4 = 0 . 0 ;
/ / Read v o l t a g e s
f l o a t a d c 1 = ( a n a l o g R e a d ( V1 ) * r e f v o l t a g e ) / 4 0 9 5 . 0 ;
f l o a t a d c 2 = ( a n a l o g R e a d ( V2 ) * r e f v o l t a g e ) / 4 0 9 5 . 0 ;
f l o a t a d c 3 = ( a n a l o g R e a d ( V3 ) * r e f v o l t a g e ) / 4 0 9 5 . 0 ;
f l o a t a d c 4 = ( a n a l o g R e a d ( V4 ) * r e f v o l t a g e ) / 4 0 9 5 . 0 ;
BV1 = a d c 1 * ( R1 + R2 ) / R2 ;
BV2 = a d c 2 * ( R1 + R2 ) / R2 − BV1 ;
BV3 = a d c 3 * ( R1 + R2 ) / R2 − ( BV1 + BV2 ) ;
BV4 = a d c 4 * ( R1 + R2 ) / R2 − ( BV1 + BV2 + BV3 ) ;
/ / E s t i m a t e SOC
SOC1 = ( ( BV1 − 3 . 0 ) / ( 4 . 2 − 3 . 0 ) ) * 1 0 0 . 0 ;
SOC2 = ( ( BV2 − 3 . 0 ) / ( 4 . 2 − 3 . 0 ) ) * 1 0 0 . 0 ;
SOC3 = ( ( BV3 − 3 . 0 ) / ( 4 . 2 − 3 . 0 ) ) * 1 0 0 . 0 ;
SOC4 = ( ( BV4 − 3 . 0 ) / ( 4 . 2 − 3 . 0 ) ) * 1 0 0 . 0 ;
SOC1 = c o n s t r a i n ( SOC1 , 0 , 1 0 0 ) ;
SOC2 = c o n s t r a i n ( SOC2 , 0 , 1 0 0 ) ;
SOC3 = c o n s t r a i n ( SOC3 , 0 , 1 0 0 ) ;
SOC4 = c o n s t r a i n ( SOC4 , 0 , 1 0 0 ) ;
}
void controlRelays ( ) {
/ / Store previous relay s t a t e s
b o o l prevR1 = d i g i t a l R e a d (RELAY1 ) ;
b o o l prevR2 = d i g i t a l R e a d (RELAY2 ) ;
b o o l prevR3 = d i g i t a l R e a d (RELAY3 ) ;
b o o l prevR4 = d i g i t a l R e a d (RELAY4 ) ;
33
/ / Battery 1 control
i f ( temp1 > MAX SAFE TEMP ) {
d i g i t a l W r i t e ( RELAY1 , HIGH ) ;
} else {
d i g i t a l W r i t e ( RELAY1 , ( BV1 > 3 . 1 && BV1 <= 4 . 2 ) ? LOW : HIGH ) ;
}
/ / Battery 2 control
i f ( temp2 > MAX SAFE TEMP ) {
d i g i t a l W r i t e ( RELAY2 , HIGH ) ;
} else {
d i g i t a l W r i t e ( RELAY2 , ( BV2 > 3 . 1 && BV2 <= 4 . 2 ) ? LOW : HIGH ) ;
}
/ / Battery 3 control
i f ( temp3 > MAX SAFE TEMP ) {
d i g i t a l W r i t e ( RELAY3 , HIGH ) ;
} else {
d i g i t a l W r i t e ( RELAY3 , ( BV3 > 3 . 1 && BV3 <= 4 . 2 ) ? LOW : HIGH ) ;
}
/ / Battery 4 control
i f ( temp4 > MAX SAFE TEMP ) {
d i g i t a l W r i t e ( RELAY4 , HIGH ) ;
} else {
d i g i t a l W r i t e ( RELAY4 , ( BV4 > 3 . 1 && BV4 <= 4 . 2 ) ? LOW : HIGH ) ;
}
}
34
Listing 9.3: Web Server Handler Function
void handleRoot ( ) {
S t r i n g h t m l = ”< html ><head ><meta h t t p − e q u i v = ’ r e f r e s h ’ c o n t e n t = ’ 2 ’ / > ” ;
h t m l += ”< t i t l e > B a t t e r y M o n i t o r i n g </ t i t l e > ” ;
h t m l += ”< s t y l e > ” ;
h t m l += ” body { f o n t − f a m i l y : A r i a l , s a n s − s e r i f ; m a r g i n : 20 px ; } ” ;
h t m l += ” t a b l e { b o r d e r − c o l l a p s e : c o l l a p s e ; w i d t h : 100%; } ” ;
h t m l += ” t h , t d { b o r d e r : 1 px s o l i d # ddd ; p a d d i n g : 8 px ; t e x t − a l i g n : l
h t m l += ” t h { b a c k g r o u n d − c o l o r : #4CAF50 ; c o l o r : w h i t e ; } ” ;
h t m l += ” . c r i t i c a l { b a c k g r o u n d − c o l o r : # f f c c c c ; } ” ;
h t m l += ” . w a r n i n g { b a c k g r o u n d − c o l o r : # f f f 2 c c ; } ” ;
h t m l += ” . good { b a c k g r o u n d − c o l o r : # c c f f c c ; } ” ;
h t m l += ” </ s t y l e > </ head > ” ;
h t m l += ”<body > ” ;
h t m l += ”<h2> B a t t e r y M o n i t o r i n g System </ h2 > ” ;
h t m l += ”< t a b l e > ” ;
h t m l += ”< t r ><t h > P a r a m e t e r </ t h ><t h > B a t t e r y 1 </ t h ><t h > B a t t e r y 2 </ t h ><t h
/ / B a t t e r y V o l t a g e Row
h t m l += ”< t r ><t d >V o l t a g e </ t d > ” ;
h t m l += ”< t d c l a s s = ’” + g e t V o l t a g e C l a s s ( BV1 ) + ” ’ >” + S t r i n g ( BV1 , 2 )
h t m l += ”< t d c l a s s = ’” + g e t V o l t a g e C l a s s ( BV2 ) + ” ’ >” + S t r i n g ( BV2 , 2 )
h t m l += ”< t d c l a s s = ’” + g e t V o l t a g e C l a s s ( BV3 ) + ” ’ >” + S t r i n g ( BV3 , 2 )
h t m l += ”< t d c l a s s = ’” + g e t V o l t a g e C l a s s ( BV4 ) + ” ’ >” + S t r i n g ( BV4 , 2 )
/ / SOC Row
h t m l += ”< t r ><t d > S t a t e o f Charge </ t d > ” ;
h t m l += ”< t d c l a s s = ’” + g e t S O C C l a s s ( SOC1 ) + ” ’ >” + S t r i n g ( SOC1 , 1 ) +
h t m l += ”< t d c l a s s = ’” + g e t S O C C l a s s ( SOC2 ) + ” ’ >” + S t r i n g ( SOC2 , 1 ) +
h t m l += ”< t d c l a s s = ’” + g e t S O C C l a s s ( SOC3 ) + ” ’ >” + S t r i n g ( SOC3 , 1 ) +
h t m l += ”< t d c l a s s = ’” + g e t S O C C l a s s ( SOC4 ) + ” ’ >” + S t r i n g ( SOC4 , 1 ) +
35
/ / T e m p e r a t u r e Row
h t m l += ”< t r ><t d >T e m p e r a t u r e </ t d > ” ;
h t m l += ”< t d c l a s s = ’” + g e t T e m p C l a s s ( temp1 ) + ” ’ >” + S t r i n g ( temp1 , 1 )
h t m l += ”< t d c l a s s = ’” + g e t T e m p C l a s s ( temp2 ) + ” ’ >” + S t r i n g ( temp2 , 1 )
h t m l += ”< t d c l a s s = ’” + g e t T e m p C l a s s ( temp3 ) + ” ’ >” + S t r i n g ( temp3 , 1 )
h t m l += ”< t d c l a s s = ’” + g e t T e m p C l a s s ( temp4 ) + ” ’ >” + S t r i n g ( temp4 , 1 )
h t m l += ” </ t a b l e > ” ;
h t m l += ”<p> L a s t u p d a t e d : ” + g e t T i m e S t r i n g ( ) + ” </ p > ” ;
h t m l += ” </ body > </ html > ” ;
36
Chapter 10
Conclusion
• Monitors voltage, SOC, temperature, sensor status, relay status, and shutdown reasons
for a four-series lithium-ion battery pack.
• Bypasses faulty or critically discharged batteries using SPDT switches, ensuring uninter-
rupted operation.
• Enhances battery safety and lifespan by preventing overcharging, deep discharge, and
overheating.
• Suitable for Electric Vehicles (EVs) and renewable energy storage systems, optimizing
performance and reliability.
37
References
[1] K. Liu, K. Li, Q. Peng, and C. Zhang, ”A brief review on key technologies in the battery
management system of electric vehicles,” Frontiers Mech. Eng., vol. 14, no. 1, pp. 47–64,
Mar. 2019.
[3] J. Meng, G. Luo, M. Ricco, M. Swierczynski, D.-I. Stroe, and R. Teodorescu, ”Overview of
lithium-ion battery modeling methods for state-of-charge estimation in electrical vehicles,”
Appl. Sci., vol. 8, no. 5, p. 659, Apr. 2018.
38