Close
0%
0%

Calorie Restricted Phone Charging

Stop overcharging your phone battery overnight. This puts your lipo batteries on a strict diet by limiting the mAh passing over a USB cable

Similar projects worth following
Ever since buying a smartphone with an unremovable battery, I've become acutely aware of how overcharging the internal lithium polymer battery could prematurely shorten its lifespan. I would always plug in my tablet and phone just before going to bed, so that they are charged to 100% when I wake up the next morning. Various articles on the Internet state that this practice is not optimal for lipo battery health. My phone and tablet might charge fully within a couple hours and thus may spend several more hours above 80% capacity per day. Some guidelines advise that I should aim to keep the lipos below 70-80% and above 20-30% - different sources suggested slightly differing safety ranges.

I tried plugging my USB charger into a timer switch but it was difficult to work out how much time to allow my phone to charge so that it halts just short of 80%. What I needed was a timer switch that shut off not after a pre-set duration had passed, but after a pre-set amount of milliamp-hours


  Assembled from my Parts Bin

I'm using a MAX471 to measure current passing through a USB charge cable. This is an analog current sensing chip. I bought this a few years ago off EBay when I was evaluating various current measuring modules for a project to measure 18650 battery capacity. Although this one is not highly accurate (especially when one considers the accuracy of the analog output is limited by the ADC resolution in the microcontroller) it is perfectly adequate for this application where I'm only interested in a rough mAh count.

I could have used a standard ATMEGA328 Arduino but I was interested in keeping this build fairly compact so opted for an ATTiny85. I bought a small stash of about a dozen of these from Cool Components for use in LED and Neopixel projects. The current measurement is made using analogRead() which depends on the absolute voltage supply rail which might vary from 4.5 to 5.3 volts depending on what I plug this into. I tried using the ATTiny85's internal 1.1V reference but this would limit the max current that can be measured. So instead I'm using a TL431 to provide a 2.5V reference on another ADC pin to correct for any variations in VCC. This precision voltage reference was included in an assortment of through hole transistors I ordered from China.

In order to convert the current measurements into a mAh count, I need a fairly accurate clock. Although the ATTiny85's internal RC oscillator can drift significantly than when using a clock crystal, the error tends to be consistent and fairly stable over a modest temperature range. So this device will need to be calibrated against a USB charge doctor.

Power to the phone is switched on and off using a IRLZ44N logic-level N-channel MOSFET. I had bought a wide range of MOSFETs from Ebay and Rapid Electronics for use in motor controller, robotics, and high powered lighting projects. A quick test showed that it could switch the USB charger power when connected on the low side.

The TM1637 4-digit module is used to display the measured current and the mAh count down. This module is a clone of the Grove 4-digit LED display by Seeed Studio. The TM1637 can actually support more LEDs than those on the module, as well as up to 16 buttons. So this is great for making efficient use of the limited GPIO pins on the ATTiny85. I bought these as an add-on item on an Amazon order. I later discovered that the TM1637 wasn't being used to its full potential on these dirt cheap modules and so ordered a few more in a variety of LED colours and sizes from TxHang Electronic (aka alice11o1983)

Other assorted components - USB charge cable from Poundland, micro USB breakout from Ebay, USB port (female) from a broken Powerbank, double throw switch from battery pack of a Christmas decoration, wires collected from discards by BT Openreach engineers working on the phone cabinets near home.

Lipo longevity research: https://batteryuniversity.com/learn/article/how_to_prolong_lithium_based_batteries

charge_counter.ino

Arduino IDE project file for the ATTiny85 that limits mAh charging

ino - 2.42 kB - 05/10/2020 at 23:39

Download

TM1637.cpp

Modified Grove 4-digit library to support keycan

x-c++src - 5.76 kB - 05/10/2020 at 23:39

Download

TM1637.h

Modified Grove 4-digit library header file - keyscan support

x-chdr - 2.76 kB - 05/10/2020 at 23:39

Download

  • 1 × MAX471 module Analog current sensor - this will be used to estimate current passing through a USB charge cable
  • 1 × TM1637 4-digit display module Clone of the Grove 4-digit display from Seeed Studio - this can be modified to add more LEDs and buttons
  • 1 × ATTINY85 microcontroller Can be programmed using Arduino IDE and an ASP USB programmer
  • 1 × IRLZ44N Discrete Semiconductors / Power Transistors and MOSFETs - N-channel, logic-level
  • 1 × USB charge cable

View all 7 components

  • Hooking up the Brain

    bornach05/09/2020 at 18:44 0 comments

    I had intended the solder the modified TM1637 to the microcontroller's strip board however I later discovered that the USBTinyISP failed to work. The ICSP shared pins that were also used by the TM1637.  I did manage to get the USBAsp ISP to work however I thought it would be better to allow the 4-digit module to be plugged in or removed as needed. I could then use this module in other projects.
    Luckily I had bought an assortment of female header pins from Ebay that also included a 4x1 size which saved me from cutting a longer one.

  • Protoboard? PCB? Lolly Sticks!

    bornach05/09/2020 at 18:32 0 comments

    I do have spare protoboard, however this build is mostly hooking together other modules and breakout boards with very few through hole components. So I thought I'd save my scarce resources by using crafting lolly sticks to hold everything together..

    This is enough to test whether the concept would work before I solder the microcontroller and program it.

  • What USB connectors to support?

    bornach05/09/2020 at 18:24 0 comments

    Chopped a Poundland USB cable so that the MAX471 can measure the current passing through it. I'm a bit worried about the thinness and the small number of strands of wire being used to charge a phone.

    I have a USB charger that outputs directly to a male micro USB - it does not provide a female USB port to plug this into. So I've exapanded the range of charging options this will support

    I'll be able to plug my USB charger into the female micro USB breakout. And I can plug a USB-C charge cable into the female USB port - I recycled this from a broken Powerbank.

  • Modifying the TM1637 Module

    bornach05/09/2020 at 17:23 0 comments

    The TM1637 4-digit module was modified to add 3 buttons and 3 more indicator LEDs


    It is easier to solder bodge wires to the pins of the 7-segment LED display instead of the pins of the TM1637 IC.


    For more details on modifications to these TM1637 4-digit modules see this video I made a couple years ago

    See also this video on the Maxint R&D channel:

View all 4 project logs

Enjoy this project?

Share

Discussions

Marcus Szolkowski wrote 05/12/2020 at 04:42 point

Don't let me stop your fun, but I achieved similar goals to this project with some off the shelf software and hardware.  I used a cheap WiFi smart plug flashed to tasmota, and then installed Tasker on the phone.  A Tasker profile then sends a http "power off" signal to the smart plug once it reaches 95% full.  Been working quite well for a few weeks now.

  Are you sure? yes | no

Daniel wrote 05/10/2020 at 03:22 point

It really sucks that phones do not support charge limiting by default. My Sony phone has something built in where you set a 'target time' for charging. It then only charges to 90% and charges the last 10% right before the target time. But of course you could unplug it before. On other phones, the only option to get this is by rooting.... But of course having the battery lasting longer is not entirely in the interest companies making phones. So this is a really cool project ;)

A few technical remarks:
You don't really need the external reference, the ADC can also be switched to measure the voltage of the internal 1.1V reference while still using VCC as its own reference. So you could still use your compensation algorithm. But the technically most correct way to solve this would be a voltage divider at the ADC input and then you can run the ADC of the internal ref voltage.

Also, the ATTiny85 has really cool differential ADC inputs with an integrated x20 gain. So you could just use a shunt directly to measure the current. But of course if you have a spare current sens module, why not use it.

When controlling a mosfet with a GPIO it's good style to add a pull-down resistor to the gate. This avoids that the gate is floating freely when the controller is in a reset state or stuck somewhere before initializing the GPIOs.

  Are you sure? yes | no

bornach wrote 05/10/2020 at 16:51 point

I did try the set ARef to the 1.1V reference but I still wasn't getting consistent values returned by analogRead when trying a variety of USB chargers. There is also supposed to be a 2.56V reference which I wasn't able to access using the attiny library for the Arduino IDE.

Thanks for the idea on using the shunt. A selection of precision shunt resistors is one thing my spare parts bins currently lack.

I shall add the suggested pull-down resistor to the MOSFET gate

  Are you sure? yes | no

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates