About PiRelay

PiRelay is an Android app you can use to Switch or Pulse the GPIO Pins of a Raspberry Pi connected to Relays. To use this app you will need to setup your Raspberry Pi and Relays which the following guide will walk you through. The relays can be connected to switch an electrical circuit for controlling things like Lights, Fans, Motors, Gates, Doors, Heating, Air Conditioning or anything else you might want to control.

If you have any Feedback for me, Issues with the app or Questions, Please ask in my thread on the Raspberry Pi forum: http://www.raspberrypi.org/phpBB3/viewtopic.php?f=37&t=60008
Features in PiRelay

– Control up to 100 Relays
– Use up to 10 Raspberry Pi’s
– Ability to send a pulse signal (i.e. Switch relay on then immediately off)
– Swipe down to refresh relay status
– Ability to assign Icons to relays
– Alternative On/Off Icons
– Refresh relay status
– Screen rotation
– Pi Header Diagrams for Rev1 (P1) & Rev2 (J8) boards
– Ability to change the Title Bar Name
– Ability to set the Wiring Pi Pin # used by each relay
– Ad Supported Free App with optional “In App Purchase” to remove ads

Disclaimer: These instructions are provided as is for information purposes only, and the author Jason Findlay cannot accept any liability for and injury or damage caused by following these instructions. Whilst these instructions can be considered safe to follow, you proceed at your own risk.

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.

Hardware Configuration

The Relays

You need to source some 5v relays that will work with the Raspberry Pi. The simplest solution is to purchase a 5v Relay Module Shield such as this one: eBay: 5V-1-2-4-8-Channel-Relay-Board-Module

This is the board I use and works very well. I am using the 8 channel relay version which is great value. It consists of 8x 250v 10Amp Relays, perfectly capable of running directly from the Pi. (Note that if all 8 relays are engaged at the same time, you will be drawing around 600mA of power from the Pi, so a 2 amp or above power supply is recommended if powering it directly from the Pi, alternately you might want to provide power to the board with an additional 5v power source)

The Connector

To connect the Raspberry Pi to the Relay Module you will need to connect wires from the GPOI pins on the Raspberry Pi to the pins on Relay Module. You can do this by any means you like, but I found using a “DIY Ribbon Cable” with connectors the simplest which can be purchased cheaply from eBay.

The first 8 relays are set to default to WiringPi GPIO Pins (GPIO 0 to 7) for you which you can change in the app settings. Attach your relay connectors the respective GPIO pin you are controlling with the PiRelay App.

If you have completed the installation and wiring of your Pi to your relay board you should now be able to switch relays with your PiRelay App.

The WiringPi Pins / GPIO Header

Check out the following page for an interactive diagram of the PinHeader on a Raspberry Pi showing the corresponding GPIO pin and WiringPi Pin number used in the PiRelay app.