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 Trott | Raspberry Pi Projects | September 9, 2018

How to 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 on and off the power to the Raspberry Pi with a toggle switch without the need to unplug any cables. If you simply unplug the micro USB cable whilst the Raspberry Pi is on, your file system might become corrupted and you may lose data. When shutting down it cleanly shuts down the RPi before it cuts the power.

As a bonus feature, the PowerBlock allows you to connect an external LED to an enclosure or case and LED which has 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 will need to use a toggle switch, not a momentary button with the PowerBlock. If you attach a momentary switch (one that returns to its original position) 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 under load, but as soon as I connected up the official power supply all was good.

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, but 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 together.

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 go ahead and 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 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. If you need more power you could use the output pins to switch a relay.

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

Installing PowerBlock Drivers

The PowerBlock needs a few drivers in order 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

All you need to do now is reboot and it should work out the box. If you want to take a look at the configuration file or make any changes you can find it located at /etc/PowerBlockconfig.cfg.

Raspberry Pi Power Switch with PowerBlock
Raspberry Pi PowerBlock
Was this article helpful to you?
 

Related ArticlesThese articles may also be of interest to you

CommentsShare your thoughts in the comments below

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?

We respect your privacy, and will not make your email public. Learn how your comment data is processed.