Learning never exhausts the mind
Home >  Technology > Raspberry Pi > Raspberry Pi Power Switch with PowerBlock

Published 9th September 2018 by

How to setup 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 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 its 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 on 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

Raspberry Pi PowerBlock

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 PowerBlock

Raspberry Pi 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, then install the service.

git clone git://github.com/petrockblog/PowerBlock.git
cd PowerBlock
mkdir build && cd build
cmake ..
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 PowerBlock

Raspberry Pi PowerBlock

Leave a Reply

Fields marked with * are mandatory.

We respect your privacy, and will not make your email public. Hashed email address may be checked against Gravatar service to retrieve avatars. This site uses Akismet to reduce spam. Learn how your comment data is processed.