Battery Care

Introduction: Battery Care

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 a...

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:

HC-05 bluetooth module :

https://amzn.to/2RkQW9y

https://www.banggood.com/custlink/G3vDs0Cg5k

Relay module :

https://amzn.to/30l3rpF

https://www.banggood.com/custlink/3GD3nBpeim

ATtiny85 microcontroller:

https://amzn.to/375oCP2

https://www.banggood.com/1Pcs-Original-ATTINY85-20...

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

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 the computer's sleep mode. However, I have not been able to establish the same behaviour during the 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: Shutdown Script

To overcome the problem of disabling the module when turning off the PC, I used a script.

In fact, I even used 2. Indeed, when the PC is turning off, the script BatteryCare_discharge.bat is executed. This last one will itself launch a ps1 script which sends the character 'd' on the communication port.

To set up a script to run when you shut down your PC, follow these instructions:

Enable the execution of PowerShell scripts :
Open PowerShell in admin: set-executionpolicy unrestricted

win+r gpedit.msc : In User Configuration/Window Settings/Scripts/LogOFF

Press add then browse and copy the 2 files in the open folder and select the .bat file.

Yes it's true, it's not the best way to do it... but it's the fastest I've found. If you find a way for the program itself to disable the charge, let me know.

These scripts are available on the github repository : https://github.com/David-LETINAUD/BatteryCare

Step 5: 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, I will try to find a more elegant way to disable the charge when the PC is turned off. In addition, it is surely 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 6: Sources

Be the First to Share

    Recommendations

    • Trash to Treasure Contest

      Trash to Treasure Contest
    • Raspberry Pi Contest 2020

      Raspberry Pi Contest 2020
    • Wearables Contest

      Wearables Contest

    2 Discussions

    0
    Penolopy Bulnick
    Penolopy Bulnick

    4 weeks ago

    Very nice job on your first Instructable :)

    0
    Létinaud
    Létinaud

    Reply 27 days ago

    Thanks, I'm glad you like it =)