loading

Step 4: Server

You can use the Arduino Ethernet shield as a web server to load an HTML page or function as a chat server. You can also parse requests sent by a client, such as a web browser. The following two examples show how to use it to serve HTML pages, and parse URL strings.

One important thing to keep in mind is that you will have to enter your Arduino's IP address in both of the examples below in order for them to work.

The following code changes the web page served based on a button press:
To make this example code work, simply attach a button between pin D2 and 5V,  a 10K resistor between pin D2 and ground, and then load the IP address of your Arduino into your web browser. The page should load with a black background. Press and hold the button, and then refresh the browser page. The site should now load with a white background.


The following code lights up an LED depending on the URL that is sent to the Arduino:

To make this work connect the positive lead an LED to pin D2, and the negative lead in series with a 220 ohm resistor to ground.

To turn on the LED enter this into your browser:
http://[YOUR IP ADDRESS HERE]/$1

To turn off the LED enter this into your browser:
http://[YOUR IP ADDRESS HERE]/$2

Note: You should obviously replace [YOUR IP ADDRESS HERE] with your IP address.
<p>Hi, am able to ping the Ethernet shield but cant get anything in browser.</p><p>What's the use of the EthernetServer Server(80)</p>
<p>i made an internet controlled rover using the arduino ethernet shield following <a href="http://www.instructables.com/id/Internet-Controlled-RC-Car/" rel="nofollow">http://www.instructables.com/id/Internet-Controlle...</a> this instructables...but it only works for my internet connection...i cant operate it from other internet connections with the same ip address...if anyone could help :(</p>
<p>Thanks Randofo</p><p>The Step 5. (Twitter Reader) section does not work. Please confirm this <a href="http://www.instructables.com/member/randofo/">http://www.instructables.com/member/randofo/</a></p><p>... I presume it would need a Twitter API</p>
<p>the twitter api updated and now you need authentication, which i have no idea how you get authentication...</p>
<p>Hey, I have been using HanRun HR911105A and when I connect it to my Laptop through ethernet cable it doesn't detect the connection and there is no blinking of LED's on the ethernet shield as well as on the Laptop.</p><p>Thanks in advance hopefully someone can help!!</p>
<p>Just a thought, when you normally plug your Arduino board into your computer the usb cable supplies the power. Most ethernet does not support power over internet (POI), so unless you are also connecting to your PC using usb at the same time you will need to supply external power to your board.</p><p>If you already provided external power ignore this comment. </p>
<p> Arduino with AJAX</p><p>https://www.youtube.com/playlist?list=PLbUAcqHuByzfm9od5kHKArjKIAtfbT0LD</p>
<p>to copy the code from the text area, simply (tested on chrome) rightClick the textArea and click inspect element, than expand the textArea element and there you have it</p>
<p>I am unable to copy the sample code that you provided. Is it available somewhere that it copied? Thanks.</p>
<p>Yes, that's annoying -- wish the author would change that. I downloaded the PDF, cut and pasted the text into the arduino editor. I think you might have to have a pro instructables membership to download the PDF.</p>
Does anyone know how to connect the radio module NRF24L01
<p>Can we use wifi insted of CAT5 cables for wireless communication?</p>
<p>looks like photo is not correct. Looks like the black wire of switch is connected to ground, not 5V. Hooked up to 5V instead and it seems to be working. Get DARK/LIGHT on website [firefox]</p>
<p>can you use this shield connected to your computers ethranet port</p>
<p>I get this message : <br>Failed to configure Ethernet using DHCP <br>any idea how to fix this thx ?</p><p>ipconfig /all gives me the physical address that i put in mac[]. <br>it also says dhcp enabled : no <br>even if code is for DHCPaddressPrinter.</p><p>in case of ethernet server code : <br>i cant open my ip address in web browser. <br>when i ping it says &quot;destination host unreachable&quot;.</p>
<p>please help me, serial monitor can't be open....<br>it says &quot;Board at COM49 is not available&quot;</p>
<p>thanks for sharing nice idea</p>
<p>I get this message :<br>Failed to configure Ethernet using DHCP<br>any idea how to fix this thx ?</p>
<p>Hi, thanks for the wonderful walk-through! However, the twitter client doesn't seems to work.. Any idea?</p>
<p>Thanks ! it worked for me. Just a little reminder : to get the info on your monitor, don't forget to set it to the same baud rate as the one set by the program (ie DhcpAddressePrinter) for the serial connection (check the number XXX in Serial.begin(XXX)). To change the baud rate, you can use the &quot;check list button&quot; at bottom right of the monitor</p>
<p>Thanks for the tutorial, but i have a question to the server work example.<br>If i would like to use other strings other than &quot;$1&quot; and &quot;$2&quot;, like &quot;$ledon&quot; for switching on the led connected, what adjustment need to do to the codes.<br>I find it difficult to solve this problem. </p>
<p>Didn't work with 1.0, but first time with 1.6.1</p>
<p>Let me first start by saying that I am a complete noob when it comes to anything Arduino. My kit hasn't even arrived in the mail yet so please go easy on me. :) </p><p>However, I have a question regarding this project. Specifically the RJ45 Ethernet Shield. In your example you are using the RJ45 to interact with the Arduino via a website/internet, is it possible to use the Arduino + Shield to interact with a series of rocker switches via a 8 channel relay board? If so, I was thinking that it would make the installation of my project really clean being able to use the RJ45 cable between my Arduino and the switches that will be located perhaps 10-15 feet away. <br><br>Any and all help is appreciated.</p>
<p>This Tutorial is Fantastic and very very very very clear everything.Got this tutorial after 4 days searching on my related topic.</p><p>Many Many Thanks Dear. </p>
<p>Excuse me, does anyone know how to access the ethernet shield from the outside of the local network - that is from the internet? I guess the local dynamic IP has to be changed, right..? Where to get that IP?</p>
<blockquote>how to access the ethernet shield from the outside of the local network - that is from the internet?<br></blockquote><p>You need to port forward the IP and port you are using of the ethernet shield to the internet</p><p>This website may help: <a href="http://portforward.com/" rel="nofollow">http://portforward.com/</a></p><blockquote>I guess the local dynamic IP has to be changed, right..?</blockquote><p>Yes if you are port forwarding the ethernet shield should have a static local IP. You can define the ethernet shield IP in the code. </p><p><a href="http://arduino.cc/en/Reference/EthernetIPAddress" rel="nofollow">http://arduino.cc/en/Reference/EthernetIPAddress</a></p><p>you can find your DNS servers, gateway, and subnet by typing <em>ipconfig /all </em>in a windows command line.</p><p>Make the ip of the ethernet shield any ip not currently used on you network. An easy way do do this is to take IP address listed in <em>ipconfig /all </em>and change the numbers after the last dot to<em> 254 and put that in the arduino code as its IP.</em></p><blockquote>Where to get that IP?</blockquote><p>If you mean your public IP you can find that by visiting </p><p><a href="http://www.whatismyip.com/" rel="nofollow">http://www.whatismyip.com/</a></p>
Nice thank u
<p>thanks for your information,</p><p>secretfood.net</p>
<p>It's useful thank</p>
<p>Nice Tutorial!!</p><p>I'm a engineer in WIZnet providing W5100 to the official Arduino Ethernet Shield.</p><p>WIZnet made W5500 and WIZ550io/ioShield-A. If you are interested in W5500 and make a tutorial of W5500, I will give a WIZ550io to you free. If you want, feel freely to contact me. </p><p>Thank you.</p>
my ethernet shields ic gets hot will u plsplspls help me for that <br>am using arduino leonardo board <br>pls help me <br> <br>regards <br>pyt
I have one of the Non-POE (power Over Ethernet) 5100's, and it does the same to me.. I think it's the 3.3V regulator trying to run the single chip, which is chewing-up massive wattage.. (even if it is being powered from the +5V regulator from the Arduino.) I've often wondered, if I could repower this off the 3.3V off an external power supply, but someone said that's a bad idea, as the back-feed could burn-out the regulator, and other chips switching between the 9 down to 5, and 5 down to 3.3, or even the USB to serial chip. <br>
<p>You need to supply the arduino and the shield with 7 or 7.5 v, you can use a dc-dc power regulator. I use a 12v power suply and a dc to dc regulator, who give me 7.5v and everything is fine. </p>
Did you do anything to change it, and/or did you plug it in correctly? It sounds like you are shorting something.
<p>Wow! a whole year later? No, It's something about the 3.3 regulator, that is handling a lot of amperage from the 5100.. I thought I saw somewhere on another instructable, someone solved the problem (slightly) by DOUBLING the regulator. (stacking another one on top of the original, so you had 2 in parallel.) http://www.instructables.com/id/Beef-up-your-Arduino-power/</p>
That happens with my wiznet W5100 too. It just happens I think.
<p>Thanks a lot work at the first run.No problem with me here.</p>
'and open the serial monitor. It should print out the IP address in use.' <br> <br>This dosen't work...........WTF
Are you using Arduino 1.0?
<p>i have the same problem, i'm using Arduino 1.0.5 and the serial monitor don't print the IP address</p>
<p>check the baud rate of serial monitor</p><p>samething happened to me, had the baud set to 115200, changed it to 9600, and it works</p>
<p>Use DHCPAddressPrint it should work...</p>
<p>This instructable answered questions I couldn't resolve after hours of work! Thanks for taking the time to do it!</p>
<p>Could you make it send emails? I'm thinking of hooking one up to a 3D printer to email you when it finishes a print.</p>
What if you don't have access to a router? (e.g apartment building, hotel rooms...) Can I use the ethernet port on my win7 computer?

About This Instructable

682,018views

670favorites

License:

Bio: My name is Randy and I founded the Instructables Design Studio. I'm also the author of the books 'Simple Bots,' and '62 Projects to ... More »
More by randofo:Robots Class Bringing it All Around Telepresence Robot: Shields and Modules 
Add instructable to: