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.
Remove these adsRemove these ads by Signing Up

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 www.arduinoprojectshq.com 
waymond912 years ago
Nicely done. How hard would be to use the buttons to trigger other functions on the arduino?
RhemyR waymond916 months ago

what the buffer thingy do?

arniep1 year ago

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


hyeppy1 year ago
i think buffer = " "; >> clear string in buffer
tekin441 year ago
i have problem this line , buffer = "" ;
very cool, do you plan on expanding this platform?
jamesrww (author)  amandaghassaei2 years ago
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.