Hi there,
This is an updated version of my previous Instructable: Control Stuff with your Raspberry Pi (GPIO) Over the internet.

This version is much more secure and could easily be used across the internet with very few security concerns.

A brief outline:
- A server program that runs on the Raspberry Pi to read variables
- A MySQL database to store the variables in
- An Apache2 served webpage to allow control of the variables
Remove these adsRemove these ads by Signing Up
1-40 of 162Next »
Whenever I use ./ and enter in 5 for the wait time it returns with:
./ 53: [: out: unexpected operator
./ 65: [: out: unexpected operator
./ 77: [: out: unexpected operator
./ 89: [: out: unexpected operator
./ 101: [: out: unexpected operator
./ 113: [: out: unexpected operator
./ 125: [: out: unexpected operator
./ 137: [: out: unexpected operator

Any ideas why?
drcurzon (author)  checkers3131 year ago
Hi there.
Does this only happen with a wait time of 5?
Many thanks, Dan.


I have the same problem with every wait time :(

What shall I do?
Thanks in advance

You have to change the code (replacing '==' with '='). Even though you are using bash (check with 'echo $SHELL') the '==' can cause unexpected errors.


echo"out"> /sys/class/gpio/gpio4/direction


echo"1"> /sys/class/gpio/gpio4/value

echo"GPIO 4 Turned On"


echo"0"> /sys/class/gpio/gpio4/value

echo"GPIO 4 Turned Off"




I have the same problem with every wait time :(

What shall I do?
Thanks in advance

Hi i have same problem... I remake it for banana pi and first day it works. And second day i turn on same script and it write same erors. Did you find why ?


superb tutorial but the biggest problem is when we reboot the device we have to run "./" code again and again. what can i do for that?

to start the script aumatically you have to move it into /etc/init.d

ps. sorry for my english i am italian

I had completed step 5 but when i type username "admin" and password "gpio" it incorrect and can't login

NigelT12 months ago



This is a good tutorial. However I am puzzled why it is neccessary

to write a GPIO value to MySQl then read the value out again.

This seem to be a high overhead. Can one not read a GPIO value

via Python in Apache and then display it? This would be much faster.

Perhaps the SPI and I2C data must be stored in MySQL.

Please comment - I need to learn much more about Web and displaying variables from C , Java or Python.

Thank you

MTec007 NigelT11 month ago

You could do it either way, but in my opinion you use the right tools for the job... You let apache do what it does best, and you let the OS do what it does best. The GPIO files are not in the www directory, so it shouldn't be apache's job to read them.. The OS can read the GPIO files, so let it.


Thank you for your input.

Now, one can use hmtl and php5 under Apache to create a Website,

Can one not then access the system using HTML or PHP? Is it possible then to start a Python Programme under HMTL/PHP5 and so access to GPIO but I am unsure about passing that variable to Apache for display.

When SQL is used writing/reading is performed from the SD Card and so is very dependant on the speed of that SD Card - if other programmes/threads also use SQL then it will take longer.

This is to help me learn about the interaction between Apache and the sysem.I still need to get more information - any tips here most welcome.

Thank you for your assistance and help


AidanC11 month ago

Great tutorial. Everything works perfectly.

Keep up the good work.

matthias2t1 month ago

Hi !

Thanks for the tutorial for doomies (as I am), but...

How would it be with Sqlite?

yashmehta71 month ago
What is the port for the ipaddress/control.php website?
MTec0072 months ago

Here is the link to my version of this, for anyone who is interested

MTec0072 months ago

I've made some serious improvements to this. Upgraded to use mysqli, a stronger password hash algorithm, and better interface.

photo 1.PNGphoto 2.PNGphoto 3.PNGphoto 4.PNG
johngriswold3 months ago

Very nice tutorial, as always, Daniel. I just have to learn to be a stickler for following instructions. You present a lot of material - i just have to pay attention.

Thank you very much!

Hello, How are you doing? i got one question im trying to do this but whit the UDOO, but im finding some problems with the, i had never used a Raspberry Pi before... but i don't think in the UDOO you have to invoke the GPIO, this is how it works in the UDOO so if you could help me I will be more than grateful. Thanks

bejot1 year ago
"sudo cp /root/ /etc/init.d/
sudo chmod +x /etc/init.d/
sudo update-rc.d defaults"

Hi, I just did what you wrote and I probably have boot loop and can't login to RPI by SSH. How can I undo it?

I think I have read and avoidet, that starting a script on the raspberry automaticalli with a too litle delay before starting could end in a endless loop and stops the Pi of booting, I´ve taken a delay of 30s.

If this is your probably problem, try the Pi on a display and you hopefully are able to stop the scipt with Ctr+C.

(the Answer 12 Months too late, but if someone els has the problem ;))

viggen5 months ago

Awesome, Is it possible to set up a schedual to control pins seconds per day?

NewHouseTM6 months ago

Great project

Help a lot

Just a demonstration of my automation

Thank you

NewHouseTM6 months ago
joedix8 months ago

Great instruction... no problems yet. How would I be able to add GPIO from the MCP23017 chip into this system?

dpaterson1 joedix7 months ago

I haven't played with this chip, but from what I can tell it uses the i2c interface, and comes with it's own "i2cset" commands.

You'd need to add database entries to represent the additional pins (so you can track thier state and show on webpage), and you'd need to modify to use i2cset commands instead of the /sys/class/gpio commands used for regular GPIO pins.

scorpionx8 months ago

Hi ~ I meet a problem by running shell script

On / Off is sure OK , I press to "Off" , and relay will open , and show the red LED will be light , and press 'On' , relay will close.

But I find a problem , when 'On' , the red let will a little light, sometimes the relay will be open ....

just running shell script will be this problem .


Hi - I'm not sure I entirely understand your problem and unfortunately your video isn't working for me.

Two things to check

1. Is your relay designed to work with 3.3 volt from the GPIO pins? I found a lot of 5volt relays but not all work reliably with the RPI. This could cause inconsistent results.

2. The relay I use inverts my logic. If I send 0 volts to the RPI GPIO pin, this turns the Relay on (and powers my connected device). If I set the GPIO HIGH (3.3 volts) it turns my relay off.

acsooley8 months ago

How can I start the ./ on startup of the raspberry PI? I cant seem to figure it out. Any help please.

Did you try putting the script path into /etc/rc.local ?

Make sure you specify the complete directory path /full/path/ ./ is a relative path and likely won't work.

dpaterson1 made it!8 months ago

Thank you so much for putting up this instructable - this was a great starting point for my own GPIO control webpage.

I made a few modifications as I wanted a real-time response (instead of waiting for the to loop around), and a simple way to group pins together with time delays (turning on an Amp before the speakers in an auditorium etc)

I ended up using WiringPI to do this, after the "TurnOn" button was pressed it calls a Shell Script that calls WiringPI commands. I still track the state of the pins in the SQL database though.

As my system is used by many people I also added a login page, it also sends daily emails via shell script cron job that summarises which users turned items on and off during the day.

As some of my TurnOn/TurnOff scenario's add delay into the webpage reloading, I also used this guys Javascript loading image code to the mix to stop form resumbissions.

Once again - thanks for this example, it got a noob at RPI up and started in no time!

hilbo dpaterson18 months ago

The first script that worked ou of the box!

Thank you for sharing!

@ dpaterson1: Hi, this is exactly what I am working on. Would you mind sharing your script as well?

dpaterson1 hilbo7 months ago

Here's an example shell script I stored in /opt/scripts/

Make sure is executable "chmod 755"

***** contents*****


#WiringPi GPIO 1 = BCM 18 = Physical Header 12


#Set GPIO 1 = PIN 12 as an Output

gpio mode 1 out

#Change GPIO 1 voltage to High

gpio write 1 1

*******PHP Code*****

$groupOnScript = "/opt/scripts/";


m3mn0t dpaterson17 months ago

Can you help me ?Can you provide your code? or simple help me with something?

m3mn0t7 months ago

Hi how can i talk with you


imohammad8 months ago

hello there, thank you for the tutorial~!! i want to ask, if the gpio is set to input. If i gave the input a signal (on) does the web page update the input status?

I don't believe it does - would need to be modified to read the status of the GPIO pins, then load it into the mysql database.

Then the web page would read the database and show the status.

thanks for the info ^^

Hello, Wondering if you can help. Great tutorial by the way however i have followed everything through but when i type ./ and enter a value it automatically turns on any GPIO pins that are connected and then nothing plays ball after. Any ideas of where i am going wrong? Cheers
drcurzon (author)  aztecthegeordie10 months ago
Hi there - can you send me the file?
Thanks - Dan.
1-40 of 162Next »