The Raspberry Pi is an amazing 35 dollars mini-computer. It allows you to do everything you could do with a regular Linux computer (Connecting to the internet, watching videos, launching applications, ...) but also to interact with the world surrounding it, just like an Arduino. That's why I qualify it as a mix between a computer and a micro-controller.
That's also why I chose it for this project. I'm going to show you how to control LEDs with your Raspberry Pi. Firstly directly from the Raspberry Pi itself, then from any device in your house like your Smartphone or your tablet.

Here is a very good example of what you can achieve after reading this Instructable: http://www.instructables.com/id/Web-Controlled-8-Channel-Powerstrip/. Thanks to Rleddington for his amazing project.

Update: French version here

Step 1: The electronic part

     The electronic part is nothing special, it's only 8 LEDs with their protecting resistor. The only hard part is to connect the LEDs to the good pin on the Raspberry Pi. Indeed, I'll be using later a library called Wiring Pi made by Gordon Henderson (You can visit his website at: http://wiringpi.com/) and the pin's numbers used in this library aren't the same than the ones on the Raspberry Pi. See this page for matches: http://wiringpi.com/pins/ (just be careful about your Raspberry Pi revision, the pinout isn't exactly the same). I'll be using Wiring pins 0 to 7.
     Concerning the resistors, they should be 270Ω but since I don't have this precise value, I'm using 560Ω resistors (LEDs are just less bright).
     Finally, I've made two schematics to make it simpler. The first one (with the complete Raspberry Pi) is showing you the real pins as they are shown on the board. The second one is a simplified version, it's showing you only the useful pins and their matches in the Wiring Pi library (GPIO Wiring number/Actual number on the board).

Step 2: Installing and using the Wiring Pi library

As said before, Wiring Pi is a library. It simplifies a lot using the Raspberry Pi GPIOs (one command instead a long process). It also means that you can use it in any of your C codes. However, we won't build and use a C program but the Gpio utility. It's a software made by Gordon and coming with the library. It allows you to control the GPIOs in a bash script or directly in a command line. Using this utility is however a lot slower than a C program.

We first need to install it. Gordon himself is explaining it very well on his website: http://wiringpi.com/download-and-install/. You just need to download it from GIT then to build it using the ./build command.
You should now be able to use the Gpio utility, type the "gpio mode 0 out" command to test it out. If nothing special appears, everything's fine. Else, if the board is printing "command not found error" or something like that, be sure that you've followed the guide and build the library.

Let's turn on and off the first LED (Wiring pin 0). You first need to set the pin as an output. Use the "gpio mode 0 out" command to do so. "0" is the wiring pin number and "out" simply stands for output. Now, use the "gpio write 0 1" command to turn on your LED. "0" is again the pin number and "1" is the status (1 for ON and 0 for OFF). If everything's fine you should see your LED shining. To turn it off, simply use the "gpio write 0 0" command.
Just a little tip, if you want to use the actual pin number (GPIO-17) instead of the Wiring Pi number (0 is corresponding to GPIO-17), use the -g flag in your command. Ex: "gpio -g write 17 1" instead of "gpio write 0 1".

There is also the "gpio read" command which allows you to read the pin's status. It may seems useless when the pin has been set as an output but it allows you to be sure of the pin's status when you can't see the LED. Using it is as simple as before, just type "gpio read 0" where "0" is the wiring pin number. The command is returning the pin's status (again 1 for ON and 0 for OFF).

Finally the Wiring Pi library is containing a lot of other commands/functions but I'm not gonna cover them in this instructable since there are not useful here. See this page if you are more curious: http://wiringpi.com/reference/ (library's functions) and https://projects.drogon.net/raspberry-pi/wiringpi/the-gpio-utility/ or the "man gpio" command for the Gpio utility.

Now that you can use this utility, let's play a little bit with it. You can first, if it's not already the case, control remotely your Raspberry Pi with SSH. You can use Putty for Windows or ServerAuditor for your Smartphone. Then have fun with bash scripts such as this one which is turning on LEDs 0 to 7, waiting 2 seconds, then turning them off again:


#set mode to output
for i in 0 1 2 3 4 5 6 7;
do gpio mode $i out;

#turn on LEDs 0 to 7
for i in 0 1 2 3 4 5 6 7;
do gpio write $i 1;

#wait 2 seconds
sleep 2;

#turn LEDs off
for i in 0 1 2 3 4 5 6 7;
do gpio write $i 0;

Step 3: Installing a web server then transferring your website to it

Controlling the LEDs remotely with SSH is pretty cool but the interface (console) isn't very user friendly and typing the commands every time is long and annoying. That's why we need a graphical interface for our project.
Programming an app for each OS (IOS, Android, Windows phone, Mac, Linux, Windows,...) would be too long and would require to know a lot of different languages for nearly nothing. It would also require to do an application running on the Raspberry Pi. Making it this way would be overkill and time wasting.
That's why a website is the best solution, it's compatible with all devices and you "only" need to know four languages: HTML (for the page's skeleton), CSS (page's style), PHP (interactions with the server) and JavaScript (interactions with the user).

We indeed need to install a web server on the Raspberry Pi. In our case, we don't need a MySQL database, only a HTTP server and its PHP extension.
After updating your Raspberry Pi with the "sudo apt-get update" command, type "sudo apt-get install apache2 php5 libapache2-mod-php5" to install Apache HTTP server and PHP5 extension. You can now test if your server is working by typing the IP of your Raspberry Pi in your browser. You should now see a "It works!" page with two other lines. If you don't, then check your board's IP, try re-installing Apache or rebooting your Raspberry Pi. This page is showing that your Apache server is working properly but not its PHP extension. To check it, navigate to your "/var/www/" directory by using the "cd /var/www/" command. If you use the "ls" command, you should have only one file named "index.html". This file corresponds to the "It works!" page. You can now delete it ("sudo rm index.html") and create another one called "index.php" (use "sudo nano index.php"). Then type the following text:


After saving it using ^o (Ctrl + o), exit nano editor with ^x (Ctrl + x). Now if you refresh your browser, you should see a long page with lots of information about your server and PHP. If you don't, check the index.php file, try re-installing PHP or try to understand the error displayed instead of the page (Google it if necessary).

If both pages were correctly displayed, then you now have a fully functional Apache/PHP server but using nano every time is annoying and not very comfortable. We indeed need to transfer files from your computer to your Raspberry Pi. You may want to install a FTP server but it isn't necessary, you can already transfer files using the SFTP protocol. All you need is an SFTP client on your computer. I'm personally using WinSCP for Windows but there are Cyberduck for mac and Filezilla for Linux. If you try transferring files before reading what's next, you'll probably have issues such as "access refused" or "cannot write here". It's due to the fact that the user pi isn't owning the www directory. Indeed, if you try the "ls -l /var/www" command, you'll see that only root (the super user) is owning the www directory. You can (like I did) use the "sudo chown -R pi /var/www" command to change it or create a group named www-data in which you place the pi user then use the "sudo chown -R www-data /var/www" command. The -R flag is standing for recursive, it means that the user/group isn't owning only the directory itself but also everything inside (index.php as example).
You now have your server ready to work and to receive web pages. Have fun with it if know HTML, CSS and PHP.

Edit: Apparently, apache's default folder has been changed to "var/www/html" so may need to adapt the previous commands.

Step 4: Controlling the LEDs with PHP

We now have a web server and a library, let' put them together.
PHP stands for "PHP: Hypertext Preprocessor", It's a server side scripting language. It means that the PHP code is executed once (each time the page is requested) by the server and cannot be seen by the client. I used this language because it's the most popular (and that's the only one I know) but you have to know that they are other server side languages like Python, Ruby, Lua, Perl, ... However, I don't know if the functions we are gonna use have their equivalents in these languages.

Executing applications with a PHP code can be done with two different functions: exec (for execute) and system. Firstly, the "system" function. It takes two parameters: "system ( string $command, int $return_var )", as you guessed it, the first parameter is the command to execute and the second one is the returned status of the executed command. The second parameter isn't compulsory. You can use this function if you don't expect an answer from the command executed. Thus, you can use it if you need to execute "gpio mode 0 out" or "gpio write 0 1" commands. Example:

     system ( "gpio mode 0 out" );
     system ( "gpio write 0 1" );

Then, the "exec" function. This function is making exactly the same work than "system" but it reads and stores what the command printed. It takes three parameters: "exec ( string $command, array $output, int $return_var )", again $command and $return_var are the same parameters and the only difference is the $output array. As it's name says it will store the command's output in an array. Thus, you can use this function if you need what the command prints like with the "gpio read 0" command. Example:

     exec ( "gpio read 0", $status );
     print_r ( $status );

You can now execute nearly whatever command you want but let's make a little PHP example to practice: We will turn on LEDs 0 to 7, then wait 2 seconds, then turn them off. Just like we did with the bash script. Edit the index.php file with the following code:

$status = array ( 0 );
//set pins mode to output
for ($i = 0; $i <= 7; $i++ ) {
     system ( "gpio mode ".$i." out" );
//turns on the LEDs
for ($i = 0; $i <= 7; $i++ ) {
     system ( "gpio write ".$i." 1" );
//reads and prints the LEDs status
for ($i = 0; $i <= 7; $i++ ) {
     exec ( "gpio read ".$i, $status );
     echo ( $status[0] );
//waits 2 seconds
sleep ( 2 );
//turns off the LEDs
for ($i = 0; $i <= 7; $i++ ) {
     system ( "gpio write ".$i." 0" );

Step 5: Making the interface

We can now control our Raspberry Pi with simple PHP scripts but there is no interaction with the user and thereby we can't choose the LED to turn on/off. Let's make the interface!
It's composed of pictures I've found on Google images (search for "on/off button"). One was green and the other one red, I just added the number using The Gimp. Each picture/button is corresponding to its LED, so if you click on one of these, the corresponding LED will be turned on/off and the picture will be changed to its green/red version. The page's skeleton will be made with HTML, the server interactions and page's generation with PHP and at last JavaScript to manage interactions with the user and page's animation. If you don't know, JavaScript is a client side language and unlike PHP, it's executed not once, but continuously by your browser. That's why you can change the page's look without reloading it or accessing to an other. If you are wondering why I spoke about CSS before, it's just because we need it for some style and page-layout like the the black background. I didn't make a full .css file because it wasn't necessary here.
We first need an "index.php" file (extension is .php and not .html cause we will use PHP code, it helps the server to know if there is PHP to execute before sending the generated page). This page is the main page containing the 8 buttons. These buttons are first generated with a "exec ( "gpio read ".$i, $output );" in a for loop. Then we need to detect when the user is clicking on one of these buttons. That's where the JavaScript is useful, I put it in a separate file called "script.js" but it's still included in index.php. The script is simply adding an event listener to all of the eight buttons and each time one of these is pressed, it uses a function which is asking for gpio.php, receiving the answer then returning it. Finally, in function of this, the JavaScript changes the button to red (for OFF) or to green (for ON). Now, the last page: gpio.php. It contains the PHP code to turn on/off the LEDs in function of what the JavaScript function sent. The user shouldn't normally ask for this precise page but there is one golden rule when creating websites and you should always remember this one: "NEVER TRUST THE USER". In other words, never think the user is always gonna do what you think he's gonna do. Thus, I added some securities at the begin of the PHP code like making sure the user gave a correct value and not a letter as example. I made a small diagram to sum up all this text.

You can download the full project directly on this website below.

Step 6: Conclusion and ideas of improvements

This small but long explained project was fun and I learned a lot. I hope you did the same. However, controlling LEDs isn't very useful. That's why what we made is rather a tool than a real project. Christmas is soon (about one and a half months from the day I wrote this instructable) so why not replacing LEDs by relays and controlling lights around your house. There are some pretty good relay boards for the Raspberry Pi on Ebay and more generally on the Internet. Alternatively, and if you're not scared about working on your house, you can even control your house's lights, garage door, coffee machine, heating system, ... The only limit is your imagination.
There are also a lot of possible improvements like changing the interface, adding more LEDs via a shift register, using vocal recognition, ... In addition, with PHP, you are not limited to gpio write or read. You can use the full Gpio utility and thus interact with other devices with UART or any other implemented protocol. You can also use PWM (Pulse Width Modification) to control servos, ...
Writing this Instructable and sharing my little knowledge was a great pleasure for me and I hope it was the same for you to read it. I tried to keep it simple but at the same time to teach the most possible. I didn't want to do a simple and dumb step by step: "download this code, run it, you're done". I think that something is useless to learn until you understand how it works or why you do this and not that. Let me know if you think it's the good way or if I should do it otherwise.

PS: This is my very first instructable and English is not my native language so if you have any comment, advice, suggestion, idea, ... Just let me know, I'll be glad to answer you and of course to learn.

<p>This was fantastic!! I'm turning on a tea kettle remotely with this and it works like a charm. I am controlling two outlets with this so I edited the code down to two options, no need for loops in this case (but in the future....). My question is, and I think it was asked earlier: If you turn on the LED, then refresh the page, the page doesnt initially read the value of the Pin. </p><p>I have two relays I am controlling, if I turn them on, they show on in the browser, then I refresh browser, they show off on the browser but are still on. They will turn off if I click the button, and then the cycle is properly rest and the buttons turn on and off.</p><p>I am trying to write up a javascript read function that reads the status of the pins when the page loads...no luck in the last 15 minutes or so but unless someone else figures it out, I will post when I'm done! This isnt a serious issue, just would be nice to have. great instructable!! oh... I did it!!</p>
<p>quite a simple solution... :) I just told GPIO via php to set all status to zero as first line...this way, no way any outlet could be accidentally forgotten or left in an unknown but truly &quot;On&quot; state </p>
<p>Perfect guide that helped me with some things I didn&acute;t get to work with one of my Pi-project. I don&acute;t have so much PHP knowledge so I have one question: Is it possible to get the status to update if the GPIO value changes from another script? Of course I can set auto update on the page but it will &quot;flash&quot; every time it updates... </p>
Hi,<br>In your case, a good and easy solution is to create a kind of JavaScript routine calling a function every x seconds. That function would simply ask the server for the pin's status and update the page in function of the response. No &quot;flash&quot;.<br>The only problem is that you have to create the JS routine (google is you best friend I would say), the JS function called by the routine and waiting for the response, and the PHP function reading and printing the pin's status. Fortunately, these functions are very similar to the one used in the code so you shouldn't have much problem writing them.<br><br>Hope I helped,<br>TheFreeElectron
<p>hello, thanks for the tutorial</p><p>i have a problem with change the pict, the pict can't show why i change the pict. i have already change the name of pict with same than your code. but the pict what i want don't show. can you help me for fix the problem ?</p><p>the function of controll work perfect, but the pict won't show correct</p>
<p>Hello,</p><p>Maybe you forgot to update the access rights of the pic? If you didn't, Apache cannot use and display these pictures.</p><p>Hope I helped,<br>TheFreeElectron</p>
thanks for reply me.<br><br>i found the problem, the problem is i forgot change the permission pict. <br><br>when i change the permission, the pict change correctly :D
hi <br>does it works on raspberrry pi 2 ?
You may need to make some minor changes but I think yes.
<p>Dude, its amazing. I will try it soon and click &quot;I Made it!&quot; button. Wish Me LUck :)</p>
Thank you TheFreeElectron for the tutorial!<br><br>How can I control LEDs that are connected on different raspberry pi devices (on same or different networks) from the same web page?
And can a nonexpert do it?
<p>HEY!!!</p><p>One last quick question...</p><p>I am almost finished my enclosure! :)</p><p>I was wondering if it was possible to add a status led for when my relays are powered?</p><p>I am already using an 8CH relay with status LED's, but these will now be closed inside the case. I'd like to add LED's on the cover of the case, so I can see which relays are on without opening the cover...</p><p>Would I be correct to breakout the pin of the GPIO I wanted to control, and add an LED (with a corresponding resistor) like that??</p><p>I (tried) to draw what I'm trying to say in paint. You may want to grab some popcorn before viewing; it's quite entertaining... </p><p>Basically the RPi, pin for relay board, and led's anode would all connect in the same row, with the cathode and the relays &quot;-&quot; connecting in a row of its own on the protoboard. Any future LED's would be connected the same way.</p><p>IS THIS CORRECT? :S (thk u for your time)</p><p>I'll take some pics when everything is complete :)</p>
Hey!<br> <br> Here's a link for you about how you should connect your LED. The way you did it seems to be the good one&nbsp;<a href="http://forum.arduino.cc/index.php?topic=126629.0" rel="nofollow">http://forum.arduino.cc/index.php?topic=126629.0</a>&nbsp;(Although your drawing is as you said, entertaining... :p). Also, don't forget to connect the Rpi's GND to the relay board's GND.<br> Btw, try fritzing to draw your schematics, it's a very nice and free software.<br> <br> Why not publishing an 'Ible about your project later?<br> <br> Hope I helped,<br> TheFreeElectron
<p>Fritzing is like my long lost friend thk u!!!!!</p><p>I've decided to incorporate 555 timers to make the external status LED's blink when the circuits are closed.</p><p>I've gotten everything tested, just waiting for my parts to come in from China (a 555 timer locally is something like $5, I got 10 from China for under $2) to complete everything (finally).</p><p>Once finished I will post back with the completed project. </p><p>I never thought of making an 'ible but it's a great idea!!!! I've always wanted to contribute some way and it seems like a good place to start!</p><p>Thanks a million again!!! :D:D</p>
<p>No problem, it was a pleasure to help!<br>Now, enjoy your own project. As I said, my 'Ible is like a tool and it's up to you to make something with it. In your case, you did it in a clean and very useful way. Congrats! ;)</p><p>TheFreeElectron</p>
<p>No problem, it was a pleasure to help!<br>Now, enjoy your own project. As I said, my 'Ible is like a tool and it's up to you to make something with it. In your case, you did it in a clean and very useful way. Congrats! ;)</p><p>TheFreeElectron</p>
<p>Hey I wanted to do something like home automation, for my room specifically, like you did here but also want to stream video from my Pi cam (or webcam) side-by-side of my room to seen in actual when I turn on a light does it actually lit up. Any idea how to integrate a web stream of my pi cam (or webcam) into your program?</p><p>Thanks</p>
<p>I have no idea how to do this with solely the RPi, but I have an ip camera that i look at to see if my kids have left the tv on, at which I can shut it off. I can view the cameras from any mobile device or pc so it is very easy for everything to work in harmony.</p><p>Also this way you can have WAY more cameras, and you aren't limited by the length of USB wire.</p><p>I have cameras on every level so I can see if the tv is on, if the lights were left on, etc..</p><p>Have had it set up like this since around december with NO problems whatsoever.</p>
Hi!<br><br>Sounds like an amazing idea! Streaming a webcam isn't something very easy to do by yourself so you are very likely to find and use a software. This soft (installed on the Rpi) will get the video stream from the Pi cam, then broadcast it with its own server. To integrate this stream into your project, you would just add a video object to index.php with as address, the address and port of the webcam server. Try to google your project, with all the applications the Rpi has, someone has probably already done the search and work for you.<br><br>Hope I helped,<br>TheFreeElectron
<p>This is a realy good and easy way to stream your camera. http://elinux.org/RPi-Cam-Web-Interface</p>
<p>This is a cracking Instructable, and I can see me using it for much more than I am at present.</p><p>I have a couple of SkyHD boxes that (typically) crash from time to time, and Sky's solution is to pull the power cord. When the boxes are mounted in a busy rack, this isn't quite so easy.</p><p>I have made some changes, including paring the UI down to 2 circuits and adding a little text here and there so my other half can understand it, as well as using my own images.</p><p>All I need to do now is mount it in a neat enclosure.</p><p>Good work TheFreeElectron!!</p>
<p>Very nice! I see there a very practical and useful application! With, by the way, a nice and clean interface.<br>Good work to you too!</p>
How to access blocked websites in colleges or schools<p><a href="http://www.besthacktricks.com/how-to-access-blocked-websites-in-colleges-or-schools/" rel="nofollow">http://www.besthacktricks.com/how-to-access-blocke...</a></p><p>Grab all the tricks and tips on latest android phones,apps,iphones and latest technews at www.besthacktricks.com...visit now!</p>
Best Tips to Build a Great and User Friendly Website<p><a href="http://www.besthacktricks.com/best-tips-to-build-a-great-and-user-friendly-website/" rel="nofollow">http://www.besthacktricks.com/best-tips-to-build-a...</a></p><p>Grab all the tricks and tips on latest android phones,apps,iphones and latest technews at www.besthacktricks.com...visit now!</p>
<p>How would you go about creating an all button for these versus the individual buttons or in addition to the already configured buttons?</p>
You can do it either in the Javascript: Add a button then attach it to a function calling change pin for all leds. Or in the PHP: add a eighth button, when the PHP receives change pin's request for this button, it turns everything on or off.
<p>I understand the layout of doing it, just not super familiar with the structure for coding the all button</p>
<p>I'm sorry but I don't have the time to write a sample code. Inspire from the current project, add a button and use one the two solutions described in my previous comment.</p>
<p>Thank you to share</p><p>Is possible do for 200 LEDs ? what i need do ?</p><p>thank you in advance</p>
Hey!<br><br>Well 200 LEDs is quite a big number and since the Rpi doesn't have 200 GPIO ports, you'll have to use some external components to control all these LEDS. One of the most common solution is to use a chip called a shift register, like the 74HC595 which can control 8 LEDs with only 3 Rpi ports. Also you can stack these chips one after the other to control even more LEDs with these same 3 ports (there is however a limit). I let you google the previous terms.<br>There are many other chips but the choice is depending on what you want to do these LEDs.<br>Finally, be aware that my code is not well adapted for high speed changes and operations, you might need to change several parts of the projects depending on your objective.<br><br>Hope I Helped,<br>TheFreeElectron
<p>I am looking to expand to 36 with two mcp23017 but I am a bit stumped. Any ideas on where to start with that?</p>
<p>Take a look at these, your chip is using I2C which should be supported by Wiring Pi:</p><p><a href="https://learn.adafruit.com/mcp230xx-gpio-expander-on-the-raspberry-pi/overview" rel="nofollow">https://learn.adafruit.com/mcp230xx-gpio-expander-...</a></p><p><a href="http://www.raspberrypi-spy.co.uk/2013/07/how-to-use-a-mcp23017-i2c-port-expander-with-the-raspberry-pi-part-1/" rel="nofollow">http://www.raspberrypi-spy.co.uk/2013/07/how-to-us...</a></p>
<p>Thanks! I have already ordered some of these chips to try out. I don't have a large exposure to java, so getting that aspect to work has me a little concerned. </p>
<p>I understand but there's nothing to really worry about. Take a look at the wiring Pi library's reference. You should find everything you need to use I2C and your chips. Enjoy! ;)</p>
<p>pretty good the project is quite straight forward although my gpio write 0 1 and gpio write 0 0 are interchanged i though i had wired badly but i checked my all my pins when in write 0 the lights turn on when i write 1 the lights come on ? any ideas why </p>
I've heard about that issue several times. I have no idea about what may cause it. The code perfectly worked on my Rpi 1. Maybe the Pi 2 is in cause?
<p>I just wanted to say THANK YOU. This project is above-awesome, and I've had the &quot;PowerPi&quot; built for around a week. The instructions given worked flawlessly. I made this to help control my tv's / monitors / lights to help keep the hydro cost down. </p><p>The only problem I had was one that was stated in the comments, where the incorrect image was displayed ( all pins set HIGH instead of LOW).</p><p>I found, through trial and error (and hair pulling, I honestly had to look up everything, I have minimal programming background... If I didn't have google I'd be lost) that index.php AND script.js had to be changed in order to get the correct pictures. Initially I had only changed one of them (can't remember which one). I'm not sure why, but everything was working great, then all of a sudden the images wouldn't refresh. I've been looking at the scripts since last night and it was not 5 minutes ago that I came across this. Yes, everything is up and running with 3 / 7 relays populated so far.</p><p>I'm cutting out a Brinks metal case to house everything. There's already mounting holes and a keylock so it should add some nice finishing touches.</p><p>I'm looking forward to more instructables from you! I have fun trying to understand your scripts since you make them easy to understand.</p><p>Keep it up!!!! :D</p>
Thank you for the cheering!<br>The best reward is to see what you can do with my 'Ible. Home automation is a rising domain where applications are nearly boundless. Doing it yourself is just amazing. Btw, your project looks really nice and, that is to say, very clean ;)<br>You are not the first one having trouble with &quot;reversed&quot; relays. Adding a 'reverse' option to my script would be nice. However, my studies are very time consuming. I hope next year will give me more time to create and share. :)<br><br>keep it up too :) <br>TheFreeElecton
<p>Hi, I really like your tutorial. I just had one question. I didn't personally get to test this, but I'm assuming because this is written in PHP, that everytime you click a button, it will redirect the page in order to run the GPIO code. Is there a way to execute GPIO code without reloading the page?</p>
Hi!<br>Thank you!<br>Actually, I used JavaScript so that it doesn't need to reload the page. PHP is used to execute the linux commands and is indeed executed once, but that is what we want.<br>Everytime you click a button, JS asks for the PHP page. This page will execute gpio commands and print the updated pin's status. The JS receives this as a response and then updates the page you're on, without reloading.<br><br>Hope I helped,<br>TheFreeElectron
<p>I see that now, looking through the code. However, I want my Pi to be controlling PWM pins, and that means the pins will not be binary, they will be between 0 and 255 (I believe). Is there any way to store this other than a database? Or this that my only option?</p><p>Sorry for bugging you so much,</p><p>Ankur</p>
<p>The PWM option is explained in the wiring pi's reference. You should find everything you need there. Among which the value's range.</p><p>I see two options to store data:<br>*Use a database, but it is relatively slow and long to implement.<br>*Use a file, it is very easy to implement and doesn't require an external SQL server. I would prefer this option and already used it in a previous project.</p><p>Hope I helped,<br>TheFreeElectron</p>
<p>I'm thinking of using the pigpio library, and I realized that can read the individual states from the pins, so I won't actually need to store it!</p><p>Thanks,</p><p>Ankur</p>
<p>First I want to say, Thanks for this awesome project. I have been struggling to web control my relay board and thanks to you it works!</p><p>but I have a small problem:</p><p>If i view the site it doesn't show the button pictures, and html says: &quot;GET <a href="" rel="nofollow"> </a> 403 (Forbidden)&quot;.<br>The site works, but with the pictures it would look way more awesome.</p><p>Can you help me?</p><p>Thanks in advance!</p>
Hi!<br><br>It seems to be an &quot;access rights&quot; issue. Are you sure you allowed apache to access the &quot;var/www&quot; directory AND its subdirectories? There is a recursive flag for the command. Also, you can easily check who's owning a file/folder by typing &quot;ls -l&quot; in the terminal.<br><br>Hope I helped,<br>TheFreeEletron
<p>Hi,</p><p>Thanks for your help, I got it working!!<br>It controls my relay board really fast!<br>This is what i was looking for.</p><p>Thanks,</p><p>Robertv33</p>
<p>Nice!</p><p>Enjoy your project, have fun and a happy christmas! </p>
<p>Hi, Great project.</p><p>I have some problems.</p><p>1st index.php you wriwriting then should be in /var/www/ in my RPi he is in /var/ww/html and when i past index.php to this place all is ok, i see &quot;it working&quot;</p><p>2nd i have different signals on GPIO, you have 1=on 0=off, in my RPI is 1=off 0=on</p><p>3rd when i do everything and look on my webbroser i see al buttons but when i puy then i see information &quot;something went wrong&quot;<br>This is my 1st project on RPI, I do not know the php js.</p><p>Can you help me ? </p><p>What can I do to project began to work properly?</p><p>thank you and sorry for my English.</p>
Hi,<br>Thank you for your interest.<br>1st. The whole project indeed have to be in &quot;var/www&quot; since every time you type your Rpi's address, Apache will search for index.php in that directory. In your case, it's still the default html page which is in &quot;var/www&quot;. This is the one printing &quot;It works!&quot;. This may be the cause of all your troubles.<br>2nd and 3rd, use the chrome's developer's tool to monitor the request and response. This very often allows to understand what's happening.<br><br>Hope I helped,<br>TheFreeElectron

About This Instructable