Introduction: Monitoring a Battery by Using Bluetooth

This topic was proposed by a person with a disability using a wheelchair, which has a motorization (battery + motor) whose access is underneath it. It is difficult for her to access the state of charge of her battery and thus to know if he can trust the motorization. More generally, the project applies to the monitoring of any battery.

To best address this problem, it is necessary to design a reliable embedded system with good autonomy. Thus, the objective is to develop an electrical system that is able to take voltage and current measurements, to collect these data on a microcontroller like ESP32, to calculate its state of charge according to the current and to transmit all the information on a smartphone via a Bluetooth communication.

The development of the application on Android for displaying the data will be created from App Inventor.

The consumption of the system will have to be minimal in order to obtain a maximum autonomy, for that it will be necessary to improve the system by using a communication in BLE (Bluetooth Low Energy), to remove some LEDs, and to use another ESP.

Supplies

To build this project you will need :

Step 1: How to Dertermine the State of Charge of a Battery ?

In this part we are going to focus on method to determine eficiently the SoC of two types of battery.

The method we use is based on the thesis « Modèle de batterie générique et estimation de l’état de charge », Dekkiche, Abdelillah (2008). We will deal with two types of batteries widely used :


Lead Acid battery

The determination of the SoC is realized thanks to the measurement of the voltage at the terminals of the battery. The voltage must be evaluated by two fixed parameters in order to obtain the current charge.

See first formula, the parameters are :

  • a = battery voltage at SoC = 0%
  • b = battery voltage at SoC = 100%
  • V(t) = mesured battery voltage


LiPo / LiFePo4 battery

For this type of battery, the voltage is not a reliable indicator of the SoC. This is due to the shape of the voltage curve as a function of the SoC, which shows a very small variation between 5% and 85%. We then measure the current entering and leaving the battery to determine the SoC.

See second formula, the parameters are :

  • Q = battery capacity (in Amps.hour)
  • integral of the current between the initial time and current time
  • SoC(t0) = initial State of Charge


In our application, we will focus on LiFePo4 batery since it is the one monted on the weelchair.

Step 2: The Current Sensor

We are using an ACS712 board allowing to measure a current of ± 20A, it has a sensitivity of 100mA/V. It has an analog output that is proportional to the measured current which evolves between 0V and 5V. See picture 4.

According to the datasheet, the internal resistance of the filter circuit is 1.7kΩ, the value of the output capacitance of the filter is 1nF : its bandwidth is therefore 2kHz and its noise voltage is about 10mV. See pictures 2 and 3.

Step 3: Electronic Circuit : Voltage Mesurements

In order to provide more information to the user and potentially use other SoC calculation models, we implement the measurement of the wheelchair battery voltages as well as the battery voltage of our system.

The maximum voltage accepted by the ESP on its GPIOs is 3.3V, so we need to use voltage dividers.

For our on-board system's battery, we have a voltage ranging from about 2V to 4V (Li-Po battery of 3.7V), so resistors R5 and R6 provide a ratio of 0.83.

For the wheelchair battery, the voltage varies between 20V and 28V, so we use R1 and R2 to dimension a 0.1 ratio divider.

We add 3.3V zener diodes D1 and D3 to avoid potential overvoltage on the ESP32's ADCs.

Step 4: Electronic Circuit : Current Mesurements

For the detection of positive or negative current we use an operational amplifier LM393 operational amplifier in dual comparator configuration.

The LM393 is particularly well-suited to our embedded application, as it operates on a single power supply. The device has an open-collector output, so we need to add 1kΩ resistors R9 and R10 to polarize its transistors.

To avoid EMC problems, we place a 1nF decoupling capacitor C1 across the power supply. We've decided to supply the component with 3.3V, so the two resulting logic signals will be directly interpretable by the microcontroller. However, the current sensor delivers a signal of up to 5V, so we have to lower this voltage to avoid altering the amplifier's behavior. A divider bridge with R3 and R4 with a ratio of 0.67 is used to adapt the voltage for both the amplifier and the ESP32's ADC. 

The two comparator thresholds are set using potentiometers POT1 and POT2. We define these using the sensor study above. We detect when the voltage varies around 1.67V (2.5V x 0.67). We run a simulation on LTSpice to validate the circuit's correct operation. See picture 2.

We fictitiously vary the current passing through the transducer, represented by the green curve: when the current is zero, the voltage is 1.67V and only the low threshold comparator is active; if the current is non-zero and positive, we have the high threshold comparator active in addition to the low threshold; if the current is non-zero and negative, both comparators are inactive. Thanks to this threshold logic, we can determine when current is being drawn and in what direction.

To protect our two components from possible overvoltage, we place a 3.3V D2 zener diode in parallel with the voltage divider and ground.

The circuit is mounted on a printed circuit board, but we notice instability in the logic states at the comparator output comparator when the measured voltage is close to a threshold. See picture 3. Since our system must be able to operate interrupts for current sensing, we need to stabilize our control signal. To achieve this, we chose to filter the signal using a low-pass filter.


Step 5: Electronic Circuit : System Supply

As our system is autonomous, we need to manage its battery supply. We use a BMS (lipo rider plus) to protect the battery from overcharging, overdischarging, overcurrent and short circuits. The BMS supplies the current sensor and the ESP32 (nodeMCU) in 5V via a switch to turn the system on and off. The 3.3V for other system components is generated by the voltage regulator on the ESP32.

Step 6: Electronic Circuit : Data Processing and Communication

We connect the parameters to measure to the ESP32, as well as the two logic signals for data processing.

Why the ESP32 nodeMCU? The ESP32 is a 32-bit microcontroller operating at 240MHz, with integrated Wifi and Bluetooth 5.0 LE communication for sending/receiving data to the application. It's popular and programmable via the Arduino IDE, with a large catalog of libraries, so it's easy to find documentation on its features on the Internet. In our case, the nodeMCU is ideal for prototyping, since it has plenty of GPIOs, and can be programmed and powered directly via its micro USB port.

Step 7: PCB Design

For the routing of the PCB we used EasyEDA again. It is necessary to pay attention to the spacing between the components, the width of the tracks and the respect of the rules of electromagnetic compatibility.

The PCB is routed in double face, the major part of the tracks are located on the copper face, the others are placed on on the component side, interconnected by vias. We chose a global routing of 0.5mm wide for the tracks, with a spacing of minimum 0.4mm between them to facilitate the development of the board and reduce the risk of shorts or cut track.

Tip :to make a vias without metallization of the hole (proposed by the manufacturers of PCB) you can use a copper wire inserted in a rather broad hole and soldered on each side of the PCB.

To support the current consumed by the wheelchair motor, which can be up to 13A, we define the thickness of the measuring tracks at 4mm, as provided on the PCB of the ACS712 sensor.

To reduce the problems of electromagnetic compatibility, we have placed a ground plane on both sides of the PCB, limiting the parasitic elements of the power supply lines of our components. To complete this approach, we place a decoupling capacitor as close as possible to the LM393 power supply terminals. The PCB of the ACS712 sensor already has a decoupling capacitor, as does the ESP32. See picture 1.

We have chosen to use pin headers to connect the two modules to our PCB, so if the ESP or BMS should fail, no soldering is required to replace them. In the same philosophy, we used a DIP8 socket for the LM393 operational amplifier.

In order to reduce the size of the PCB (80 x 60 x 23mm) we chose to stack the boards, so we took advantage of the space between boards to place small components (resistors, diodes). The BMS of the battery is susceptible to suffer from mechanical stresses due to the connection/disconnection during the recharging of our embedded system. We therefore used insulated spacers to strengthen the connection between the two boards. To facilitate the handling as well as the integration in a future box, we chose to position in edge of card the USB ports, the switch and the two potentiometers adjusting the thresholds. See picture 2.

Step 8: Program Design

The ESP32 program is an essential part of the project. In particular, it enables current and voltage measurements to determine the battery's SoC and act as a bridge between the ESP and the mobile application. As for the development environment, we used the Arduino IDE, which can integrate the ESP32 board.

At system startup, we initialize serial communication for debugging and sending logs through the USB port. We then initialize Bluetooth communication to enable the phone to connect to the system. We end the Setup function by initializing the memory and reading the previous SoC value stored in EEPROM. This saves the information and restore it even if the system has stopped.

We now move straight on to the Loop function.

We start by checking for Bluetooth reception using the "SerialBT.available()" instruction. If this is true, then we store the character read with SerialBT.read() in a variable, and then add this character in a string until the "\n" end-of-string symbol appears. Each new character is added to the string at each iteration of the loop.

Then, if the string is "data", we assign in another string the SoC value followed by the separator ":", then the current voltage at the battery terminal, using the inverse divider bridge to find the value, always followed by ":", and finally the battery percentage of the on-board system. However, if the first string is "reset", we set the SoC to set the SoC to 100% and write its new value to the EEPROM memory.

The advantage of writing to this non-volatile memory is that it retains the state of charge even if our system encounters a problem (reset) or shuts down (battery is empty or manual switch-off).

We then use the logic signal at the output of the comparators to determine whether or not current is being drawn, and its sign (+ or -). If so, we'll measure the current and store its value in a table every 5 seconds.

We fill this table with 20 values, then calculate the state of charge and finally empty the table. These values are actually derived from from the average of a dozen currents measured over a period of 100ms to obtain a more stable current value. 

We repeat these operations indefinitely.

To calculate the SoC, we use the formula described in step 1. To calculate the current integral, we retrieve the table containing the current samples and use the trapezoidal method to calculate the integral between two current values.

So the total current integral is the sum of the integrals per sample over a global period period of 100 seconds. We then divide this value by the load over the same time interval Q*3600*100. Finally, subtract this value from the previous SoC to obtain the current SoC. Once the SoC has been determined, all that remains is to save this value in the EEPROM of the ESP32.

Step 9: Application Design

Comming soon...

Step 10: Thanks

This project was realized within the framework of the Master 1 EEA-ESET of the University Toulouse 3 Paul Sabatier.

It is the work of three students :

  • Anna Ernst
  • Thomas Dehee
  • Alexandre Barret

Supervised by Vincent Boitier.