View All Posts
Want to keep up to date with the latest posts and videos? Subscribe to the newsletter
HELP SUPPORT MY WORK: If you're feeling flush then please stop by Patreon Or you can make a one off donation via ko-fi

Learn how to test and safely use free batteries in DIY projects by building a homebrew battery tester with an ESP32 and a simple circuit. Find out how to make batteries safe by adding protection boards, and see the results of testing battery capacities and discharge curves.

Related Content

[0:00] The Bigclive pixies have been kind to us and we’ve scored a couple of free batteries.

[0:05] Let’s test them out and then we’ll make them safe to use in our projects.
[0:09] Our first battery is still lodged inside its pretty grotty container.

[0:13] The top has already been lost and we can just pull the base off with some pliers.
[0:18] I’m just going to push the contents out with a screwdriver.

[0:22] Don’t worry I did check that I’m not poking the battery.
[0:25] It’s pretty disgusting and it is covered in the special magic fluid.

[0:30] I’ll remove all the horrible bits - at this point,

[0:32] I started to regret not wearing rubber gloves and went for a bit of a handwash.
[0:37] Snipping off the atomiser I did get a bit of a fright and thought for a brief moment that

[0:42] the battery was about to go up in smoke, but it was just protesting a bit at being chopped off.
[0:48] Let’s just watch that again in slow motion.
[0:58] With all the junk removed we can tack on a couple of jumper wires

[1:02] and connect it up to this little charger board.
[1:04] I’m also putting it in a metal dish just in case I need to carry it outside and dump it.
[1:10] These charger modules use a TP4056 chip

[1:14] and they also include a DW01A battery protection IC along with a duel MOSFET.
[1:20] The schematic for both the charging and battery protection circuits

[1:23] are pretty much an exact match for what we see on their respective datasheets.
[1:28] On the charging side of things, we have the two LED indicators for charging and fully charged

[1:33] and we have the resistor for programming the charging current.
[1:36] My PCB has a 1.2K resistor which according to the datasheet will give us a charge current of 1A.
[1:43] Talking of PCBs - this seems like an opportune moment to talk about PCBWay who sponsor the

[1:48] channel. If you’re in the market for a PCB then check them out. There’s a link in the description.
[1:54] After an hour or so the battery charging is complete.
[1:58] Now, the battery says it’s got a 500mAh capacity. I’ve hooked it up

[2:02] to this battery capacity checker and we’ll let it discharge. Assuming the capacity is correct

[2:08] this should take around one hour as it’s being drained at just over 500mA.
[2:14] An hour has passed and it’s fully discharged. Amazingly it’s bang on 500mAh!
[2:21] Let’s have a look at the second battery. This one seems to have

[2:24] been run over and the outer casing has been completely destroyed.
[2:28] Initially, I thought that the battery had actually been squashed

[2:31] but comparing it with the first battery this is just the shape they come in.
[2:36] Checking it with the voltmeter we get around 3.7 volts.

[2:39] So this battery is also not completely dead.
[2:42] Once again I’m stripping off all the nasty bits and tacking on some wires.
[2:47] With it connected up to the charging board we get

[2:50] up to a healthy 4.2 volts before charging cuts off.
[2:54] Hooking it up to our capacity testing board

[2:56] this second battery comes in at 566mAh - another great result.
[3:02] Looking at this battery tester got me thinking.

[3:05] It’s not doing anything clever - we should be able to recreate it with parts we already have.
[3:10] There’s a 0.02-ohm shunt resistor along with an op-amp for sensing the current.

[3:16] And there’s a MOSFET for switching the load into the circuit.
[3:19] Under the display, there’s a seven-segment driver and an MCU.

[3:23] I’ve linked to a video in the description that has a teardown of this device along

[3:27] with some details on why it’s not very accurate.
[3:31] All the board is really doing is measuring the current and then integrating that over time until

[3:36] the battery voltage drops below a threshold. This gives us the Ah capacity of the battery.
[3:42] I’ve got a whole bunch of ESP32s lying around including this one with a nice

[3:47] colour display so I’ve got something we can use to show the results on.
[3:50] The ESP32 also has a built-in Analog to Digital Converter

[3:55] so we can easily measure the battery voltage.
[3:57] Since we know the resistance we are discharging the battery through

[4:01] we can calculate the current and sum that up over time to get the Ah value.
[4:06] I’ve sketched out this very simple circuit - the ESP32 only goes up to 3.3 volts

[4:12] so I’ve got a simple voltage divider of two 10K resistors

[4:15] to halve the maximum 4.2V that the battery will output down to 2.1V.
[4:20] To discharge the battery I’ve got a 5W 7.5-ohm resistor

[4:25] and I’m switching this into the circuit using a power MOSFET.

[4:28] This will let us switch off the battery discharge when the voltage drops too low.
[4:33] The battery will continue discharging through the 20K divider,

[4:37] but we’re not going to be leaving it connected forever so this should not be a problem.
[4:41] I’ve also added a little indicator LED to the gate of the MOSFET so we can see when it is turned on.
[4:47] When the MOSFET is turned on, the total resistance that the battery

[4:50] will be connected to is 8.6ohms - so we’ll use that to calculate the current flowing.
[4:56] I’ve also measured the two potential divider resistors

[4:59] to make sure my voltage calculations are as correct as possible.
[5:02] Having said that, the ADC on the ESP32 is notoriously inaccurate, so we’ll only

[5:09] really be able to get approximate values without doing some calibration. It’s also very noisy,

[5:15] so I’m taking multiple measurements and then averaging the result.
[5:19] The software is very simple. We start off in an idle state with the MOSFET switched off.
[5:24] When we connect the battery we see the voltage go above 4v and switch into the measuring state.

[5:30] We turn on the MOSFET, and reset any calculations.

[5:34] And then we start to accumulate the current we measure over time.
[5:37] When the voltage drops below 3 volts we switch back into the idle state and turn off the MOSFET.
[5:42] The battery capacity can then be read off the screen.
[5:45] It works pretty well - we’re in the same ballpark as the other battery tester.

[5:50] Though both that and our DIY version are going to be pretty inaccurate.
[5:54] My measurement of the total resistance when the MOSFET is turned on is probably not very accurate,

[5:59] my multimeter is a pretty cheap one. And we are dealing with the ESP32’s very inaccurate ADC.
[6:06] I’ve also recorded the battery voltage on the serial monitor every second so we can

[6:10] plot the discharge curve of our cells. This is the 500mAh cell. And this is the 550mAh cell.
[6:18] Looking on the web at some reference curves we’ve got a pretty good match - always nice

[6:23] when an experiment matches the theoretical result.
[6:26] We can also get an estimate for the internal DC resistance of the battery.
[6:30] We can see that the battery voltage under load is 4.078 volts.
[6:35] Assuming the battery was fully charged to 4.2 volts we’re dropping 0.12 volts in the battery.
[6:42] Given the current of 0.474 amps we can calculate the internal resistance to be approximately 0.26 ohms.
[6:50] This is obviously very approximate given all the errors in our system.
[6:54] Obviously, both my DIY version and the one I bought are on the very cheap end of battery

[6:59] testers. There are professional ones that will give you much more accurate results.
[7:04] But, I’m going to call this a win for DIY - I like my homebrew version.
[7:09] I’ve tested the batteries a few times, fully charging and discharging them

[7:12] and they have both been pretty consistent.
[7:15] So we’ve got a couple of healthy batteries,

[7:17] you would think we can go ahead and use them in our projects - well, not so fast batman.
[7:22] Eagle-eyed viewers will have spotted that there is

[7:24] something missing from these batteries - there is no battery protection board.
[7:29] That’s fine if we always use our charging board with the built-in battery protection,

[7:34] but we really should not use these bare batteries anywhere else. We need to make them safe.
[7:38] So I’ve bought some battery protection boards, these boards feature the DW01 protection chip

[7:44] along with the dual MOSFET. It’s exactly the same circuit as we have on our charger board.
[7:50] I’ve tacked a couple of wires onto the output pads.
[7:53] And I’ve soldered the tabs to the battery tabs.
[7:56] Everything is now wrapped up in Kapton tape and we’ve got a couple of safe free 500mAh batteries!
[8:02] We can see this in the discharge graph - I’ve changed the code so that it does turn off the

[8:06] MOSFET unless the voltage drops below 2.5V. But as you can see when we drop to 3V the

[8:12] battery protection cuts and we drop down to 0V, this makes our code turn off the MOSFET.
[8:18] You can also see the effect of the battery’s internal resistance - as

[8:22] soon as we remove the load the voltage jumps back up above 3.0V.
[8:28] It’s all very interesting stuff.
[8:30] So, a small bit of bonus content. I decided

[8:33] to invest in a slightly more sophisticated battery tester.
[8:37] This has a lot more functionality and comes with a nice OLED screen.
[8:41] I’ve tested out the 500mAh battery and this device reports it as having 440mAh.
[8:47] Our 550mAh battery comes in at 567mAh.
[8:52] We’re still getting pretty good results for both batteries.
[8:55] This device also gives us battery resistance. It’s

[8:58] in the same ballpark as our calculation, so that’s nice as well.
[9:02] If you’re looking for a good battery project then you should watch my keyboard hack video it’s pretty good.

HELP SUPPORT MY WORK: If you're feeling flush then please stop by Patreon Or you can make a one off donation via ko-fi
Want to keep up to date with the latest posts and videos? Subscribe to the newsletter
Blog Logo

Chris Greening

> Image


A collection of slightly mad projects, instructive/educational videos, and generally interesting stuff. Building projects around the Arduino and ESP32 platforms - we'll be exploring AI, Computer Vision, Audio, 3D Printing - it may get a bit eclectic...

View All Posts