Arduino WebServer Controlled LED





Introduction: Arduino WebServer Controlled LED

I wanted to investigate controlling the digital outputs on a Arduino from a webpage so I decided to build a simple setup to Turn a LED on and off from a webpage. For this project I used the Arduino Uno R3 and Arduino Ethernet Shield.

Step 1: Configure Web Server

First off we need to configure the web server  this is done by calling the Ethernet libraries, setting the Mac Address, IP Address and Server Port. then in the Void Setup you start the server and define the pin you want to plug the LED into.

#include <SPI.h>
#include <Ethernet.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1, 177);

EthernetServer server(80);

void setup()
pinMode(8, OUTPUT);
Ethernet.begin(mac, ip);

Step 2: Create HTML Form

In the Void Loop we define client then check that the web server is connected and available the get it to display some HTML. The first lot checks the status of pin 8 and prints HTML to tell us if the LED is currently turned on or off. Then we use a HTML form to make some radio buttons and a submit button to select the status on or off.

if (digitalRead(8)){
client.print(” LED is <font color=’green’>ON</font>”);
client.print(” LED is <font color=’red’>OFF</font>”);
client.println(“<br />”);

client.print(“<FORM action=\”\” >”);
client.print(“<P> <INPUT type=\”radio\” name=\”status\” value=\”1\”>ON”);
client.print(“<P> <INPUT type=\”radio\” name=\”status\” value=\”0\”>OFF”);
client.print(“<P> <INPUT type=\”submit\” value=\”Submit\”> </FORM>”);


Step 3: Read LED Status and Turn on or Off

Now all that is left is to read the input from the HTML Form and turn the led on or off. When you select one of the radio buttons and click submit the form adds a status=1 or status=0 to the end of the URL. We can now use the GET function to read the value and run through am IF statement to set the digital write on pin 8 to either High or Low (On or Off).

if (c == ‘\n’) {

currentLineIsBlank = true;
} else if (c == ‘\r’) {
if(buffer.indexOf(“GET /?status=1″)>=0)

if(buffer.indexOf(“GET /?status=0″)>=0)
else {

For more information head to 



    • Clocks Contest

      Clocks Contest
    • Woodworking Contest

      Woodworking Contest
    • Oil Contest

      Oil Contest

    We have a be nice policy.
    Please be positive and constructive.




    are u able to do the same thing if you are not using the local wifi?

    i am getting an error about stray '\342' in program.

    if(buffer.indexOf(“GET /?status=0″)>=0)

    Can anyone explain why?

    1 reply

    you need to change the quotation marks to type out yourself those quotation marks instead of just copy and paste.

    so change those " in

    'if(buffer.indexOf(“GET /?status=0″)>=0)'

    to you type yourself ".

    i am getting an error about a stray "/" in this line..

    if(buffer.indexOf(“GET /?status=0″)>=0)

    Can anyone explain why?

    1 reply

    try to rewrite the quotation marks if you have copy pasted the code.

    Nicely done. How hard would be to use the buttons to trigger other functions on the arduino?

    1 reply

    what the buffer thingy do?

    Wonder if you have made any progress on web controlled relays?


    i think buffer = " "; >> clear string in buffer

    i have problem this line , buffer = "" ;

    Hi there,

    I sure do, Next I will be setting up a web form to control relays. I will post it once i am finished.