You are on page 1of 5

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.

Related
See More (/tag/type-id/?q=)
(http://cdn.instructables.com/F33/DPF8/H7UR92QD/F33DPF8H7UR92QD.LARGE.jpg)
About This Instructable
Li cense:
38,334 views
50 favorites
(/member
/jamesrww/)
j amesrww (/member
/jamesrww/)
Follow 6
Arduino (/tag/type-id/category-technology/keyword-
arduino/)
Tags:
How to use Arduino Mega
2560 as Arduino isp
(/i d/How-to-use-Arduino-
Mega-2560-as-Arduino-i sp/)
Control Arduino Board
Wirelessly With i Phone,
iPad or iPod Using
iArduino App and Ether
(/i d/Control-Arduino-Board-
Read analog data directly
in Processing (/id/Read-
analog-data-directly-
in-Processing/)
How To Program An At
Tiny (/i d/How-To-Program-
An-At-Tiny/)
by appleman123987 (/member
How to connect Ardui no to
a PC through the serial
port (/id/How-to-connect-
Arduino-to-a-PC-through-
the-serial-/)
Arduino WebServer controlled LED by jamesrww (/member/jamesrww/)
Collection I Made it!
Download (/id/Arduino-WebServer-controlled-LED/?download=pdf) 3 Steps
Favorite Share
(/id/Arduino-WebServer-controlled-LED/)
(/)
(/)
Explore (/tag/type-id/) Create (/about/submit.jsp) Contests (/contest/) Community (/community/) Login (/account/login) | Sign Up (/account/gopro?sourcea=header)
Arduino WebServer controlled LED http://www.instructables.com/id/Arduino-WebServer-controlled-LED/
1 of 5 9/20/2014 10:18 PM
Print to PDF without this message by purchasing novaPDF (http://www.novapdf.com/)
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()
{
Serial.begin(9600);
pinMode(8, OUTPUT);
Ethernet.begin(mac, ip);
server.begin();
}
Step 2: Create HTML Form
(http://cdn.instructables.com/F7S/7P8A/H7UR92QU/F7S7P8AH7UR92QU.LARGE.jpg)
(http://cdn.instructables.com/FU9/QNRQ/H7UR92QN/FU9QNRQH7UR92QN.LARGE.jpg)
Arduino WebServer controlled LED http://www.instructables.com/id/Arduino-WebServer-controlled-LED/
2 of 5 9/20/2014 10:18 PM
Print to PDF without this message by purchasing novaPDF (http://www.novapdf.com/)
Make Comment
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>);
}else{
client.print( LED is <font color=red>OFF</font>);
}
client.println(<br />);
client.print(<FORM action=\http://192.168.1.177/\ >);
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>);
break;
}
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;
buffer=";
}else if (c ==\r) {
if(buffer.indexOf(GET /?status=1)>=0)
digitalWrite(8,HIGH);
if(buffer.indexOf(GET /?status=0)>=0)
digitalWrite(8,LOW);
}
else {
For more information head to www.arduinoprojectshq.com
(http://arduinoprojectshq.com)
Arduino WebServer controlled LED http://www.instructables.com/id/Arduino-WebServer-controlled-LED/
3 of 5 9/20/2014 10:18 PM
Print to PDF without this message by purchasing novaPDF (http://www.novapdf.com/)
(/member
/arniep/)
8 months ago
Reply (CGCP4LIHQNC4E21)
(/member
/hyeppy/)
11 months ago Reply (C9KLSTNHMMFAU4S)
(/member
/tekin44/)
1 year ago Reply (CT86AGRHLPS69KV)
(/member
/amandaghassaei/)
1 year ago Reply (CNRK1ZGH82UEJ QN)
(/member
/jamesrww/)
1 year ago Reply (CSKD0MLH82UHML8)
(/member
/waymond91/)
1 year ago Reply (CS3HLISH82U7KE8)
arniep (/member/arniep/)
Wonder if you have made any progress on web controlled relays?
Thanks!
hyeppy (/member/hyeppy/)
i think buffer =" "; >>clear string in buffer
tekin44 (/member/tekin44/)
i have problem this line , buffer ="" ;
amandaghassaei (/member/amandaghassaei/)
very cool, do you plan on expanding this
platform?
jamesrww (/member/jamesrww/) (author) amandaghassaei
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.
waymond91 (/member/waymond91/)
Nicely done. How hard would be to use the buttons to trigger other functions
on the arduino?
About Us
Who We Are (/about/)
Advertise (/advertise/)
Contact (/about/contact.jsp)
J obs (/community/Positions-available-at-Instructables/)
Help (/id/how-to-write-a-great-instructable/)
Find Us
Facebook (http://www.facebook.com/instructables)
Youtube (http://www.youtube.com/user/instructablestv)
Twitter (http://www.twitter.com/instructables)
Pinterest (http://www.pinterest.com/instructables)
Google+(https://plus.google.com/+instructables)
Tumblr (http://instructables.tumblr.com)
Terms of Service (http://usa.autodesk.com/adsk/servlet/item?siteID=123112&id=21959721) |
Privacy Statement (http://usa.autodesk.com/adsk/servlet/item?siteID=123112&id=21292079) |
J oin! English
Arduino WebServer controlled LED http://www.instructables.com/id/Arduino-WebServer-controlled-LED/
4 of 5 9/20/2014 10:18 PM
Print to PDF without this message by purchasing novaPDF (http://www.novapdf.com/)
Resources
For Teachers (/teachers/)
Artists in Residence (/group/air/)
Gift Pro Account (/account/give?sourcea=footer)
Forums (/community/)
Answers (/tag/type-question/?sort=RECENT)
Sitemap (/sitemap/)
Go Pro Today (/account/gopro?sourcea=footer)
We're Hiring! (/community/Positions-available-at-Instructables/)
Mobile
Download our new apps for iOS,
Android and Windows 8!
Android (https://play.google.com/store
/apps/details?id=com.adsk.instructables)
iOS (https://itunes.apple.com
/app/instructables/id586765571)
Windows
(http://apps.microsoft.com
/windows/en-us/app/7afc8194-
c771-441a-
9590-54250d6a8300)
Legal Notices & Trademarks (http://usa.autodesk.com/legal-notices-trademarks/) | Mobile Site (http://m.instructables.com)
(http://usa.autodesk.com/adsk/servlet/pc/index?id=20781545&siteID=123112)
2014 Autodesk, Inc.
Arduino WebServer controlled LED http://www.instructables.com/id/Arduino-WebServer-controlled-LED/
5 of 5 9/20/2014 10:18 PM
Print to PDF without this message by purchasing novaPDF (http://www.novapdf.com/)

You might also like