Control Stuff With Your Raspberry Pi (GPIO) Over the Internet





Introduction: Control Stuff With Your Raspberry Pi (GPIO) Over the Internet

Please Note:
This Instructable is now depreciated.
Click here for the updated, much improved, version.

Hi there,
This will hopefully show you how to control electronics across the internet using your Raspberry Pi.
It's not the best way to do it, and soon I will update this with a way to use MySQL to do the same thing.

Here's a link to YouTube showing it in action:

For this, please ensure that you have apache with php running on your Raspberry Pi, Instructions can be found here.

Also, it would be a good idea to read my previous instructable on general GPIO control, which can be found here.

Step 1: Overview + Warning

This is not the best way of doing this, and I hope to update this soon with a MySQL solution.
Until then, I'd recommend keeping this to your local network (not over the internet yet).
However, there shouldn't be any issues, it's just a warning. :D

This will (at the moment) allow you to control your GPIO pins via a web interface.
The program running on your Raspberry Pi checks to see if a file exists, if it does - it turns the output on, otherwise it turns it off. All the web interface does (at the moment) is to either create or delete this file.

Step 2: Web Page Code

The web page is really quite simple, and is one php page.
As earlier, you will need Apache and PHP installed onto your Raspberry Pi (A guide can be found here).

The php code is attached to this step, and must be uploaded to the raspberry pi (/var/www/ directory).

Step 3: Shell Script Code

The shell script attached must be run on the server as root.

Upload this to your Raspberry Pi, then perform the following commands:
mv gpioCheck.txt
chmod +x

It will ask you to input a delay - 1 second is usually quite good, although if you enter 0 there will be minimal lag between you pressing the web button, and the raspberry pi setting the GPIO.
PLEASE NOTE: This is timed in seconds by default.

It will then ask you for the GPIO number, not the pin number. (attached is a pinout)
I used 21 for this example.

Then it will output whether or not the web interface has told it to be on or not.

Step 4: Finish

That's it really,
Just run the shell script (./ and click the buttons.
The rest is up to you.

If you felt lost, you might want to check out this instructable first, otherwise leave a comment :D
Hope this helps,



    • Microcontroller Contest

      Microcontroller Contest
    • Spotless Contest

      Spotless Contest
    • Science of Cooking

      Science of Cooking

    We have a be nice policy.
    Please be positive and constructive.




    Hii, I have a doubt. My main project is home automation using internet in which i have to control speed of fan at five different levels from internet. I designed a web-page and kept 5 buttons in it. I am able to send signal to raspberry pi when i press any one button. Now my problem is what should i write additionally and also what task should i do so that i can interpret the incoming signal to pi and accordingly generate square wave pulses from my GPIO pins of pi.


    where is the text ? i dont see for download , please help me

    hi great tutorial , just what I`ve looking for . I do have one problem
    julian@GridCamera:~/PiStuff/php_2_gpio$ ./
    Please enter a wait time
    ': not a valid identifieread: `waitTime
    Please enter GPIO number
    ': not a valid identifieread: `pin
    ./ line 24: syntax error near unexpected token `fi'
    ./ line 24: `fi'

    I get the above error. Not clued up on sh any ideas.


    Hi, first of all a great tutorial, but I'm having a problem since I'm a beginner with raspberry. I followed all the steps but something is wrong. .
    When I open the web page in my browser I don't see anything.

    I tested the php5 and apache server and they both work.

    Please help.

    hi, i have a problem.
    i am beginner for Raspberry, shell script and web.

    1. when i run the web, and i press "turn on" button. the browser say "can't open file"
    2. when i run, the command exit is always "turn on" although i press "turn off" button on a browser.
    Can anyone help me to be able to run like the one in the video
    many thanks. mima

    Oh just read the overview and got it now thanks xD ill try it latter...

    Hi, dont know if im wronge but isn't there 3 files in this project?
    gpio.php (webpage) (bash script running on server)
    gpio.txt (txt file were the status of the pin is stored)

    do you have the code for the .txt if there is any at all?


    Hello, I have a problem

    1) I create a php file with the given code (gpio.txt) then I placed in var / www
    2) I create a txt file with the given code (gpioCheck.txt) then I placed in a directory (the first available: home)
    3) I logged in as root via Putty and i placed in the home directory (cd / home)
    4) I have run this commands :

    -"mv gpioCheck.txt"
    -"chmod +x"

    5) and this is what I get:

    I don't Understand !! What's the Problem ??? Thanks

    Try changing the wait time to 1.
    Many thanks. Dan.

    the problem does'nt looks to be here :
    I am not a specialist, but there seems to be a problem in the script "gpioCheck",

    Here is the code I downloaded and copy:

    "echo "Please enter a wait time"
    read waitTime
    echo "Please enter GPIO number"
    read pin
    if [ "$pin" != "4" ] && [ "$pin" != "17" ] && [ "$pin" != "18" ] && [ "$pin" != "21" ] && [ "$pin" != "22" ] && [ "$pin" != "23" ] && [ "$pin" != "24" ] && [ "$pin" != "25" ]; then
    echo "Pin error - GPIO number doesn't exist"
    echo "$pin" > /sys/class/gpio/export
    echo "out" > /sys/class/gpio/gpio$pin/direction
    while :

    if [ -f /var/www/gpio.txt ]
    echo "Turn GPIO on"
    echo "1" > /sys/class/gpio/gpio$pin/value
    echo "Turn GPIO off"
    echo "0" > /sys/class/gpio/gpio$pin/value
    sleep $waitTime