Tuesday, November 28, 2017

Raspberry Pi Relay Control from Android and Internet

This turned out to be drop dead simple. Once you have your outlets wired up to your relays and everything working good this is so easy. See my other post on how to setup the relays and such here.

I wanted to create my own, low dollar, solution for Home Automation and such. Jason Findlay does all of the software heavy lifting for you. Assuming you have a Relay hooked up to your Raspberry Pi, follow along.

  1. Install Wiring PI
    1. git clone git://git.drogon.net/wiringPi
    2. cd into the directory: cd wiringPi
    3. Run this: sudo git pull original
    4. then run: ./build
  2. Install Apache and PHP
    1. Run this command: sudo apt-get install apache2 -y
    2. Run this command: sudo apt-get install php7.0 libapache2-mod-php7.0 -y
  3. Create the PHP script
    1. Run this command: sudo nano /var/www/html/gpio.php
    2. Paste this code
    3. Save the page. You should now have a gpio.php file. This will drive the calls from the Android app.
  4. Download and Configure Android APP
    1. Search the Play Store for PiRelay and download the app: https://play.google.com/store/apps/details?id=com.jasonfindlay.pirelaypro
    2. Fire up the app and click on the Hamburger Icon in the top left to show the config sections.
    3. Click on the Pi URL Addresses option
    4. Enter the address to your Pi Example: (or whatever the IP on your Pi is. Run an ifconfig to see the IP)
    5. Click the Hamburger Icon in the top right corner again and Click Number of Relays
    6. Enter the number of Relays you will configure
    7. Click Hamburger Icon in the top right corner again and Click Setup Relays
    8. Click Relay 1
      1. Enter a name for the relay
      2. Choose the WiringPI Pin #. Use this as a guide
      3. Select a Relay Icon
      4. Choose the appropriate Relay type. The Relays I used were Active Low. Just play around with it until it works
      5. Then click the back arrow.
      6. You should now be able to toggle the relay and turn whatever you have plugged in on and off.

This may seem like a lot of instructions, but honestly it was very easy to setup and get rolling. If you have troubles head over to https://pirelay.jasonfindlay.com for help. You can also use the gpio.php page you built above to control the relays without using the Android app.

http://{your pi IP address}.gpio.php/?pin=1&status=0
http://{your pi IP address}.gpio.php/?pin=1&status=1

Use the Pin look up image I pasted above to specify the correct Pin number, this is the WiringPi pin, not the GPIO or Raspberry PI pin numbers.


Post a Comment