Battery Monitoring System
The recent advancement of battery technology has encouraged newcomers to learn about BMS system and there designing. In this post I will provide a beginners guide towards BMS systems and we will also make a DIY BMS system(for monitoring the battery cell voltage).
BMS - Battery management system.
A battery management system monitors and controls the charging and discharging state of the battery.
my post may not be helpfully for you to design an entire BMS but you can use this to customize/upgrade your BMS systems which can monitor the cell voltage, Battery charging and discharging state.
Supplies
Arduino uno/nano * 1
li-ion/li-poly battery * 5
INA219 * 1
Basic soldering kit * 1
Arduino Programming
Arduino is well known for its simplicity and low cost. In order to make this project simple and cost efficient I am using Arduino UNO/Nano.
Arduino uno -> 6 ADC
Arduino Nano -> 8 ADC
INA219 is I2C based sensor so Arduino pin A4 and A5 is used as I2C SCL and I2C SDA. we have to sacrifice two ADC pins for I2C communication there are alternative choices which can be made by using software based I2C but I can not assure its working behavior so I strongly recommend working with hardware I2C.
Arduino Nano seems to satisfy my needs so I will be using Arduino Nano for this project. I have attached separate program codes for both Arduino UNO and Nano.
Programming algorithm:
- Start
- Initialize I2C, Uart, ADC.
- Declare variables to store data.
- Read Analog Data and store it.
- Read data available at INA219 current sensor.
- calculate and store power consumption in Wh.
- Send data using Uart communication.
- End
LabVIEW Based GUI
Arduino sends data to LabVIEW using UART communication. LabVIEW collects this raw 10 bit ADC values and convert into its equivalent voltage value.
Algorithm:
- start
- Initialize serial communication using VISA configure Serial port Block.
- Use VISA read Block to read the incoming Serial data and specify number of bytes to be read.
- Use match regular expression Block to separate and extract the required data from the UART data stream.
- Use Hexadecimal string to number block to convert string data into integer values.
- Use replace array subset BLOCK to replace/update the array which stores voltage value.
- Use Index Array to read required cell voltage.
- With the help of indicator Block display the voltage on Meter Gauge.
- Stop
I will be using a GUI software which is based on labVIEW software. To run our labVIEW_GUI we need labVIEW runtime engine pre-installed on our PC.
The labVIEW GUI will collect data from Arduino serially and organize those data to display those data into its GUI indicators blocks.
we will be using controls and indicators to configure port settings and to monitor the cell voltage and temperature of battery pack, INA219 can help us measure the power consumption by measuring both voltage and current of entire battery pack. To make the whole setup work we need Arduino as the brain of this organization and the labVIEW GUI software to monitor and control this partially built BMS system in future we can just simply attach some relays and use the same GUI software with some improvements to turn ON/OFF the charging and discharging of the battery pack.
Arduino Program
#include <Wire.h> #include <Adafruit_INA219.h> Adafruit_INA219 ina219_A(0x41); const int cell_1 = A0; const int cell_2 = A1; const int cell_3 = A2; const int cell_4 = A3; const int cell_5 = A6; const int cell_6 = A7; uint16_t c1, c2, c3, c4, c5, c6; float shuntvoltage = 0; float busvoltage = 0; float current_mA = 0; float loadvoltage = 0; float power_mW = 0; float energy; unsigned int voltage; unsigned int current; unsigned int power; unsigned int Energy; void setup() { Serial.begin(9600); if (! ina219_A.begin()) { Serial.println("Failed to find INA219 chip"); } } void loop() { c1 = analogRead(cell_1); c2 = analogRead(cell_2); c3 = analogRead(cell_3); c4 = analogRead(cell_4); c5 = analogRead(cell_5); c6 = analogRead(cell_6); shuntvoltage = ina219_A.getShuntVoltage_mV(); busvoltage = ina219_A.getBusVoltage_V(); current_mA = ina219_A.getCurrent_mA(); power_mW = ina219_A.getPower_mW(); loadvoltage = busvoltage + (shuntvoltage / 1000); energy = energy + loadvoltage * current_mA / 3600; voltage = loadvoltage * 100; current = current_mA * 10; power = power_mW; Energy = energy * 1000; Serial.print("@"); Serial.print(c1); Serial.print(","); Serial.print(c2); Serial.print(","); Serial.print(c3); Serial.print(","); Serial.print(c4); Serial.print(","); Serial.print(c5); Serial.print(","); Serial.print(voltage); Serial.print(","); Serial.print(current); Serial.print(","); Serial.print(power); Serial.print(","); Serial.println(Energy); delay(2000); }
LabVIEW Program
Output
These images will help you understand how this GUI works and how to wire INA219 and battery cells together.
A BMS generally uses analog devices to monitor and control the cell balancing most of the cases battery is connected in series but I did not use series connection of battery well that can overload the arduino and lead to an permanent damage. But still with the help of voltage divider networks we can solve this issue.