Switching LEDs on from a Web Page using Arduino

The Arduino and Ethernet shield are set up as a web server. The web page that the server hosts allows two LEDs to be controlled by clicking checkboxes on the web page.

This video shows the Arduino and web page in action:

The LEDs are interfaced to pin 2 and pin 3 of the Arduino.

This is an answer to a question from the Arduino web server blog entry relating to the article on Arduino Web Server LED Control. The question is on how to control two LEDs from a web page.

The Arduino sketch for this solution:
This code is a hack from some previous code that I wrote and so does not look exactly like the code from the sketch that the question is related to.

27 thoughts on “Switching LEDs on from a Web Page using Arduino

  1. Pingback: Arduino Web Server Tutorial | Starting Electronics Blog

  2. Hi.

    I’m trying to work with my Arduino UNO in Linux (Xubuntu) but I don’t know how do it. How can I work with my Arduino UNO in Xubuntu?


  3. Boa noite.

    Parabéns pelo tutorial.
    Gostaria se possível um tutorial igual a este porém que a página fique hospedada no cartão SD.

  4. Hello. Yor codes are incredibile. That is what I ever need with Arduino. First one LED control with mobile, now two. I was singing yesterday all day long. But I have a little problem. I use 2560 board with 50 digital I/O. This code for 2 LED can work with pins from 2 to 9 and I need pin 30 and up. The checkboxes of this pin can not be checked. Have you got solution for me.

    Best regards and thank you for my dreams come true.

    SANEL, Bosnia and Herzegovinia

  5. Pingback: Arduino Web Server Tutorial | WnGeek

  6. This script didn’t work. I get a server timeout. I turned on the serial port to print diagnostics and the setup() doesn’t print anything. I then instrumented the for/next for the LED loop and it appears that somewhere in the LED for/next something happens that causes the Setup() to run again, which gets through and enters loop(). But the ethernet connection does not happen and loop() just keeps running and does nothing. I’ll keep looking to see what might be wrong.


  7. Awesome! Now I can do this, but sadly, I can’t access this web page from another computer via internet. I tried using port forwarding, but my ISP does not provide a static IP, which makes it impossible to access remotely. any ideas on this?

  8. Thanks for this code. I’m totally green to c++, setting up Web pages etc. But find this very rewarding once I get the stuff to work.
    I would like to use this same code in order to switch 8 led’s
    Can you help?

  9. Hi, I am using eth_websrv_LED2.ino sketch with UNO and ENC28J60 module and UIPEthernet library. Everything works fine for few clicks, after that webpage won’t response and also I can ping the IP of the ENC28J60 module. I have to reset arduino to gain the access to the IP. Any idea whats the problem is? Thanks in Advance

  10. Pingback: Extending LED Output Range on Arduino MEGA 2560 Web Server | Starting Electronics Blog

  11. hye..with the sketch given,if i run to my arduino, do i need to store the html file like index.htm into my sdcard too?

    • Hi
      No, you do not need an SD card or index.htm file with this sketch. The HTML is embedded in the Arduino sketch.

  12. Thanks for the sketch. It works perfectly.
    It would also be useful to have a basic authentication to prevent public control of your arduino (when you set port fwd on your router).
    Can you please add the code for authentication (arduino uno)?

  13. Is there anyway you con provide this tutorial using the ESP8266 12E module?
    Ethernet is a thing of the past IMO and I never use it.


      • Thank You! I’ve been looking for a SIMPLE tutorial on using the ESP8266 12E module to turn on an LED from webpage using AJAX technology without any luck. Most are all over complicated and simply do not work.
        I plan on using the above as a starting point and trying to eliminate the Ethernet stuff and use the ESP8266.

        Thanks for your reply and I look forward for your tutorial.


  14. Pingback: im(a); Diana Xu & Jingyi Sun Week 10: Arduino server |

Leave a Reply

Your email address will not be published. Required fields are marked *