Nuffnang Ads

Wednesday, 10 September 2014

Raspberry Pi GPIO - LED on/off (wiring Pi + php)

This entry is the third entry for the GPIO on Raspberry pi. Assuming readers already installed the wiringPi, just follow the below step to make LED can be controllable using web GUI.

1) Type the following command to install the necessary packages at the Raspberry pi. Make sure your Raspberry pi has internet connection.

sudo apt-get update
sudo apt-get install apache2 php5 libapache2-mod-php5

2) Now, from your computer,, open the web browser and type the IP address of your Raspberry pi. You will get the "It works!" page. This means the apache and php successfully installed in your Raspberry pi.

3)Now cd to /var/www and edit the index.html to index.php.

4) Edit the index.php as the following to create two simple button (on,off) that will link to execution of the gpio commands. The command "system("")" is used to execute the linux command

    if (isset($_POST['button']))
         system("gpio mode 0 out");
        system("gpio write 7 1");
    else if (isset($_POST['btn']))
        system("gpio write 7 0");
    <form method="post">
        <button name="button">On</button>
        <button name="btn">Off</button>

5) Save index.php and exit. Open the web browser any machine that connected to the same router and enter the Raspberry Pi's IP address. You will get the page similar to this:-

Click "On"/"Off: to turn on/off the LED

LED on

LED off

6) Done



  1. Hi.. i like your article.
    what if i want using two leds ?

  2. Hi Indra, thanks, you can put more LED depends on the number of GPIO pins supporter by raspberry pi. You can put another LED at another GPIO pin see (
    for GPIO pins. After that, create another sets of on/off button at PHP, link it with "gpio write 0/1"

  3. hi,,, i try your article,,
    in puty console with script ""gpio mode 0 out" and "gpio write 7 1" Or "gpio write 7 0" LED can on/off..
    but i have problem, when i try in php script like your code but LED didn't work on/off, help me sir

  4. Thanks it worked for me.But we need to change the out put pin from 0 to we are sending signal to pin number 7.

  5. Hi...,
    Thanks for this article.i tried this using two LEDs.i created two more on/off buttons and linked the gpio pin 11 to gpio write 0/1.But the LED which i newly connected did not work on/off.Please help me sir if any changes are required.

  6. شركة تسليك مجارى بالرياض افضل شركة تسليك مجارى فالشركة تعتمد على افضل الخدمات المميزة التى تساعد فى الوصول الى افضل النتائج المميزه التى تساعد فى اعمال التسليك من خلال افضل الطرق المميزة التى تساعد فى القيام باعمال التسليك والحصول على افضل النتائج المميزة فمن اهم ما تقوم بيه شركة تسليك مجاري بالرياض السعى الى الانتهاء التام من اعمال التسليك المتكررة والانتهاء ايضا من اى شى غير مالوف وجوده فى المجارى فاذا اراد ان تقوم بكل ذلك فتاكد انك لم تجد افضل من شركة تسليك المجاري
    تعتمد شركة بسمة الرياض افضل شركة تسليك المجارى بالرياض على افضل الكودار البشرية المميزة المتواجده فى الاسواق والتى فى حاله تدريب ميتمر من قبل شركتنا لكى يتم التاكد ان العماله على وعى كبير بكيفيه القيام بالتسليك واختيار الانسب لنوع المجارى المتواجده حتى لا يتم عودتها مرة اخرى فاذا اراد ان تتخلص من اى شىء غير مالوف فعليك ان تتعاقد وتتعاون معنا الان فى القيام بكل ذلك فى اقل وقت ممكن وتخلص من مشاكل التسليك المتكررة .

  7. Now cd to /var/www and edit the index.html to index.php

    how to edit the file from index.html to index.php
    i tried doing it but the access permissions cannot be changed.

  8. Nice info about Php it’s reallyhelpful…. If it possible share some more tutorials……….

  9. Just a note. I had to add a -g option to the GPIO mode and GPIO write to get the LED to turn on and off.
    Great tutorial-Thanks so much

  10. Great blog created by you. I read your blog, its best and useful information. You have done a great work. Super blogging and keep it up.php jobs in hyderabad.

  11. Australia Best Tutor is one of the best Online Assignment Help providers at an affordable price. Here All Learners or Students are getting best quality assignment help with reference and styles formatting.

    Visit us for more Information

    Australia Best Tutor
    Sydney, NSW, Australia
    Call @ +61-730-407-305
    Live Chat @

    Our Services

    Online assignment help Australia
    my assignment help Australia
    assignment help
    help with assignment
    Online instant assignment help
    Online Assignment help Services

  12. Each department of CAD have specific programmes which, while completed could provide you with a recognisable qualification that could assist you get a job in anything design enterprise which you would really like.

    AutoCAD training in Noida

    AutoCAD training institute in Noida

    Best AutoCAD training institute in Noida

  13. 6-week summer course in Noida - 6 weeks The summer course plays a crucial role in shaping the career of young aspiring / informatics students. This training has been specifically introduced so that students can become familiar with current industrial culture and industrial needs. Webtrackker technology offers a 6-month training program for students / graduates that includes small and large projects.
    6-week summer course in Noida

  14. Cloud Computing Training In Noida
    Webtrackker is IT based company in many countries. Webtrackker will provide you a real time projects based training on Cloud Computing. If you are looking for the Cloud computing training in Noida then you can join the webtrackker technology.
    Cloud Computing Training In Noida , Cloud Computing Training center In Noida , Cloud Computing Training institute In Noida ,

    Company Address:
    Webtrackker Technology
    C- 67, Sector- 63, Noida

  15. what will happen to the gpio status if I close the browser , it will reset or unchange

  16. Video editing course in Noida
    Video editing training institute in Noida- Webtrackker Technology is and IT Training institute providing the Video editing course in Noida, FCP, Final Cut Pro Training in Noida. For more call us- 8802820025.
    Video editing course in Noida
    best video editing course in Noida
    best video editing institute in Noida
    Company Address:
    Webtrackker Technology
    C- 67, Sector- 63, Noida
    Phone: 01204330760, 8802820025

  17. This is a 2 good post. This post gives truly quality information.

    RPA Training in Hyderabad

  18. It's very nice blog. I'm so happy to gain some knowledge from here.

    MSBI Training in Hyderabad


  19. Like different elements of India, numerous oil and spices usually cross into making food. This effects in substances getting caught to the partitions of the filter out.
    Visit here
    Best kitchen chimney installation and service
    Auto clean chimney sevice in Faridabad

  20. Thank You so much for writing this blog. This is probably the best one by far. Easy to understand and educate myself on scala and how the best way to go about it.

    Tekslate Online Trainings.

  21. This is very informative and interesting for those who are interested in blogging field.