Introduction: Arduino WebServer Controlled LED

Picture of 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

Picture of 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

Picture of 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 


YongB1 (author)2017-03-09

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

LukášB21 (author)2016-05-04

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

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

Can anyone explain why?

jclmdt (author)LukášB212017-03-06

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

makeosaurus (author)2015-09-19

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

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

Can anyone explain why?

erike7 (author)makeosaurus2015-09-19

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

waymond91 (author)2012-10-09

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

RhemyR (author)waymond912015-01-26

what the buffer thingy do?

arniep (author)2014-01-20

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


hyeppy (author)2013-10-13

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

tekin44 (author)2013-09-18

i have problem this line , buffer = "" ;

amandaghassaei (author)2012-10-10

very cool, do you plan on expanding this platform?

jamesrww (author)amandaghassaei2012-10-10

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.

About This Instructable




More by jamesrww:Arduino WebServer controlled LED
Add instructable to: