Lithium-Ion Batteries Power Your Devboards Easily

Last summer, I was hanging out with a friend from Netherlands for a week, and in the middle of that week, we decided to go on a 20 km bike trip to a nearby beach. Problem? We wanted to chat throughout the trip, but the wind noise was loud, and screaming at each other while cycling wouldn’t have been fun. I had some walkie-talkie software in mind, but only a single battery-powered Pi in my possession. So, I went into my workshop room, and half an hour later, walked out with a Pi Zero wrapped in a few cables.

I wish I could tell you that it worked out wonders. The Zero didn’t have enough CPU power, I only had single-core ones spare, and the software I had in mind would start to badly stutter every time we tried to run it in bidirectional mode. But the battery power solution was fantastic. If you need your hack to go mobile, read on.

In 2022, I decided to cast the Be Not Afraid spell to provide you with a healthy amount of information on working with Lithium-Ion batteries. Over the last year, I’ve been actively mentoring up-and-coming hackers developing various gadgets, and whenever I linked the three LiIon articles to someone, I would realize that it was lacking very specific guidelines, schematics and board layouts.

Prepare The Tools

In terms of tools, you should have a multimeter and a soldering iron – the multimeter in particular is great to have when working with LiIon stuff because it provides you a very quick check on battery health. You’ll also want some wires you can solder, and a small number of common components.

Other than that, you’ll want some Aliexpress-obtainable boards – TP4056 charger boards, and optionally a 5 V step-up if you’re going to be charging off of something other than USB.

Now you need a battery. You’ll want to pick one that has about 3.7 V nominal voltage, and about 4.2 V full charge voltage – which is most of them except stuff like LiFePO4, that we won’t talk about here. You can buy new or harvest them from other devices, Old 18650s from devices like laptops are fine as long as they don’t look suspicious, aren’t mechanically damaged, and you get them a holder – don’t solder to them. Pouch batteries are also fine, again, if they’re undamaged, healthy-looking, not overdischarged, and solder to them carefully if you must. You also might want to get a protection circuit to safeguard your battery – TP4056 boards I recommend tend to already have one included, you can harvest them from old devices otherwise, or just get them from Aliexpress. Also, if you’re reusing a smartphone cell, there likely will be a protection circuit present.

Last, look at your dev board – find its schematic if possible, too. Chances are, it’s in one of the three categories as far as powering boards goes – “needs 3.3 V”, “needs 3.3 V to 5 V”, or “needs 5 V”. The overview is that we’ll supply 5 V to the TP4056 charger module to charge up the battery, and depending on the dev board, we’ll need to take the battery’s output and condition it further. Here, our paths diverge.

Your Board Needs 3.3 V

An ESP32, an ESP8266, and a Pi Pico, all have the same thing in common – they simply need 3.3 V for power, and you can provide this easily from a LiIon battery, so at its core, you only need a 3.3 V regulator. On many ESP32 and ESP8266 boards, there’s even a 1117 style regulator on the board already, but those tend to have a problem. The 1117 regulators are uniquely bad for LiIon use. Because of their high drop-out voltage, they fail to provide 3.3 V at as low as at 4 V input, so when the battery is at 50% capacity, they’re already cutting out. There are pin-compatible substitute LDO regulators that are very cheap and accessible – AP2111 and AP2114 are my favourites, so get a few of those. As for Pi Pico boards, or ESPs with small SOT23-5 package regulators, those tend to already be LiIon-compatible!

So we have a 5 V USB input, we have a LiIon battery that needs charging, and we need 3.3 V for the microcontroller. Wire the TP4056 board to the 5 V, and wire its output to the battery. One caveat exists – you can’t pull power from the battery while it’s being charged, that will mess with the LiIon charger chip algorithm! We solve this with three components – a resistor, a diode, and a small MOSFET, mixing the charger and the battery voltage in a way that the charger input is used for power whenever the charger is plugged in. This creates a power rail that goes from about 5 V, down to as low as the battery will go, which is about 3.5 V in practice. I refer to this three-component circuit as a “power path”, because that’s the how circuits for such purposes are usually known as!

You can, of course, add this circuit to a development board – many Sparkfun and Adafruit boards do exactly this, and so do a lot of Eastern-designed devboards. Also, you can measure battery voltage through a resistor divider, as a very crude proxy for state of charge. For ESP32 and ESP8266 boards, dividing battery voltage down to 1 V is the best choice for measurement accuracy for their ADC peripherals, so, you can do something like 330 kΩ / 100 kΩ divider, and for 3.3 V friendly ADCs on a RP2040 or an ATMega, a 1:1 divider (i.e. 470 kΩ / 470 kΩ) will do just fine. Want part recommendations? We talked through those in the last article!

Oh, and, fun thing about the Pi Pico? Look at its schematic, and notice a fun thing – we have access to all the signals and components we need, and the necessary diode is already present on the Pi Pico board. To power a Pi Pico from a LiIon battery with all the benefits that our circuit brings, you only need a resistor, a FET, and a TP4056 board for charging.

This is a seriously universal solution. It applies for a whole lot of devboards with so many different MCUs, you would easily lose track if I were to list them all. As much as these boards might be initially designed for 5 V, you don’t need to actually create 5 V unless you also need to also power things like servo motors or USB devices. But a Pi Zero, for instance, needs 5 V.

Your Board Needs 3 V to 5 V

There are a lot of Pi Zero battery HATs on the market, and most of them tend to use a powerbank-intended circuit to feed the Pi Zero with 5 V. This is quite inefficient because the Pi Zero itself doesn’t actually need 5 V. Internally, it feeds the 5 V input to its regulator to generate 3.3 V and 1.8 V that the chips actually need. Also, there’s a secret – you can feed that regulator with as low as 3.3 V, as it has 100% duty cycle mode that allows it to do pass-through. This results in the regulator having a wide input range, from low 3.3 V to 5 V. Remember our power path circuit? Yeah, you can just use that again.

Here’s a very important consideration we shall solve! See those microUSB ports on the Pi Zero? They are directly connected to the regulator input, which in turn has a direct connection to the battery whenever a charger is not connected. Your task is to make sure you can’t accidentally plug anything into these ports anymore. Thankfully, not many people actually desire a MicroUSB port, much less a MicroUSB OTG port – solder your own USB-A or USB-C port to the GND/D+/D- testpoints on the bottom, and bring 5V from an additional step-up regulator.

If you plan to use the HDMI port, not all HDMI devices will be compatible with receiving 3.3 V on HDMI’s dedicated power rail, so if you encounter problems, you might want to supply your 5 V to the HDMI 5 V pin too – it has a diode you can comfortably solder a wire onto. Those are about all the problems with this method, and in return, you get a seriously increased battery life – I can run a Pi Zero with a few peripherals for over 20 hours from a 5000 mAh LiIon cell.

But if you need the 5 V, how do you find a 5 V step-up? Usually, search through the same place you got your TP4056 boards from. LM2956 regulators will be too bulky if all you want is to power a USB device or two, and the three-pin IC ones will be too underpowered, but there are a lot of regulators in the middle that will be fine generating 5 V at 500 mA for anything you need. I much prefer these because they even appear to work fine when powered from 5 V; it’s been about 7 years since I started using these, so, you might just find a better option too. Also, many USB devices can be powered from 3.3 V, just that it’s quite a gamble on which ones do.

This, too, applies to more than just the Pi Zero. For instance, I’ve recently taken a look at the Banana Pi M4 Zero schematic while doing my research, and its regulator seems to be fully compatible with this powering method, too – save for the SY8089 regulator powering the WiFi module. Full-sized Pi boards, though, won’t work well with this method – with those, you will want to straight up power your board from a 5 V step-up or step-down.

Your Board Absolutely Needs 5 V

If you’re sure your board truly needs 5 V, you should indeed provide it with that. This is where the circuit tends to get simple, because there are a lot of ICs for this task – you have to do the same thing that a powerbank does, so for a lot of purposes, you can reuse a powerbank circuit. You will find these circuits on boards inappropriate and appropriate alike – for instance.

One of the problems with the powerbank IC approach is that many of these chips will shut down their 5 V output whenever a charger is plugged in. For that, you could semi-easily build a FET-based switch that passes charger voltage through whenever the charger is plugged in, and, perhaps, disconnect the IC’s output too while at it. Want an open-source design example you can modify and manufacture? Here you go. Got a USB-C powerbank that has combined USB-C input and output? You can likely use the simplest possible USB-C dock with charging passthrough that provides you with a USB-A or USB-C output port.

The 5 V approach is simple, and the main problem with it is that it’s wasteful. If you’re powering a Pi Zero, this kind of circuit will step the battery 3 V to 4 V up to 5 V only to have the Pi Zero step it back down to 3.3 V, which makes you waste a noticeable amount of power on regulator loss instead of powering your CPU for more hours. In a pinch, you can always rely on the straightforward powerbank-style boards, but if you don’t actually need 5 V, the decreased runtime will make you sad, which is why you should know about the circuits above.

Reference Design To Last You Until Next Time

Last but not least, here’s a reference design for KiCad for all your LiIon needs. I’ve developed a power-your-portable-devices helper PCB that can help you handle a wide range of LiIon batteries you might work with, whether it’s pouch cells, or 18650s in holders SMD and THT alike. This board has a ton of quality-of-life features! There’s the power path, TP4056 and 5 V DC-DC footprints with FET control for the DC-DC, JST-SH 2-pin connector for pouch cells (Adafruit polarity), fuses for two 18650 cells you can put on it, an extra USB-C port for charging wired to the TP4056, wiring holes for connecting wires to the board in a mechanically stable way, reverse polarity protection and even per-cell reverse polarity alarm LEDs, separate 3.3V LDO with FET control that’s compatible with both SOT0223 and SOT23-5 LDOs, and even a protection trigger button in case the protection circuit gets stuck in the shut-off state like I’ve described. Plus, I’ve recently added a few mounting holes on the corners, improved wrong polarity silk markings for LEDs, and D-/D+ testpoints for the onboard USB-C port – after all, I’ll need to order a new batch of these boards soon!

I’ve originally developed this board for my own use on hardware hackathons, where I noticed myself always having to roll a small-scale solution for powering whatever gadget I was hacking away at – saving a few hours during a hackathon tends to result in great outcomes. Over the years, this design has powered multiple portable projects of mine, including designs I’ve used for years, and I’ve even used it to trigger small-scale explosives a couple of times – in Minecraft, of course. The design is fully open, so you can remix it, steal footprints and symbols from it, manufacture a small batch, it’s up to you.

Now, what if you need more, like 12 V? At some point, step-ups for such voltage will become inefficient, and you might just want to connect LiIon batteries in series, like many higher-power devices do. This does require more care from you, though, which is why so far, we’ve only talked about single-series configurations. Let’s devote the next article to putting multiple cells in series, so you know what it takes to treat batteries safely while getting a comfortably high voltage for any circuit you might have in mind.

24 thoughts on “Lithium-Ion Batteries Power Your Devboards Easily

    1. Yeah, I’m curious too. It has to be doing something significant and possibly interesting, because I used to have minimal load from running Murmur (with a small number of clients) on the original raspberry pi which is slower than the zeros are. So this might be more than just the equivalent of a wifi hotspot with voip.

    2. Not the author, but if I wanted to build a “digital” walkie talkie I would explore the feasibility of Codec2, as it does voice communication using very low bandwidth, which even LoRa could achieve, and would be usable with much smaller modules consuming a fraction of a fraction of the power needed by a Pi.

      Check out the results wrt bandwidth.

  1. It’s all fun and games until paranoid karens working in building administration step in. Recently they’ve introduced a regulation that tenants must ask for their permission to store lithium-powered devices in flats or basements, with exception of laptops and phones. Why? “Fire safety”. This BS applies to power tools, flashlights, e-bikes and scooters etc. In addition, “raw batteries” like LiPol-s used for RC cars are banned altogethether because they “pose a significant risk of explosion”. Failure to follow those new “safety regulations” will result in a 5000 EUR “administrative fee”.

    Sometimes I wish I could just take a one-way trip to mars. I don’t want to live on this planet anymore.

    1. When you find a RC LiPO battery swollen and scorched you too will invest in some fireproof bags to store your cells. Also not store those bags on flammables. Also don’t fill them.

      At least one bag for charging.

      It shouldn’t be a law, but you should do it because you’re not crazy.

      E-bike packs are mostly HobbyKing grade.

      The leading economy in the EU is of RULES CRAZY Germans!
      What do you expect?

      1. Just to be clear, there are _no_ such laws in RULES CRAZY Germany. I don’t know where Pharaoh lives, but the reference to “building administration” makes me think that it’s a particular work or institutional situation.

        E-bike batteries (and car batteries!) are usually made of LiIon 18650 cells, which are a ton safer than LiPo pouch batteries. The reason is partly the pouch versus the metal case, but also partly that the pouches are a different topology designed for high current, which just makes them inherently more volatile.

        That said, quad people put millions of charge cycles through LiPo packs, many at maximum discharge. The number of fires is anecdotally very small in comparison. I don’t think we have stats, but I’d love to see them if we do!

        Charge slowly and don’t over-discharge. Don’t store them topped up. Balance them out if they’re in parallel. Pitch ’em when they get puffy.

  2. Don’t forget the FUSE on the supply output. Looking at the current capabilities of some 18650 cells (9900 ma) should be a wake up call, especially for unattended operations. I have found assortments of auto reset fuses are a great value. They will reset when the power is removed temporarily. I was using a 12v car battery starter pack in a project that powered 12v motors when one of the motors completely shorted out.
    If I had not had the circuit properly fused, there would have been plenty of marsh-mellows to toast. When using packs like this, I would even recommend using an additional standard glass type fuse inline as close to the battery as possible.

  3. This is great, I’ve been starting and failing to design a simple 5v UPS for small 2A loads for years, always ending up buying something that doesn’t quite suit my needs as well as a custom design would.
    Thanks for sharing both the reference design and the explanation for the design.

    1. Nice one, Rog77!
      I’ve never seen that site before. Very handy to bookmark. Some more useful stuff there, other than the subject covered in this article too. The section you linked about TP4056 charging modules should be required reading for anyone working with them. I’ve been a bit squeamish myself through not really understanding how to pick the charging resistors and a lot of the circuits online that use those modules look *very* janky.

    2. That’s a neat article. In the conclusion, the writer mentions:
      “However, I have never heard of any problems in using the breakout board as it is commonly used – as a charger and power source at the same time. But it is far safer to tack on three components as discussed in this page.”

      Which is very interesting to me. Which makes me wonder, how did this chip even get to a point where these chips are so common and available to hobbyists without reports of massive failure? A similar question is posed:
      Also found a giant PSA in the DIY Gameboy scene on reddit:

      My takeaway from all this is that this chip is severely flawed with the DW01 chip not doing it’s job trickle charging. But at the same time, the chip exists so that it won’t catastrophically destroy the battery you are using. At the most, it sounds like it will degrade your battery much faster. I’ll probably start staying away from the tp4056 boards moving forward. Hopefully I can find a better alternative soon (suggestions are welcome)

      1. The grumbing about the DW01 is that it cuts out at around 2.5v & 4.3v, voltages that some consider too low & too high for LiPo cells. Eh.

        It’s also meant to be used with small sub 1000mAh cells (as found in prehistoric phones) for reasons I’ve never bothered to find out.

        Most of the chargers boards apparently wire it up wrong, I can’t remeber the details. You’ve got Google, look it up.

        The TP4056 isn’t that great a chip, but it works and it’s cheap Its main problem is it’s a linear controller, meaning it gets hot at high charge rates. Fortunately that’s easily solved by changing one resistor. 20k gets you 1 amp, less gets you less.

        Bi-directional USB-C PD boards are getting cheap, making this article already obsolete.

        1. If you wanted to build a device to last years and years with an oversized battery the DW01 is a terrible choice. It looks to be a fast and loose setup to get the most out of a battery short term and the usable lifespan is reduced by 30% to 50%. If you check out some curves, keeping the battery between 30 and 90% will make it last possibly twice as long. If you are replacing some AAA or something the same run-time with a usable life span of 10-20 years instead of 2-5 might be something people want. It should be adjustable is all. And it is odd its basically the only cheap choice.

          1. The DW01 has nothing to do with charging, it’s a protection chip.

            If you want longer life by limiting charge to say 80% (as often recommended) you need to add some smarts to your charger. A lot of thing already do this by cutting off at ~4v rather than going to the full 4.2v. Do the same for discharge. And then you don’t even need the DW01.

  4. Two things I’d like to note.

    1. Efficiency of stepping up Li-Ion to 5V just to LDO them down to 3.3V is horrible. I’d rather choose a device specifically designed for the purpose (integrated buck-boost) Li-Ion to 3.3V converter like the LTC 3440.
    2. Having a voltage divider on the battery at all times increases the risk of accidental deep discharge of the battery. I usually design in a MOSFET that is only conducting when the battery voltage gets read.

  5. I would like to find a circuit able to boost Li-ion voltage and at the same time provide a constant current output. This would be useful for using white LEDs at 4-6 V for lightning purposes. I would make use of old laptop and phone batteries and also salvaged LEDs from partially dead bulbs. I have only found boost and constant current circuits as two independent boards.

  6. The guy with the Swiss accent (who is regularly mentioned on Hackaday), had a nice video about using LiFePO4 instead of LiIon.
    Nicest idea in favor of LiFePO4 is that it will never go over 3.6V, so most 3.3V devices can be used without voltage regulator.

      1. +1. LiFePO4 seems like a no-brainer for off-the-grid electronics. Buy a bunch of salvaged 18650 or 26650 cells, test them, keep the good ones, easy power with a minimal BOM. I might be wrong, but I think they degrade less with heat, which appeals to me for literal out-in-the-field applications (e.g., soil moisture sensors).

  7. Hi, You can add a IP5306 IC to get 5V output and battery charging & protection capabilities. This IC can be easily included in your Devboards to take care of powering your boards with Li-Ion batteries.

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.