PiRelay Installation

Install The Software On Raspberry Pi

There are 2 methods of installing the software to use Pi Relay. 

Method 1. which is simple, and for people who either need it up and running quickly, and/or don’t have experience running Linux commands manually.


Method 2. which is the manual install with Terminal for people who prefer to know/learn how to configure the software, or to customise the installation.

Method 1.

Restore a Pre-installed image to your SD Card (Quick & Easy)

1.1.  Download Pi Relay app from the Play Store here: PiRelay App Download

1.2.  Download one of the Pi Relay SD Card Images here:

Download one of the following SD Card Image’s (The images are compatible with ALL versions of Raspberry Pi):

PiRelay Raspbian Lite (Stretch) (2.2GB): Download– (Best for Pi 1 and Pi Zero)

PiRelay Raspbian (Stretch) (With Desktop) (1.5GB): Download

NOTE: You will need a 4GB or larger SD Card to write the image file. If using an SD card larger than 4GB you can run “sudo raspi-config” in terminal which has the option to expand the file system to your SD card’s capacity after first boot.

Write Image to SD Card:

Once downloaded and extracted use an SD Card Image Writer such as: http://sourceforge.net/projects/win32diskimager/files/latest/download to write the extracted image to your SD card.

Finally just put the SD card into your Raspberry Pi and power it up.

That’s it… your Pi is now ready to use with PiRelay App to start switching or pulsing stats of your GPIO pins.

If you’ve successfully used this method, then you can now skip to the Hardware Configuration section of this guide.

NOTE: Method 1. will erase all existing data from the SD card.

Method 2.

Manual Software Install / Configuration

Setting Up Your Android Device

2.1.  Download Pi Relay app from the Play Store here: PiRelay App Download

In the app settings you can define a custom Server URL. This is the network path to your Raspberry Pi. The default path is “http://raspberrypi/”, however you can define an IP address or a custom URL. If you want to use PiRelay using Mobile Data then you will need to configure your own port forwarding on your router (By default PiRelay uses Apache2 on port 80).

Setting Up Your Raspberry Pi

2.2. Run terminal commands to install PiRelay on your Raspberry Pi

NOTE: It is recommended to run each command individually.

To install the required software on the Raspberry Pi you need to run the following commands at the Linux command line interface. To make it quicker and easier I use Putty on windows to SSH straight onto the Pi, but that’s not required, you could just type in these commands directly into the command line on the Raspberry Pi.

You should be able to run these commands with any Debian based Linux distribution, however I would recommend using the latest version of Raspbian (At the time of writing this the latest version is Stretch) from http://www.raspberrypi.org/downloads.

NOTE: Your Raspberry Pi needs to be connected to your network either via WiFi or an Ethernet Cable for Pi Relay to be able to access the RaspberryPi.

Command to Install: Wiring Pi (Required for Raspbian Lite)

sudo apt-get install wiringpi


Commands to Install: Apache & PHP

sudo apt-get install apache2 -y

sudo apt-get install php7.0 libapache2-mod-php7.0 -y

Create the PHP Script

Use the following command to launch the Nano File Editor and generate the gpio.php file:

sudo nano /var/www/html/gpio.php

Then copy the following into the Nano Editor:

<!DOCTYPE html>
 $output = shell_exec('gpio mode '.$_GET['pin'].' out');
 $output = shell_exec('gpio write '.$_GET['pin'].' '.$_GET['status']);

for ($i = 0; $i < 32; $i++){
 $output = shell_exec("gpio read ".$i);
 echo "Relay ".$i.":".$output."<br>";

To exit the Nano Editor press Ctrl+X together. When it asks if you want to save the file press “Y” for “Yes” and press Enter! to save your gpio.php file.

That’s it… your Pi is now ready to use with PiRelay App to start switching or pulsing stats of your GPIO pins.