Introduction: Battery Drainer

About: I love doing hobbyist projects involving electronics, 3D printing and CNC.

This project describes hardware to safely discharge batteries to a user-chosen level.


Project source files, including code, schematics and PCB layouts can be found here: https://github.com/mattwach/battery_drainer


Why?


Before I started flying RC models (many years ago), the concept of managing batteries was off my radar. While in the hobby, it became clear that proper management makes a big difference in how long batteries last and how much power they will deliver.

Storing lithium ion batteries fully-charged or fully-drained causes them to degrade permanently. It's much better to store them in a half-charged state.

Since lithium batteries are used basically everywhere (phones, tools, laptops, cars, on and on), being aware of these concepts can help you keep more of your devices running longer and more healthy.

Many non-lithium batteries have "memory effects" and can benefit from a deep discharge now and then. See your particular battery type for details on how to maintain/restore it.

Other applications for discharging include testing battery capacity and preparing it for disposal.


Caution


Following anything written in this document is at-your-own risk.

Batteries are energy storage devices and thus carry an inherent risk. If you are not familiar with the battery type you are working with, take a few moments to educate yourself on recommended handling practices.

When working with an untested draining device or new batteries, I suggest extra caution. For example doing initial testing outside on concrete or in a fire pit.


This design incorporates a protection fuse. I recommend using the smallest-sized fuse that meets your requirements. If anything goes wrong with the firmware, a hardware component, or the hardware build, the fuse will limit the maximum current that can flow. Starting with a small fuse and upgrading it later could be a good initial verification strategy.


Pre-existing Market Solutions


If you look up "LIPO Battery Discharger" on Amazon or similar, you will find a variety of products. These might work for you but note that the project I am describing has some advantages over what you can buy:

  1. Higher maximum power. The unit I built is running great at 350W. The components I chose are specified to 460W 30V and 30A. Since you are building it yourself, you can choose a transistor/cooling combo that supports the power dissipation you need.
  2. Support for "safe" multiboards. My project has a diode-protected multiboard that allows you to safely plug in multiple batteries that are at different discharge levels. This protection requires the discharger account for the voltage drop across the protection diodes, which commercial charges do not typically do.
  3. Support of 1S packs. Many chargers have a 2S minimum.
  4. Lots of customization. My project lets you customize voltages and create special profiles. For example, I have one that takes packs down to 4V/Cell, which is useful for packs that I want ready-to-use in worklights and tools.
  5. Detailed status. The OLED of this project gives lots of information during the discharge which can help you gauge the health of the pack.
  6. Support for more battery types than just LIPO, due to the extensive customization ability.

Supplies

For convenience:


  1. Here is a loaded digikey cart with most of the parts added. I suggest bumping up the numbers on some of the parts to get lower-per-unit costs and have some spares. For example, I would personally bump up each resistor count to 10, but it's up to you of course.
  2. From Amazon, I purchased
  3. 2 120x69x36mm heatsinks
  4. 128x64 OLED (comes with 2 but the project only needs one)
  5. a 120mm case fan with PWM pin.
  6. XT-60 Male/Female PCB connectors


If you prefer, here is an itemized list of the same parts (Prices sampled in Jul, 2023)

  1. 1x 12V Regulator: MC7812BDTG ($0.66)
  2. 1x 3.3V Regulator: TPS70933DBVR ($1.34)
  3. 2x 3V Reference: LM4040DBZ-3 ($1.14)
  4. 2x Capacitor 0805: 1u ($0.30)
  5. 4x Capacitor 0805: 10u ($0.54)
  6. 1x Zener Diode: 1N5363BG ($0.47)
  7. 1x Fuse: 40A Glass ($0.42) I suggest testing with something smaller.
  8. 3x NPN Transistor: MMBT3904 ($0.39)
  9. 1x OLED 128x64_OLED ($5.00)
  10. 3x P MOSFET: IRLML5103TRPBF ($1.71)
  11. 1x PI Pico ($4.00)
  12. 1x Power P MOSFET: IXTH90P10P ($11.65)
  13. 3x Power Resistor: PWR220T-35-R400F (0.4 OHM) ($11.28)
  14. 5x Push Buttons ($0.70)
  15. 3x Resistor: 2.2k ($0.30)
  16. 1x Resistor: 22K ($0.10)
  17. 6x Resistor: 1k ($0.60)
  18. 2x Resistor: 6.8k ($0.20)
  19. 3x Resistor: 47k ($0.30)
  20. 1x Resistor: 10 ($0.10)
  21. 1x Resistor: 1.5K ($0.10)
  22. 2x Resistor: 100 ($0.20)
  23. 1x Resistor: 100k ($0.10)
  24. 1x Temperature Sensor: MCP7901 ($0.53)
  25. 2x Heatsink: 120x69x36mm ($25.98)
  26. 1x 120mm PWM case fan ($5.99)
  27. 1x XT-60 Male/Female PCB connector ($8.99)

Total of the above $83.63


Some of the parts, like the fan, you may already have while others, such as the XT-60 connectors, you might want to change up according to your preference.


Advanced: The above design should be good for 26V, ~25A and 350W - The specified limit is 30V, 30A and 462W but I have not pushed mine to that limit. If you need more power, the areas to look into are the heatsink, Power P MOSFET and Power Resistors. If you need less power, you could also opt to replace these same components with less expensive variants with lower specifications. If you need more voltage (say for 8S packs), you'll need to change the Zener diode for a larger one. You'll also need to review the schematic and check the voltage limits on everything connected to the battery, especially the max Vgs of each P FET transistor.

Step 1: Using

The unit has four UI buttons: On, Off, Select and OK.

When the device is initially powered up, it will display the current voltage, cell count and the target voltage. It also shows a scrollable list of profiles to choose from. The user chooses a profile with "Select" and presses "OK" to start discharging. During discharge, the following status information is displayed (the ghosting in the image is because the unit was actively updating during the photo).

Note: Default charging parameters are for LIPO packs 1S-6S. If you are discharging something different, you'll need to create a profile for it.

Information shown includes:

  • Time running
  • Number of mAH discharged so far
  • Battery voltage and cell count
  • Target voltage
  • Discharge Current
  • Power (Voltage * Current)
  • Temperature
  • FET power level %
  • Fan power level %

If the FET power level is limited < 100%, then the parameter that is limiting the power is highlighted as inverse text. In the example above, this limit is overall power draw. A lower-cell-count battery might hit the max current instead. A small battery might be limited by voltage sag. A hot day might introduce a temperature limit. All limits are user configurable - but you'll need to be aware of what your built hardware can handle and test higher limits with due caution.

When the discharge is complete, the unit will show some stats for a configurable amount of time before automatically shutting down.

After shutdown, the unit takes very little power (a few microamps) to avoid further unintended drainage of smaller packs.


Configuration


Profiles can be edited by connecting a computer to the unit via USB and starting a terminal program. On my Linux laptop, I used:

minicom -b 115200 -P /dev/ttyUSB0

Refer to the dedicated configuration guide for details about how to configure settings, calibrate the device and create/edit profiles.

Step 2: Schematic

Above is a snapshot of the schematic design. The project's KiCAD design may have some additional updates.

Here is an early Falstad simulation that gives a basic idea of how the circuit works:

https://tinyurl.com/2qg4xwyj

There is much going on here. Starting at the next step, I explain the circuit design in detail.

Note The schematic shows four PFETs in parallel. The unit I actually built uses a single high-power FET instead. I think that four PFETs would still work but have not tested it. The main risk of using 4 is that they will be unevenly loaded to the point where one of them is damaged. I do believe that they will be unevenly loaded at lower currents but not after the current ramps up enough to matter. Again, I have not tested this assumption. Using a single high-power FET is my recommendation if you want to play it safer.

Step 3: Optional: How It Works - Power Control

This step is optional educational material. Feel free to skip it if you want to get to the building steps.


Power Dissipation


Falstad model


The second image shows a set of 4 P-Channel MOSFETs connected in parallel. More or less could also work. As mentioned previously, the unit I actually built uses a single high-power FET instead.

In most applications, FETs are used as switches by setting the Vgs voltage as high or low as practical. In this application, Vgs is run in a middle setting, which limits current and creates power loss as heat - exactly what is needed for this application. This FQP27P06 datasheet graph (third image) shows how changing Vgs limits the current for that transistor. The falstad link above will let you try it yourself.


Controlling Vgs


Falstad model

To achieve the target Vgs for the FETs, the subcircuit shown in the 4th image is used.

The main element here is a 10uF capacitor on the right side of the subcircuit. The voltage across this capacitor is the gate voltage that each FET will see.

Filling the capacitor is a 5k resistor, R16. When the capacitor is sufficiently charged (in about 50-100ms), the FETs will be turned off.

The two BJT transistors (Q6, Q9) are used to drain the capacitor. The one on the left is a "slow" drain and the one on the right is a "fast" drain. The size of the resistors (R17 and R20) determines the drain speed. A microcontroller feeds in a PWM signal to open/close these transistors. The duty cycle of this PWM signal determines how much current is pulled on average and the frequency of this PWM signal determines how smooth/stable the voltage will be.

The reason for two drains (verses one) is to support a larger voltage range. At lower voltages (4V), the FAST drain circuit is needed to get the Vgs lower than the SLOW drain can achieve. For higher voltages (25V), the SLOW drain provides better control resolution. Depending on the FET you go with and voltage range you want to support, a single drain may work fine.

In the power-on event, we can assume that SLOW and FAST are initially not driven at all (high Z). In this state the two 50k pulldown resistors (R14, R18) turn off Q6 and Q9 which leads to the FETs naturally turning off (safety feature).

The 100K pull down resistor (R25) slowly drains the capacitor so that it at a known voltage (0V) when the unit is unplugged and idle.


Inrush protection

Falstad model

The 5th image show the inrush protection circuit. On initial battery plug-in, the 100ms or so it takes the capacitor (C4) to charge via R16 could allow a high current to pass through the FETs for that time period. This is mitigated by the following inrush protection circuitry.

The way this subcircuit works is that we have another resistor, R13, which is only 10 ohms. This one has the capability to fill C4 very quickly (in a handful of microseconds). The downside is that it's too fast to leave it open all the time.

Thus we have a FET, Q5, that can turn R13 on and off. On initial plugin Q5 is on (thanks to R8). When the user presses the "ON" button, the same voltages that powers the microcontroller also turns Q5 (and thus R13) off, disabling the circuit.

Step 4: Optional: How It Works - Sensors

This step is optional educational material. Feel free to skip it if you want to get to the building steps.


Current Sense


Falstad model

Refer to the first image. One of the four ways the microcontroller decides where to set Vgs is by monitoring the current flowing through three resistors (R22-R24). The other three are voltage, power, and temperature. An ADC within the microcontroller measures the voltage across these resistors then uses Ohm's law (I = V/R) to determine the current.

Resistor values were chosen for a full 3V swing at 30A of current. This choice allows us to use the full 12-bits of ADC resolution for good accuracy. The downside is that 3V * 30A = 90W, which is a lot for a resistor to dissipate. To support this, I chose 3 35W 0.4 ohm resistors connected in parallel for a total dissipation capability of ~100W and an equivalent resistance of 0.133 ohm. Potentially wasting this much power on a current measurement would normally be frowned upon but in this application it's actually helping take some load off the main power FET.

A Zener diode (U5) is used to protect the ADC of the microcontroller in the event that the divided voltage is too high (> 3V). This is a protection feature that serves no function under "normal" operating conditions.



Voltage Sense

Falstad model

Refer to the second image. The microcontroller monitors the overall battery voltage to determine a sag value and to determine when the drain process is completed.

The circuit is a simple voltage divider with a capacitor to help stabilize the reading.

Battery voltage sags while under load. Remove this load and the voltage raises back up. We want to know the "unloaded" voltage so that we know when draining is complete and also so we don't pull too much current. We measure this unloaded voltage by periodically turning off the FETs (for one second every 10 seconds) and measuring the "unloaded" voltage at this point.

The voltage at R9 is not exactly the battery voltage as it has to pass through a a diode and FET. The software provides a calibration value to account for this drop.


Temperature Sense


Refer to the third image. A temperature sensor is placed against the heatsink and as-close-as-possible to the Power FET to monitor the FET temperature. This measured temperature can be used to control a cooling fan (described below) and reduce the current draw as needed.


ADC reference


Refer to the forth image. When using a microcontroller-provided ADC, one can typically choose from several different sources for the calibration with the internally-generated 3.3V source as the most convenient. The downside of choosing this source is mediocre accuracy.

This design uses the alternate ADC_VREF input with a LM4040 voltage reference to allow for more accurate measurements.





Step 5: Optional: How It Works - ON / OFF

This step is optional educational material. Feel free to skip it if you want to get to the building steps.


Falstad model

The battery drainer is designed to draw nearly zero power (outside of parasitic losses) after you turn it off or it turns itself off. This is implemented with the following circuit:

The Q2 FET is key. It determines if the microcontroller gets any power. Q2 is off by default, turned off by R2. There are two ways to turn it on:

  1. If the user presses SW5
  2. If the microcontroller activates Q1 via "EN". The microcontroller does this as soon as it can (in a split second) and holds it high until the microcontroller decides that it is time to power down OR the user presses the "OFF" button which forces Q2 off.

Step 6: Optional: How It Works - Misc

This step is optional educational material. Feel free to skip it if you want to get to the building steps.


OLED connection


Refer to the first image. The design breaks out an I2C 4 pin header that is typical for an I2C OLED. A 128x64 design is the intended hardware but anything that supports I2C could be supported with appropriate firmware modifications.


Fan connection


Refer to the second image. This sub circuit supports a PWM-based fan controller.

The circuit is just a 12V linear regulator with supporting capacitors. The connections support "PWM" style PC case fans which are specified to accept a 25Khz PWM signal on pin 4.

A flyback diode is needed when powering generic motors but is unlikely to be needed here as PWM-controlled motors usually already have one in the motor control circuit. You can add one for peace-of-mind if you choose.


PI Pico Microcontroller


As is typical, a microcontroller orchestrates the operation. Here I chose a PI Pico because it is inexpensive and quite capable. It's main downside is the lack of a low-power sleep mode, but the power cutoff circuit explained above compensates for this shortcoming.

A little bit on the tasks the Pico must attend to:

  1. When the unit is powered-up, the Pico must raise the EN pin to keep the power on
  2. It must lower the EN pin when it is time to shutdown.
  3. It controls the dissipation rate of the main FETs via PWM signals on the SLOW and FAST pins.
  4. It measures current by ADC decoding the voltage at the CUR pin.
  5. It measures the battery voltage via an ADC.
  6. It provides an output display via SDA and SCL
  7. It controls the fan speed via the FAN pin.
  8. It monitors the buttons Select and OK buttons.


Protection Fuse


We also have a protection fuse to help protect against software bugs or other unexpected problems. More protection would be offered if the fuse were right at the battery input but this would introduce a further temperature-dependent voltage drop that would throw off the voltage measurement. The "unprotected" components are the digital logic which should be low current draw barring a physical issue with the board (< 100 mA)

Step 7: PCB

The PCB layout is above. Some notes on the layout:

  • The dimensions of the board are 122 x 88 mm (4.8 x 3.5 inches)
  • Power FETs and resistors are aligned so that a single (large) heatsink can service all of them
  • Large traces are used in the higher current areas.
  • Large vias are used to try and distribute current and reduce hotspots.

I went with thicker 2oz copper when manufacturing this board to handle the potentially-large current. I tried several different companies and saw the best price with PCBWay. My boards arrives in just 5 days and I am happy with their quality.

Here are some images of the board, unpopulated and with most components added. To add the components, I used a hot plate that I got off Amazon for just $13. It works really well!

Note that the completed board had a bug where I forgot to add a power-cutoff to the fan. If not corrected, this could have caused the fan to draw ~5-10 mA even after charging is completed. The fix was to add a PFET (green wires). The board design now incorporates the FET on the board.


Daughterboard


You could plug a single battery into the unit or use a parallel adapter. Safer than a parallel adapter is a board with integrated protection diodes. This will allow batteries of different charge levels to be plugged in without the concern of large current flows due to unequal discharge levels. The firmware can account for the drop across the diodes after the user calibrates the board.

A bundled example provides connection for 6 XT-60 packs.

Step 8: Firmware

If you don't want to build the firmware yourself, there is a prebuilt version here.

The firmware, battery_drainer.uf2, is in a standard PI Pico format. One way to download it is to mount the Pico as a USB drive and copy over the file. Refer to beginner PI Pico tutorials for more information, such as this one.

If you do not wish to build the firmware yourself, feel free to skip to the next section.

The firmware is built using a script that uses the official Pico build system. To run it, you execute bootstrap.sh which exists in the src/ directory.

./bootstrap.sh
cd build
make -j

Let's take a look inside the file:

$ cat bootstrap.sh 
#!/bin/bash

if [ ! -f lib/pico_uart_console/CMakeLists.txt ]; then
git submodule init
git submodule update
fi

rm -rf build
mkdir build
cd build
cmake ..


All commands are standard git and cmake operations which you can execute individually if you prefer (or are running in an environment where executing bootstrap.sh directory will not work).

Step 9: Case Design

For cooling, I ended up going with 2 120x69x36 mm finned alunimum heatsinks which cost me $13 each for a total of $26. These work great but having to use two is a bit inconvenient, due to the vertical seam in the center. I tapped holes in these heatsinks, both for mounting the board and for holding the FETs, resistors, and temperature sensors securely to the heat sink (with the aid of thermal paste to complete the thermal connection).

On the backside of the heatsink, I have a 120mm fan which blows air into the fins. The microcontroller controls fan speed based on current temperature and power dissipation.

At first everything was held together with wires. I wan't sure if a 3D printed solution would be able to tolerate the dissipated heat. But after testing the unit and doing official (temperature probe, IR camera) and non official measurements (finger touch), I determined it would probably be ok.

I ended up designing a 3D printed case using Open SCAD.

Design files are included with the project here. Ready to print models are here.

After many uses, the case is holding up fine with no signs of warping. Note that I used PETG for the print as PLA has a tendency to "creep" over time, even at slightly elevated temperatures.

The front plate is acrylic. I used a 3018 CNC machine to cut it out. Printing a cover or making something by hand are of course other options.