jazzler
Posts: 31
Joined: Mon Nov 04, 2013 7:43 am

Control Relay Switches via Android using a Raspberry Pi

Mon Nov 04, 2013 7:53 am

I've started a project and published an app on the Android Play store here: PiRelay to control Relays from an Android Device using a Raspberry Pi.

I would be interested to hear any feedback on this, and to hear from anyone who uses my app/instructions.

Instructions to set this up can be found here: http://bit.ly/pirelay

Thanks for looking.

Update: 03/02/2017 - Updated SD Card Image (PiRelay v2) for Raspberry Pi (Follow the instructions in the link above to download the latest SD Card Image)

Image
Video of PiRelay working on a simple home setup can be seen here: https://youtu.be/Ft6x_X_Cqk4

Features of PiRelay App
- Control up to 100 Relays
- Use up to 5 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
Last edited by jazzler on Sat Feb 11, 2017 10:14 am, edited 30 times in total.
PiRelay Project : http://bit.ly/pirelay
PiRelay Play Store App : http://bit.ly/PiRelayApp

Hoagie
Posts: 119
Joined: Sun Sep 23, 2012 7:19 pm

Re: Control Relay Switches via Android using a Raspberry Pi

Tue Nov 05, 2013 1:08 pm

If you have Apache installed, can;t you do this as a web page. That way any device with a browser can control it. I control my TV with an iPhone or android tablet using the page in the attached picture.
remote.jpg
remote.jpg (27.92 KiB) Viewed 35697 times

jazzler
Posts: 31
Joined: Mon Nov 04, 2013 7:43 am

Re: Control Relay Switches via Android using a Raspberry Pi

Tue Nov 05, 2013 10:14 pm

Hi, thanks for the feedback. yes you most certainly can. Of course you could run the web page for any device and use the app on android with the same apache install. For me I prefer a native app over a web page where possible. It's a bit like the fact that I use the Facebook app on my phone, instead of the Facebook mobile site, even though Facebook has a perfectly good and usable mobile site.

Nice interface on your remote by the way...

Jas
PiRelay Project : http://bit.ly/pirelay
PiRelay Play Store App : http://bit.ly/PiRelayApp

jazzler
Posts: 31
Joined: Mon Nov 04, 2013 7:43 am

Re: Control Relay Switches via Android using a Raspberry Pi

Mon Dec 02, 2013 3:12 pm

I'm pleased to see that there are quite a few people using this app with their Raspberry Pi now. So Just a quick update for you. The PiRelay Pro version of my app in the Google Play store has now been released with the following features:

- Option to choose if the Relay Type should be 'Active High' or 'Active Low' (To support different types of relays)
- Option to change how many relays are being controlled (So it doesn't display unused relays in the interface).
- Ability to change the labels of each Relay. (e.g. Change label 'Relay 1' to 'Garden Lights', 'Relay 2' to 'Heating' etc..)
- Status Checking of the Relay States when you open the app, or resume it, and automatic updating of the toggle switches to match the state. (Note: You will need to update your GPIO.php file to use this feature if you are already using the original version of PiRelay)

If you already have the initial version of PiRelay Pro installed, then to make use of the new 'Status Checking' feature you will need to update the GPIO.php file on the Raspberry Pi. I have added update instructions to my project page http://pirelay.jasonfindlay.com.

Please let me know if anyone has any trouble using the new version of the app or updating your GPIO.php file on the Raspberry Pi.

The next feature I want to implement is the ability to define a 'Delay Off' value to a relay, e.g. If delay off on Relay 1 was set to 2 seconds, then 2 seconds after turning it on, it will turn off the relay. This is useful for applications such as Garage Door openers which require a short signal to Open/Close the Garage door etc.
PiRelay Project : http://bit.ly/pirelay
PiRelay Play Store App : http://bit.ly/PiRelayApp

jazzler
Posts: 31
Joined: Mon Nov 04, 2013 7:43 am

Re: Control Relay Switches via Android using a Raspberry Pi

Sun Dec 22, 2013 10:01 pm

A quick update of the latest feature for those of you following this thread..

I've now implemented the 'Use Relay X As Signal' feature into the Pi Relay Pro app, so the app can now be used to control devices which require an instant (On/Off) signal, instead of just a Power state On or Off (e.g. Garage Doors, Electronic Gates etc..).

Also here is a video I made of the app being used to control my Fish Tank: http://www.youtube.com/watch?v=poPHlrG2xM4

and a link to my app in the Android Play Store: https://play.google.com/store/apps/deta ... pirelaypro
PiRelay Project : http://bit.ly/pirelay
PiRelay Play Store App : http://bit.ly/PiRelayApp

pelti
Posts: 5
Joined: Wed Dec 25, 2013 1:54 pm

Re: Control Relay Switches via Android using a Raspberry Pi

Wed Dec 25, 2013 2:04 pm

Hi,

I downloaded and installed your OS to rasp and tried to set settings.
I have one relay connected (when powering it, it says "click" so I think it works. and 2 leds light)
But the pirelay software does not control the relay. I have changed the server address 192.168.1.30 to settings - no help :(
How I can test the wiring from terminal (without the software pirelay) using commands.? And is there something else in the pirelay software to configure?

sorry I have taken only very few steps in this area :)

User avatar
Richard-TX
Posts: 1549
Joined: Tue May 28, 2013 3:24 pm
Location: North Texas

Re: Control Relay Switches via Android using a Raspberry Pi

Wed Dec 25, 2013 3:11 pm

I wrote a web page some time ago that selected a streaming radio station and told mpc/mpd to play it. Using a web page, you could have the Rpi do anything.
Richard
Doing Unix since 1985.
The 9-25-2013 image of Wheezy can be found at:
http://downloads.raspberrypi.org/raspbian/images/raspbian-2013-09-27/2013-09-25-wheezy-raspbian.zip

jazzler
Posts: 31
Joined: Mon Nov 04, 2013 7:43 am

Re: Control Relay Switches via Android using a Raspberry Pi

Wed Dec 25, 2013 3:48 pm

Hi Pelti,

From terminal to test it, use the commands for Wiring Pi,

First type in:
gpio mode 1 out

Then:
gpio write 1 1

This will turn on the GPIO input for relay 1,

To turn it off again use:
gpio write 1 0


Also for testing purposes, you can go to: http://192.168.1.30/gpio.php from a computer or phone on your network. It should show you the current status of each of the relays. (1 = GPIO Pin is active, and 0 = GPIO Pin is inactive).

As two lights turn on when you plug in your Pi & Relay, I suspect your relay is an 'Active Low' type, so make sure you enable that from within the app to get the correct On/Off states.

Hope this helps you.
PiRelay Project : http://bit.ly/pirelay
PiRelay Play Store App : http://bit.ly/PiRelayApp

User avatar
Richard-TX
Posts: 1549
Joined: Tue May 28, 2013 3:24 pm
Location: North Texas

Re: Control Relay Switches via Android using a Raspberry Pi

Wed Dec 25, 2013 4:49 pm

There is always /bin/sh

Code: Select all

#!/bin/sh

# GPIO numbers should be from this list
# 0, 1, 4, 7, 8, 9, 10, 11, 14, 15, 17, 18, 21, 22, 23, 24, 25

# Note that the GPIO numbers that you program here refer to the pins
# of the BCM2835 and *not* the numbers on the pin header. 
# So, if you want to activate GPIO7 on the header you should be 
# using GPIO4 in this script. Likewise if you want to activate GPIO0
# on the header you should be using GPIO17 here.

# Set up GPIO 4 and set to output
echo "4" > /sys/class/gpio/export
echo "out" > /sys/class/gpio/gpio4/direction

# Set up GPIO 7 and set to input
echo "7" > /sys/class/gpio/export
echo "in" > /sys/class/gpio/gpio7/direction

# Write output
echo "1" > /sys/class/gpio/gpio4/value

# Read from input
cat /sys/class/gpio/gpio7/value 

# Clean up
echo "4" > /sys/class/gpio/unexport
echo "7" > /sys/class/gpio/unexport
Richard
Doing Unix since 1985.
The 9-25-2013 image of Wheezy can be found at:
http://downloads.raspberrypi.org/raspbian/images/raspbian-2013-09-27/2013-09-25-wheezy-raspbian.zip

pelti
Posts: 5
Joined: Wed Dec 25, 2013 1:54 pm

Re: Control Relay Switches via Android using a Raspberry Pi

Wed Dec 25, 2013 8:08 pm

hi, found this far (wiring:)
[email protected] ~ $ gpio -g mode 4 out
[email protected] ~ $ gpio -g write 4 0
[email protected] ~ $ gpio -g write 4 1

these will work. on and off.

and this is result of gpio.php: (so effects on relay 7, that is changing depending on
Relay 1:0
Relay 2:0
Relay 3:0
Relay 4:0
Relay 5:0
Relay 6:0
Relay 7:1
Relay 8:0

wired to gpio4 (cpclk0) refer you wiring picture

but what next?

BuffKnysna
Posts: 24
Joined: Thu Aug 02, 2012 12:38 pm
Location: Port Elizabeth, South Africa

Re: Control Relay Switches via Android using a Raspberry Pi

Thu Dec 26, 2013 8:48 am

Hi All
Just found this post which interests me greatlly having recently upgraded to a Samsung Galaxy.
Is it possible to use the app via bluetooth to control the pi?

If this has already been mentioned, please point me in the right direction.

Thanks

jazzler
Posts: 31
Joined: Mon Nov 04, 2013 7:43 am

Re: Control Relay Switches via Android using a Raspberry Pi

Thu Dec 26, 2013 4:31 pm

Hi Pelti,

It looks like you may have wired your relay to GPIO Pin 4, it's odd that Relay 7 is showing as on when you go to the webpage (Unless perhaps you activated this pin through the app without realising it?).

If you want to do more testing, try turning all the relays on/off in the app to see which one reacts with your Relay (I presume 4 or 7, but its hard to tell without seeing your wiring.)

The app sends a http get request e.g. to make GPIO 1 active: http://YOUR-PI-IP-ADDRESS/gpio.php?pin=1&status=1

And to make it inactive: http://YOURPI-IP-ADDRESS/gpio.php?pin=1&status=0

Try this in your web browser, chaing the Pin number / Status Number (1 on 0 off).

If this works then the app should work fine, so long as you have the correct IP address in the settings, and have wired up the Pi to Relay on the corresponding GPIO Pin headers.

If you are still having trouble, make sure you can access http://192.168.1.30/gpio.php from your phone, and are connected to your Wifi.
Last edited by jazzler on Tue Dec 31, 2013 4:13 pm, edited 3 times in total.
PiRelay Project : http://bit.ly/pirelay
PiRelay Play Store App : http://bit.ly/PiRelayApp

jazzler
Posts: 31
Joined: Mon Nov 04, 2013 7:43 am

Re: Control Relay Switches via Android using a Raspberry Pi

Thu Dec 26, 2013 4:35 pm

Hi BuffKnysna,

I believe it is possible to control the GPIO headers with other apps in the play store using Bluetooth, but this app (Pi Relay) is specifically designed to work over your home network.

Is there a reason why you would not want to use it over your Wifi/Network? When configured it should be ready to go as soon as you walk into the house and the phone connects to your WiFi network.
PiRelay Project : http://bit.ly/pirelay
PiRelay Play Store App : http://bit.ly/PiRelayApp

jazzler
Posts: 31
Joined: Mon Nov 04, 2013 7:43 am

Re: Control Relay Switches via Android using a Raspberry Pi

Thu Dec 26, 2013 4:49 pm

Hi Richard-TX,

Great call about using a webpage to change/start/stop a radio station. It's got me thinking of tweaking my PHP script to do this or similar from within the app..

Thanks for the feedback
PiRelay Project : http://bit.ly/pirelay
PiRelay Play Store App : http://bit.ly/PiRelayApp

BuffKnysna
Posts: 24
Joined: Thu Aug 02, 2012 12:38 pm
Location: Port Elizabeth, South Africa

Re: Control Relay Switches via Android using a Raspberry Pi

Fri Dec 27, 2013 5:30 am

Hi jazzler

Thanks for the reply. I had in mind an application to use the Pi and my smartphone to control a device which will not be near a home network i.e. caravan park.
I like your concept and will definitely use it around the house.

Does anyone know which bluetooth apps would be suitable?

pelti
Posts: 5
Joined: Wed Dec 25, 2013 1:54 pm

Re: Control Relay Switches via Android using a Raspberry Pi

Fri Dec 27, 2013 8:52 pm

Hi,

I am now using raspberry locally or by localhost.

Only commands -g write 4 or write 7 controls that pin gpio4.
Those url commands (I have tried from pin 0 to pin 30 and 0 or 1 status) do not do anything. Not even locally.

readall command - I can see statuses and they will change only via write commands.

I will download OS + your staff again, and start from scratch.

pelti
Posts: 5
Joined: Wed Dec 25, 2013 1:54 pm

Re: Control Relay Switches via Android using a Raspberry Pi

Sun Dec 29, 2013 7:59 pm

hi, some findings

the url should be
http://YOUR-PI-IP-ADDRESS/gpio.php?pin=1&status=1

so P in pin and S in status should be small (p / s) :(

then the url works.
Now I will check the code how those are there.....

pelti
Posts: 5
Joined: Wed Dec 25, 2013 1:54 pm

Re: Control Relay Switches via Android using a Raspberry Pi

Mon Dec 30, 2013 7:15 pm

Hi Finally something.

I have downloaded the application to Denver tac-70051 tablet, and that is the reason. The application does not work in Denver.
I downloaded it to Samsung phone and Samsung tablet and it works.

Via the browser Denver shows the statuses ok (using those commands earlier this thread), but can not change the statuses maybe it sends the data in differently.

jazzler
Posts: 31
Joined: Mon Nov 04, 2013 7:43 am

Re: Control Relay Switches via Android using a Raspberry Pi

Tue Dec 31, 2013 4:17 pm

Well done Pelti, Thanks for updating with your results. I have updated my earlier post now to reflect the lower case P and S in the link. Sorry I should have been more careful when replying.

Glad you got it sorted now. Its strange that the Denver tac-70051 doesn't post the web command, unfortunately I don't have one of those so can't test on it. However the app just sends an HTTP Get request, so I wonder if there is some kind of firewall built into it blocking the network access built into that devices software.

Anyway, glad you got it working now.
PiRelay Project : http://bit.ly/pirelay
PiRelay Play Store App : http://bit.ly/PiRelayApp

BuffKnysna
Posts: 24
Joined: Thu Aug 02, 2012 12:38 pm
Location: Port Elizabeth, South Africa

Re: Control Relay Switches via Android using a Raspberry Pi

Tue Jan 14, 2014 8:04 am

Hi All
Is it possible to change the GPIO numbers controlled by the relays?
I need to use GPIO pins 7,8,23 and 24.
If it is, must the app be change or the Pi software?
Thanks

jazzler
Posts: 31
Joined: Mon Nov 04, 2013 7:43 am

Re: Control Relay Switches via Android using a Raspberry Pi

Tue Jan 14, 2014 7:53 pm

Hi BuffKnysna,

Yes you can do with with the app 'as is'. What you would need to do is change the PHP code in your GPIO.php file to use an IF statement in your PHP script, that executes the Wiring Pi command to control those pins when something like IF $_GET['pin'] = 1 then command X e.g.

$output = shell_exec('gpio mode 7 out');
$output = shell_exec('gpio write 7 '.$_GET['status']);

and IF $_GET['pin']=2 then command Y e.g.

$output = shell_exec('gpio mode 8 out');
$output = shell_exec('gpio write 8 '.$_GET['status']);


etc.

I can't write this for you at the moment as I don't have time right now so you may need to research the correct syntax for a PHP IF Statement, but it's entirely possible to do this as it is now.

Good luck. If you really get stuck i'll put together a new gpio.php script example for you when I get time. Are you using GPIO Pins 0-7 for something else?
PiRelay Project : http://bit.ly/pirelay
PiRelay Play Store App : http://bit.ly/PiRelayApp

BuffKnysna
Posts: 24
Joined: Thu Aug 02, 2012 12:38 pm
Location: Port Elizabeth, South Africa

Re: Control Relay Switches via Android using a Raspberry Pi

Wed Jan 15, 2014 9:19 am

Hi jazzler. Thanks for the response.
I was stupidly confusing the GPIO designation on the header drawing with the actual gpio pins. :oops:
I have everything working fine. Thanks for the app and the project. :)

Stevepi
Posts: 6
Joined: Sun Jan 19, 2014 4:04 pm

Re: Control Relay Switches via Android using a Raspberry Pi

Sun Jan 19, 2014 4:28 pm

Hi,

I've been wanting to make some kind of automation for my marine fish tank incorporating my Pi and if possible my mobile phone. Having purchased an 8-relay board I began searching for ideas. Then I stumbled across your thread/android app. I've purchased the pro version and downloaded (or manually installed) all the relevant bits on the Pi. The setup instructions were excellent by the way, and everything installed fine.

The app talks to the Pi fine, both within my network and from 'outside' it from the Internet.

My long winded intro is to ask this question:

Whilst most things are on all the time (unless I want to turn them off), my lights are on two separate timers. I can wire into the timers but as they are mechanical ones I can either choose to hardwire them to turn ON with the timer and off/on remotely as long as the timer is in ON mode, or wire them to be switchable whilst the timer is in OFF mode, but not able to switch them off when the timer is ON.

I can do it with two relays per light but that seems excessive. There's probably a simple electrical way of doing this that is staring me in the face but I can't see it.

Therefore, is there a way of coding a timer into the software side of things and doing away with the mechanical timers altogether?
And if there is, would that code need to be on the Pi, or in the app?

I realise that this would require quite a long answer, and I'm not expecting a full re-write of the code (although if anyone wants to you're welcome!), but some pointers in the right direction would be greatly appreciated.

Cheers!
Steve.

alleedx
Posts: 1
Joined: Tue Jan 21, 2014 11:29 pm

Re: Control Relay Switches via Android using a Raspberry Pi

Tue Jan 21, 2014 11:49 pm

Hi,

first of all - thank you for this great project! I have a question about connecting the Relay Module Shield to the Raspberry Pi. The pins on my Relay Module are a litte bit different than on the one used by Jason. Here are some pictures

http://www.directupload.net/file/d/3510 ... 7m_jpg.htm
http://www.directupload.net/file/d/3510 ... bc_jpg.htm
http://www.directupload.net/file/d/3510 ... 5o_jpg.htm

As I am very new to all these things, could somebody of you please help me? Can I connect it as shown on the project-website? In my opinion the order of the 10 pins should be the same and only the pins for the jumper in another place on the module!?

Thank you!

ondrej1024
Posts: 144
Joined: Thu Dec 05, 2013 3:09 pm
Contact: Website

Re: Control Relay Switches via Android using a Raspberry Pi

Thu Jan 23, 2014 2:35 pm

Hi jazzler

I have written a small program to control a USB relay card (4 relays) as announced earlier in this thread. It runs on the Pi and in daemon mode it listens for HTTP requests.

When I was looking for a way to control the relays via an Android app I stumbled across your project. I have now added an HTTP API to my program which is compatible with your app. I tried it with the free version of PiRelay and it works fine. There is no need to run any web server or PHP support on the Pi as everything is built in. As a next step I was thinking of supporting also relays connected directly via GPIO pins.

I have two questions:
- Are you planning to support also a command for single pulse generation on the relays (toggling a relay two times with a short delay in between)
- Any special reason why the PiRelay app doesn't run on an Android 2.2.1 device ? (had to borrow my daughters phone to try the app :( )

Thanks, Ondrej
The Telegea.org project: https://www.telegea.org

Return to “Automation, sensing and robotics”

Who is online

Users browsing this forum: lthomasrx and 11 guests