How to Add a Power Switch to a Raspberry Pi with PowerBlock

How to setup PetRockBlog's PowerBlock on a Raspberry Pi and add a simple hardware power switch to turn the Pi on and off and add power LED.

By Tim TrottRaspberry Pi Projects • September 9, 2018
How to Add a Power Switch to a Raspberry Pi with PowerBlock

How do you set up PetRockBlog's PowerBlock on a Raspberry Pi and add a simple hardware power switch to turn the Pi on and off? We will also add a power LED, which can be used to show the status when in an enclosure.

PowerBlock is a Power Switch for the Raspberry Pi A+/B+/2/3 and Zero/Zero W from PetRockBlog. The power switch functionality allows you to turn the power to the Raspberry Pi on and off with a toggle switch without the need to unplug any cables. Suppose you unplug the micro USB cable whilst the Raspberry Pi is on. In that case, your file system might become corrupted, and you may lose data. When shutting down, the RPi is cleanly shut before it cuts the power.

As a bonus feature, the PowerBlock allows you to connect an external LED to an enclosure or case and an LED with several modes indicating the system status. When the Pi is booting up, the LED will flash slowly; when it's booted up and ready, the LED will be a steady light, and when shutting down, it will flash rapidly.

Attaching a Raspberry Pi Power Switch

You must use a toggle switch, not a momentary button, with the PowerBlock. Suppose you attach a momentary switch (one that returns to its original position). In that case, the Raspberry Pi will power itself off as soon as it's loaded.

The power switch of the PowerBlock leads to a tiny voltage drop, so you need to ensure that your power supply can provide voltage and current. My phone charger was having problems with being under load. Still, everything was good as soon as I connected the official power supply.

The easiest way to attach the power switch (and the LED) is to solder a two-pin header to the board. You can, of course, solder the switch directly to the board. Still, you are limiting your options for future reuse and extendability by doing this.

With the two-pin header attached, you can then use a two-pin female connector attached to the switch to connect the two.

Raspberry Pi PowerBlock Module Adds a Hardware Power Switch and LED
Raspberry Pi PowerBlock Module Adds a Hardware Power Switch and LED

Attaching a Status LED

Installation of the LED is optional, so feel free to skip this step if you don't require it.

As with the power switch, the best method for attaching the LED is to solder on a two-pin header and connector.

Installing the PowerBlock to the Raspberry Pi

With those two headers soldered to the PowerBoard, we can connect everything up. This is as simple as connecting the PowerBlock to the Raspberry Pi using the GPIO connector and sliding the switch and LED to the headers.

We can then connect the power cable to the PowerBlock (not the original power connector on the Raspberry Pi) and power it on.

The PowerBlock has 5V output pins (+, -). These pins are also switched by the PowerBlock. Since the PowerBlock connects to the 5V output of the Raspberry Pi, you will need to connect accessories or fans to the PowerBlock instead, as long as they don't draw too much current. The maximum current the PowerBlock can handle is 3.7 A - including the current consumption of the Raspberry Pi. You could use the output pins to switch a relay if you need more power.

Raspberry Pi Power Switch with PowerBlock
Raspberry Pi Power Switch with PowerBlock

Installing PowerBlock Drivers

The PowerBlock needs a few drivers to configure the soft shutdown and LED.

Firstly, there are a few prerequisite packages you will need to install.

sudo apt-get update
sudo apt-get upgrade -y
sudo apt-get install -y git cmake g++-4.9 doxygen

Once they are installed, you need to get the GitHub package, extract and build it, and then install the service.

git clone git://github.com/petrockblog/PowerBlock.git
cd PowerBlock
mkdir build && cd build
cmake ..
make
sudo make install
sudo make installservice

You need to reboot now; it should work out of the box. Suppose you look at the configuration file or make any changes. In that case, it is located at /etc/PowerBlockconfig.cfg.

Raspberry Pi Power Switch with PowerBlock
Raspberry Pi PowerBlock

Related ArticlesThese articles may also be of interest to you

CommentsShare your thoughts in the comments below

My website and its content are free to use without the clutter of adverts, popups, marketing messages or anything else like that. If you enjoyed reading this article, or it helped you in some way, all I ask in return is you leave a comment below or share this page with your friends. Thank you.

There are no comments yet. Why not get the discussion started?

New comments for this post are currently closed.