Introduction: Battery Care - the Ultimate Battery Saver

About: Fascinated by embedded systems, I chose the training in Electronics and Industrial Computing at the INSA in Rennes. I study industrial computing and more precisely programming languages, but also computer arc…

A few years ago, I bought a new PC but I didn't want to make the same mistakes as with my old one.
Like you certainly do, I used to plug it in all the time. As a result, after 2 years, the battery lasts only half an hour and after 3 years, I could barely disconnect it for more than 5 minutes. So I did some research on the subject, and it seems that there is a simple solution.

Supplies

Step 1: The Study

In particular, to extend the battery's life when charging, extreme cycles should be avoided. It is therefore preferable to make small recharges regularly.

For example, CADEX, a company that develops battery management tools, conducted a study on this subject that resulted in the following results.

(cf table)

The number of discharge cycles corresponds to the lifetime of the battery. (The number of cycles of a rechargeable battery indicates how many times it can be completely discharged and recharged before it fails or loses its storage capacity.) According to the results, changing from a 100% to 40% depth of discharge would increase the battery life by a factor of 6. It is also strongly discouraged to completely drain or fully charge the battery.

Thus, the solution proposed by the CEO of CADEX (a company that designs battery management tools) is to charge the battery when it reaches 40% and let it charge up to 80%. But well.... in the long term, having a constant eye on your battery to keep it charged between 40 and 80% is not easy, not to say impossible. That's why I developed BatteryCare, a module to disconnect or reconnect the power supply to the PC. It is controlled via Bluetooth by a program that monitors the battery level.

Step 2: Hardware & Microcontroller

Hardware

The system is rather simple, it mainly consists of an ATtiny85 microcontroller, an HC-05 Bluetooth module and a 230V relay. In addition, there is a 5V power supply for the electronics. The male and female sector cables can be recovered from an extension cord.

Microcontroller

The code is also very simple, since it is only a matter of establishing a serial connection and then controlling an output in the "high" or "low" state depending on the byte received. Here, 'c' is for charge and 'd' for discharge.

#include "SoftwareSerial.h"

#define RELAY_OUTPUT 4

const int rx = 3; const int tx = 1;

SoftwareSerial mySerial(rx, tx); int i = 0; char buf[12]; int inByte = 0 ;

void setup() { pinMode(rx, INPUT); pinMode(tx, OUTPUT); pinMode(RELAY_OUTPUT, OUTPUT); digitalWrite(RELAY_OUTPUT,HIGH); // turn the RELAY off mySerial.begin(9600); }

void loop() { if (mySerial.available() > 0) { inByte = mySerial.read(); if (inByte == 'c') { digitalWrite(RELAY_OUTPUT, LOW); // turn the RELAY on } else if (inByte == 'd') { digitalWrite(RELAY_OUTPUT,HIGH); // turn the RELAY off } } }

Here, I use the "SoftwareSerial" library because the ATtiny85 doesn't have hardware serial communication. However, if you are using an arduino board, you can simply use the standart serial port.

This program is available on the github repository : https://github.com/David-LETINAUD/BatteryCare

Step 3: PC Software

The basic principle of the program is to send the character 'c', to activate the power supply and to send the character 'd' to deactivate it. These commands are determined by selected thresholds.

For Bluetooth communication, it is first necessary to pair the HC-05 module with the PC (parameters>bluetooth devices and others>, add a bluetooth device or another device) the code requested is either 1234 or 0000.
The already compiled program is available on the github repository : https://github.com/David-LETINAUD/BatteryCare/tree...

It is necessary to keep the .exe in the same folder as the .dll. It is also possible to launch BatteryCare at startup by placing a shortcut to the .exe in : C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp

I developed this program in VB.net, while taking care to simplify the user interface as much as possible. Although fully functional, it can be improved.

This program turns off the power when it detects sleep mode or computer shutdown.

To facilitate the connection of the module at startup, I created a small config file called "config.txt", it contains the number of the serial communication port that the computer uses to transmit information via bluetooth, as well as the charge and discharge threshold.

Its content is in the form: "COM4 40 80".

Feel free to suggest improvements even with another programming language.

Step 4: Conclusions

I have been using it with my PC for more than 3 years now and I am very satisfied with it. I do not feel any significant decrease in the capacity of my battery.

In the end, the results are conclusive. However, there is room for improvement.
In particular, it may be possible to disable the battery charge in a software way. This would make it possible to dispense with the relay module.

Beyond this use, it is possible to use this module to control any kind of electronic device such as a fan, a light or even to control the charge of a smartphone.

The whole project is available here : https://github.com/David-LETINAUD/BatteryCare

Feel free to comment to share your experiences and knowledge, thanks.

Step 5: Sources