Often, when doing a project based on a Raspberry Pi, the main goal is to make it portable. Thus, we find ways to make it work unplugged. In this tutorial, we will talk about how to power a Raspberry Pi with a battery.

I’ve been using the Raspberry Pi for years now, and hands down, the best part is that you can bring it anywhere. It is a tiny computer the size of your hand, so having it connected to a power outlet kind of defeats its purpose.

With batteries connected, you can set up a web server for sensors in an open field, apply machine learning to a CCTV, or even control actuators from anywhere in the house. Now, the only drawback in using batteries is that you have to start minding power consumption. But that’s perfectly doable, as we will see in this tutorial.

The first thing you need to do is to choose the correct Raspberry Pi.

Choosing the Right Raspberry Pi

Figure 1: Raspberry Pi 4 (Credits: https://www.raspberrypi.org)

The latest Raspberry Pi 4 B is a beast among single board computers. It has a quad-core processor, a gigabit Ethernet port, USB3, which supports two 4k displays, but consumes a whopping 6.25Wh.

You can use the Raspberry Pi 4 B if your application is resource intensive, but a Raspberry Pi Zero would be a better choice if you want to maximize battery life.

Figure 2: Raspberry Pi Zero (Credits: https://www.raspberrypi.org)

This table compares the power usage and power source between the Raspberry Pi 4 and the Raspberry Pi Zero:

Raspberry Pi 4 BRaspberry Pi Zero
Power Ratings1.25A180mA
Power SourcesUSB-CmicroUSB, GPIO
Table 1: Power consumption between Raspberry Pi 4B and Raspberry Pi Zero

The Raspberry Pi Zero consumes almost seven times less power than the Raspberry Pi 4 B. To demonstrate, let’s convert these current ratings in terms of battery life.

How to Calculate Battery Life

Suppose I have a single cylindrical 18650 lithium battery with 2200 mAh capacity. How long would a Raspberry Pi 4 B last? To get the battery life, divide 2200mAh with the rated amperage of the Raspberry Pi 4 B:

One hour and forty-five minutes of operating time is definitely not good for a portable device. However, if you use a Raspberry Pi Zero, the results improve significantly:

Note that this is only for a single lithium battery, so there is a large room for improvement. You can add more batteries in parallel to prolong battery life. Also, the Raspberry Pi’s rated current is an average from the datasheet. The actual current readings may differ depending on your Raspberry Pi’s activity and peripherals. If you want to know the actual readings, you can use a current tester.

How to Choose the Battery Size

Using the calculations above, we can formulate a rough estimate of our device’s battery life. For instance, a 1000mAh battery would be able to power a device with a rated current of 1000mA for one hour. Similarly, a 40,000 mAh power bank would be able to power a 4A device for one hour, or 1A device for 40 hours. It’s really a compromise between your project’s power consumption and how long you need the device to be powered by a single charge.

Things to Consider

The Raspberry Pi needs to be powered with 5V DC, so we need to have a DC/DC converter to convert the 3.7V battery voltage to 5V. This means the power consumption and efficiency of the converter needs to be considered when determining battery life. Efficiency affects battery life like a multiplier, so read the datasheet and choose a good DC/DC converter carefully.

Finally, if you’re powering the Raspberry Pi with a rechargeable battery, you need to have a battery charge controller. Charge controllers regulate the incoming current and voltage to your batteries. They are used to prevent overcharging, allow you to charge your lithium batteries safely, prolonging your battery’s lifespan.

Now that you have chosen the appropriate Raspberry Pi, the correct battery size, a DC-DC converter, and a battery charge controller, we can now proceed to the possible battery setups.

There are three setups I have tried over the years. First is the minimal setup.

Charge Controller

Connect a TP4056 charge controller to a 3.7V lithium battery. Then, connect the charge controller’s output to the 5V pin and ground of the Raspberry Pi Zero. Since the Raspberry Pi operates at 3.3V, the 5V rail already has an onboard voltage regulator that creates this voltage using any input between 3.3V and 5.25V.

Figure 3: Directly connected with a charge controller

This setup is great for testing. Best for trying your system out for a few minutes and observe if it is working. However, I don’t recommend using this as a permanent solution. It’s because you’re basically connecting 3.7V to the 5V pin. When the battery level goes down to 3.3V, the Raspberry Pi will shut down even if the battery is not completely spent. Also, you have to disconnect the Raspberry Pi from the battery every time you’re charging, so you’ll need a toggle switch or a breadboard.

DC/DC Converter

To solve this, you need to have a MT3608 3.7V to 5V DC/DC converter that ups your 3.7V to standard 5V. Take the output from the charge controller. Connect it to the converter’s input and connect the output to the 5V pin of the Raspberry Pi. With this setup, you don’t have to worry about not making the most of your batteries. You also don’t have to disconnect the batteries every time you charge because of the built-in circuitry of DC/DC converters.

Figure 4: Connected to a DC/DC converter with a charge controller

Power Boost Module

The last setup is uses the PowerBoost 1000 charger module from Adafruit. This module works like a battery charge controller and a DC/DC converter in one. No need to have separate modules. Just connect a 3.7V lithium battery, and you’ll have constant 5V output and regulated USB charging.

Figure 5: Powerboost setup

Hope this article has helped you setup your Raspberry Pi to run off of a battery! Feel free to leave a comment below if you have questions about anything.