Raspberry GPIO control from Phone

Friday, September 2, 2016

This project will show how to control Raspberry GPIO from Phone.
Local web server is using for php page, which receives command from Web Browser (or from Phone Apps), then control GPIO.

Overview steps are:
1. Make Web server & php page
2. Make simple circuit
3. Control GPIO from Web Browser
4. Control GPIO from Phone Apps (Android)




1. Make Web server & php page
1.1. Install WiringPI
WiringPI is used to control GPIO
$ sudo apt-get install git-core
$ sudo apt-get update
$ sudo apt-get upgrade
$ git clone git://git.drogon.net/wiringPi
$ cd wiringPi
$ git pull origin
$ cd wiringPi
$ ./build

Checking after installation WiringPI
$ gpio mode 0 out
->If nothing special appears, everything's fine.

Sample command, write and read pin 1
$ gpio write 1 0
$ gpio read 1

1.2. Install web server:
Install Apache HTTP server and PHP5 extension
$ sudo apt-get install apache2 php5 libapache2-mod-php5
If everything is OK, local web will display in Web Browser as following:
    in which: 192.168.1.71 is Raspberry IP address
                  the file page index.html is store in /var/www/html/

1.3. Make PHP page to interface GPIO
PHP page helps to receive command from Web Browser, then send control command GPIO  to board through WiringPI (install in step 1.1)
Following is php code for ON/OFF GPIO7
<?php
//engineer2you.blogspot.com

//Getting and using values

if (isset ( $_GET["pin"] )) {
 $pin = strip_tags ($_GET["pin"]);
 
 //test if value is a number
 if ( is_numeric($pin)) {
  //set the gpio's mode to output
  if($pin==70){
   system("gpio mode 7 out"); //GPIO7
   system("gpio write 7 0");
   echo('finish pin7 = off');
  }
  if($pin==71) {
   system("gpio mode 7 out"); //GPIO7
   system("gpio write 7 1");
   echo('finish pin7 = on');
  }

  if($pin==80){
   system("gpio mode 8 out"); //GPIO8
   system("gpio write 8 0");
   echo('finish pin8 = off');
  }
  if($pin==81) {
   system("gpio mode 8 out"); //GPIO8
   system("gpio write 8 1");
   echo('finish pin8 = on');
  }

  if($pin==90){
   system("gpio mode 9 out"); //GPIO9
   system("gpio write 9 0");
   echo('finish pin9 = off');
  }
  if($pin==91) {
   system("gpio mode 9 out"); //GPIO9
   system("gpio write 9 1");
   echo('finish pin9 = on');
  }
 }
 else { echo ("fail, it's not number".$pin); }
} //print fail if cannot use values
else { echo ("fail"); }

?>
Complete php file for controlling GPIO7, GPIO8, GPIO9. Download from this link

2. Make simple circuit
Connect LEDs to GPIO7, GPIO8, GPIO9

3. Control GPIO from Web Browser
For example, to make GPIO7 off, put the address in Web Brower: http://192.168.1.71/io.php?pin=70
To make GPIO7 on, put http://192.168.1.71/io.php?pin=71

4. Control GPIO from Phone Apps (Android)
There is an Android Application can be used to send command to php page.
The App can be downloaded from link Google Play or search by keyword Data2Server

Following is setting for php address, pin:






13 comments

  1. can we send a feedback from raspberry pi to android app b using current sensor at output of bulb if bulb is on then current sensor give high signal to raspberry pi gpio pin and then raspberry sends feedback to android app

    ReplyDelete
    Replies
    1. We can do it. However, it will make system quiet complicated. So i don't make it.

      Delete
  2. I am trying to make this, If it will be done , I will share with you.

    ReplyDelete
  3. really appreciate that its working thank you.
    i have some question regarding homeautomation can you mail me
    2492vishalsingh@gmail.com

    ReplyDelete
    Replies
    1. Hi, we can discuss here in comment box, or go to discussion board in this blog. I love finding solution after discussion.

      Delete
  4. need source code for android application..??

    ReplyDelete
    Replies
    1. unfortunately we can't give you that. It's not complicate, just send command like "http://192.168.1.71/io.php?pin=71"

      Delete
  5. This comment has been removed by the author.

    ReplyDelete

  6. Please click on this post if you wanna paly with online casino.Thank you.

    ทางเข้าจีคลับ
    โกลเด้นสล็อต

    ReplyDelete
  7. Please click on this post if you wanna paly with online casino.Thank you.
    บาคาร่า online
    goldenslot
    gclub online

    ReplyDelete
  8. Wow its a very good post. The information provided by you is really very good and helpful for me. Keep sharing good information.I bookmark your blog because I found very good information on your blog

    ดูหนังออนไลน์

    ReplyDelete

 

Search This Blog

Most Reading

Google+ Followers

...