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

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


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

References
[1] http://www.instructables.com/id/Simple-and-intuitive-web-interface-for-your-Raspbe/#step1

62 comments:

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

    ReplyDelete
  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 (http://kurup87.blogspot.com/2014/09/raspberry-pi-gpio-simple-led-example.html)
    for GPIO pins. After that, create another sets of on/off button at PHP, link it with "gpio write 0/1"

    ReplyDelete
  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

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

    ReplyDelete
  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.

    ReplyDelete
  6. 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.

    ReplyDelete
  7. 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

    ReplyDelete
  8. 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
    Email: info@webtrackker.com
    Website: www.webtrackker.com
    http://webtrackker.com/Cloud-Computing-Training-Institutes-In-Noida.php

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

    ReplyDelete
  10. 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
    Email: info@webtrackker.com
    Website: http://webtrackker.com/Best-training-institute-Video-editing-FCP-course-in-Noida.php

    ReplyDelete
  11. This is a 2 good post. This post gives truly quality information.



    RPA Training in Hyderabad

    ReplyDelete

  12. 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
    http://kitchenware.ml
    Best kitchen chimney installation and service
    Auto clean chimney sevice in Faridabad

    ReplyDelete
  13. 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.

    ReplyDelete
  14. This is very informative and interesting for those who are interested in blogging field.
    www.bisptrainings.com

    ReplyDelete
  15. thank you for the information shared about php training course...

    ReplyDelete
  16. for more updates visit RnWmultimedia for this topic

    ReplyDelete
  17. thanks for given information about code. more information about code visit:
    https://www.surat-training-course.com/php-training-course-surat

    ReplyDelete
  18. Thank you... Nice article....

    ReplyDelete
  19. Brilliant - nice, efficient and easy. Thank you.

    ReplyDelete
  20. Excellent post. I was always checking this blog, and I’m impressed! Extremely useful info specially the last part, I care for such information a lot. I was exploring this particular info for a long time. Thanks to this blog my exploration has ended.
    If you want Digital Marketing Serives :-
    Digital marketing Service in Delhi
    SMM Services
    PPC Services in Delhi
    Website Design & Development Packages
    SEO Services PackagesLocal SEO services
    E-mail marketing services
    YouTube plans

    ReplyDelete
  21. Thank you for sharing this useful article with us. This blog is a very helpful to me in future. Keep sharing informative articles with us.

    https://www.ahmedabadcomputereducation.com/course/php-training-course/

    ReplyDelete
  22. Nice Blog !
    Our team at QuickBooks Customer Support Number 1-855-974-6537 is working continuously to help you assuage your QuickBooks problems in less time amid the COVID 19 pandemic.

    ReplyDelete
  23. Thank you for sharing this useful article. This blog is a very helpful to me. Keep sharing informative articles with us.

    https://www.ahmedabadcomputereducation.com/course/ionic-training-course/

    ReplyDelete
  24. Great sources for knowledge. Thank you for sharing this helpful article. It is very useful for me.

    https://www.ahmedabadcomputereducation.com/course/laravel-training-course/

    ReplyDelete
  25. Wow it is really wonderful and awesome thus it is very much useful for me to understand many concepts and helped me a lot. it is really explainable very well and i got more information from your blog.

    python Training in chennai

    python Course in chennai


    ReplyDelete
  26. Nice Blog !
    QuickBooks accounting software is no strange from annoying errors or bugs. Among all these errors, QuickBooks Error 8007 is very common. In case you have also encountered this error,Our experts are available 24/7 around the clock for you.

    ReplyDelete
  27. learn Youtube money making things https://www.digitalbrolly.com/youtube-course-training-in-hyderabad/

    ReplyDelete
  28. The content is very nice and has sets of the fantastic piece of information. Thanks for sharing with us. If you face QuickBooks 6189 error, visit:

    Quickbooks error 6189

    ReplyDelete
  29. Thank You for sharing this informative article.

    https://web30india.com/

    ReplyDelete
  30. Excellent Article. Thank you for sharing!

    https://www.ahmedabadcomputereducation.com/
    https://www.ahmedabadcomputereducation.com/course/live-project-training-in-asp-net/
    https://www.ahmedabadcomputereducation.com/course/live-project-training-in-ios/
    https://www.ahmedabadcomputereducation.com/course/live-project-training-in-java/
    https://www.ahmedabadcomputereducation.com/course/live-project-training-in-android/
    https://www.ahmedabadcomputereducation.com/course/live-project-training-in-php/
    https://www.ahmedabadcomputereducation.com/course/live-project-training-in-python/

    ReplyDelete
  31. YTD star break program is anything however extreme to utilize effectively build up the URL for the video you request to download and tap the Download get YTD Crack Download

    ReplyDelete
  32. Adobe Animate CC 22.0.8.217 Crack 2022 unveiled the new Release that the business states is the product launch that is biggest since they.Adobe Animate 2022 System Requirements

    ReplyDelete
  33. "Looking to kickstart your career in SAP EWM? Bangalore offers a plethora of options for SAP EWM training.
    Here’s what to consider:
    SAP EWM Training in Bangalore at SAP Masters
    1.Quality Training:
    Opt for best institutes with a solid reputation and accreditation from SAP Masters Training institute.
    Look for expert faculty who can provide comprehensive insights.
    2.Curriculum:Ensure the curriculum covers core EWM concepts and offers hands-on projects for practical learning.
    3.Infrastructure: Check for modern facilities and labs equipped with the latest software to support your training needs.
    4.Placement Support: Choose institutes that offer robust placement assistance, including resume building and interview preparation.
    Consider institutes like SAP Masters Institute of Technology, sap masters Academy, and sapmasters training institute bangalore,
    known for their quality training and successful placements. Choose wisely, and jumpstart your SAP EWM journey in Bangalore!



    Visit SAP Masters - Best SAP Training in Bangalore"
    Visit SAP Masters - SAP EWM Training in Bangalore"

    ReplyDelete
  34. This comment has been removed by the author.

    ReplyDelete
  35. https://kurup87.blogspot.com/2014/09/raspberry-pi-gpio-led-onoff-wiring-pi.html?sc=1720694143571#c1199515776724696158

    ReplyDelete