Arduino Ethernet Shield Tutorial by randofo
Featured
main1.jpg
The Arduino Ethernet Shield allows you to easily connect your Arduino to the internet. This shield enables your Arduino to send and receive data from anywhere in the world with an internet connection. You can use it to do fun stuff like control robots remotely from a website, or ring a bell every time you get a new twitter message. This shield opens up endless amounts of possibility by allowing you to connect your project to the internet in no-time flat.

Step 1: Setup

1.jpg
Setting it up is as simple as plugging the header pins from the shield into your Arduino.

Note that the Ethernet Shield sold at Radioshack is online compatible with Arduino Uno Rev. 3 boards (or later). It has too many pins to plug into earlier version Arduino boards.

Step 2: Shield Features

2.jpg
The Ethernet Shield is based upon the W51000 chip, which has an internal 16K buffer. It has a connection speed of up to 10/100Mb. This is not the fastest connection around, but is also nothing to turn your nose up at.

It relies on the Arduino Ethernet library, which comes bundled with the development environment.

There is also an on-board micro SD slot which enables you to store a heck-of-a-lot of data, and serve up entire websites using just your Arduino. This requires the use of an external SD library, which does not come bundled with the software. Using the SD card is not covered in this Instructable. However, it is covered in the Step 8 of the Wireless SD card instructable.

The board also has space for the addition of a Power over Ethernet (PoE) module, which allows you to power your Arduino over an Ethernet connection.

For a full technical overview, see the official Ethernet Shield page.

Step 3: Get started

4.jpg
3.jpg
Plug the Arduino into your computer's USB port, and the Ethernet shield into your router (or direct internet connection).

Next, open the Arduino development environment. I highly recommend upgrading to Arduino 1.0 or later (if you have not done so already). This version of the software has built in DHCP support, and does not require manually configuring an IP address.

To figure out what IP address has been assigned to your board, open the DhcpAddressPrinter sketch. This can be found at:

File --> Examples --> Ethernet --> DhcpAddressPrinter

Once open, you may need to change the Mac address. On newer versions of the Ethernet shield, you should see this address on a sticker attached to the board. If you are missing a sticker, simply making up a unique mac address should work. If you are using multiple shields, make sure each has a unique mac address.

Once the mac address is properly configured, upload the sketch to your Arduino, and open the serial monitor. It should print out the IP address in use.

Step 4: Server

5A.jpg
5B.jpg
5C.jpg
5D.jpg
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.

Step 5: Client

6A.jpg
You can also use the Ethernet Shield as a client. In other words, you can use it to read websites like a web browser.

Websites have a lot of text both visible and hidden, which makes programming on the client side very tricky. Reading information from websites typically involves parsing a lot of strings. This is maddening, but worth it, if that is what you intend to do.

I was going to write some code to read Twitter messages, but such a code already exists as an example within the Arduino programmer. Instead, I simply modified it slightly to turn on an LED if a special message is read.

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.

Don't forget to enter your own IP address into the code below, or it will not work.

Here is the code:

Presumably you are going to want to read something other than the recent post on the RandyMcTester Twitter feed.

To read other Twitter feeds, change the following bit of text:
client.println("GET /1/statuses/user_timeline.xml?screen_name=[NEW TWITTER NAME HERE]&count=1 HTTP/1.1");
1-40 of 50Next »
sandeep200870 says: May 20, 2013. 6:25 AM
hi, i have successfully sent commands from a browser to ethernet shield in same network. but, can u please tell me how to do same if i have to do it from a separate network? actually i want to make an android app to operate ethernet shield, so i need it necessarily.
mwezel says: May 16, 2013. 9:45 AM
your ethernet shields is dead you plug something wrong
parth_bhat says: May 3, 2013. 6:51 AM
my ethernet shields ic gets hot will u plsplspls help me for that
am using arduino leonardo board
pls help me

regards
pyt
randofo (author) says: May 3, 2013. 8:00 AM
Did you do anything to change it, and/or did you plug it in correctly? It sounds like you are shorting something.
sshapiro2 says: Apr 17, 2013. 7:51 AM
SOLUTION:

sorry i had the wrong resistors in the circuit, was using those baby blue ones, I find them hard to read. make sure its the right resistor!
sshapiro2 says: Apr 17, 2013. 6:26 AM
Thanks!

Any advice: i have confirmed ip address with addressprinter.

byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0x56, 0xC6 };
IPAddress ip(10,0,0,10); //<<< ENTER YOUR IP ADDRESS HERE!!!

The light goes on when i uplaod the script but wont respond to the ip $1 or $2, the page just sits and doesnt load. i even tried the script below to return a black screen and nothing loads on that ip.

Thanks!
sshapiro2 says: Apr 17, 2013. 6:59 AM
i have a similar problem with the Switch activated code. It loads a white page with the words DARk but nothing happens when the switch is pressed, tried refreshing etc
lazer eyes says: Apr 17, 2013. 12:16 AM
hai I have ethernet w5100 shield v3 and I have UNO and I'm using 1.0 and I tried all latest version of ide but i can't able to configure my ip address it is showing error "failed to configure mac address, I have mac address on the sticker , but it doesn't work
1) i hooked the SHIELD with uno
2) I changed the mac address in chcp address printer
3) program uploaded,
4) rj45 hooked with shield

after that my system showed local area network connected ,

when i click the serial monitor its showing only failed to confogure mac address"

what shall i do
clsorens says: Apr 16, 2013. 12:16 PM
I know it's kinda old-ish post, but just in case anyone else is still having this problem like I was too here's a solution.

It should still turn the light on, but the reason it's not displaying a web page is because the code doesn't return a web page.

change the "
if(c == '\n')
{
currentLineIsBlank = true;
} " to "

if (c == '\n' && currentLineIsBlank)
{
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connnection: close");
client.println();
client.println("");
client.println("");
client.println("");
client.println("");
currentLineIsBlank = true;
break;
}

"

This code will return a web page with the background set to black (#000000) after light turns on.
Zarainia says: Mar 23, 2013. 5:45 PM
Is the "serverName" line supposed to be changed?
Zarainia says: Mar 23, 2013. 5:50 PM
Never mind, it worked. Thanks for the tutorial!
crusso says: Feb 1, 2013. 5:59 PM
Great instructable, Thank you very much!
grandleo75 says: Jan 12, 2013. 7:19 AM
Awesome tutorial. Thanks for posting it.

I seem to have a problem. pin2 seems to default to on. How can I get ti to default to off?

Thanks,
MegaPicklesrock says: Jan 10, 2013. 5:41 PM
Never mind. I went to arduino 1.0.1 and it worked!
MegaPicklesrock says: Jan 10, 2013. 5:36 PM
When I upload my code to my arduino it says "IPAddress does not name a type" Can you guys help. I tried fixing it but it always fails
waterlubber says: Dec 27, 2012. 1:50 PM
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?
purpulhaze says: Dec 27, 2012. 8:05 PM
Port should handle the cross over internally if its a newer computer if it doesn't you will need a cross over cable.
waterlubber says: Dec 28, 2012. 4:41 PM
What is a crossover cable, and do I need one? (If so, why) I have an Atheros AR8132 PCI-E Fast Ethernet Controller and and Atheros AR5B95 Wireless Network Controller.
purpulhaze says: Dec 29, 2012. 11:14 AM
Well communicating from pc to pc via the rj45 port in the past you would need a cross over cable. Alot of ports on newer computers usually handle this internally. You may need to check the specs for your computer. Please read up on cross over cables. Just look up pc to pc networking via rj45 port. Basically pc to pc networking. The arduino and ethernet shield is basically a computer.
waterlubber says: Dec 29, 2012. 3:10 PM
OK, my memory just gave me the memory of hooking up mine with another (it worked) so a Windows 7 computer seems to be compatible. ;P Is it like the serial cables when you have to "cross over" the TX and RX wires? Anyhows, its working. Thanks for the help.
red_green says: Oct 20, 2012. 9:23 PM
I have an Ethernet shield, and I lost the sticker. All the sketches I upload, however, won't compile. First, is there a way to find the MAC address, and second, do you have any idea why the sample code won't compile?
waterlubber says: Dec 28, 2012. 4:43 PM
Can I see the code? Also, try making up a random MAC address. How 'bout AB-CA-BA-12-34-AF?
mcktimo says: Sep 27, 2012. 3:44 PM
Everything worked but when I stressed the server a little by accessing it from multiple browsers (phone, laptop, etc) it would stop responding an need a reset. I wonder why?
waterlubber says: Dec 27, 2012. 1:57 PM
You might have overloaded the buffer.
jstelmack says: Nov 17, 2012. 5:06 AM
Just getting started with Audrino and Ethernet Shield. Your tutorial has helped TREMENDOUSLY! Thanks For your time/efforts!
DNMEBOY says: Oct 24, 2012. 12:52 PM
I have the radioshack ethernet/Sd shield and I can say that it does work with the original arduino uno. Even though the shield has extra pins it still connects to my uno and functions properly. Im not an advanced arduino user but I have not run into anything that requires those extra pins. They just hang over and are not in the way of anything. They can be slightly bent if the caps on the side of the arduino uno are in the way.
ananth raj says: Sep 7, 2012. 9:22 AM
Can u make a video of this turorial, with connecting to routers and configurations in ethernet shiled.
randofo (author) says: Sep 7, 2012. 10:16 AM
That is not on my to-do list. Maybe try asking for help in the forums.
varuninnz says: Aug 12, 2012. 10:50 PM
hey man I want to confirm one thing before buying this shield. Please reply ASAP thanks.
Can this shield be used to send an email without connecting the arduino to a pc?
willpow1993 says: Sep 6, 2012. 7:59 AM
Try http://www.pushingbox.com :) It's an internet based client that, when a specific command is sent from the arduino, will send an email or a phone notification as you specify! I've found it really easy to use and they provide some fairly well documented demo code so you can easily understand what to do and modify it to your own needs. Have fun!
varuninnz says: Sep 6, 2012. 9:48 PM
thanks man. I'll check it out..
randofo (author) says: Aug 13, 2012. 11:52 AM
No. It cannot directly send email. You might be able it to connect to a server that sends email on its behalf.
varuninnz says: Aug 13, 2012. 6:18 PM
okay i'll do my research on that, but i reallly need a client that i can put on the arduino or something that can send emails without a pc. with only the Arduino.

Please let me know if you come across anything..
randofo (author) says: Aug 13, 2012. 6:25 PM
Try using the Raspberry Pi.
varuninnz says: Aug 13, 2012. 11:45 PM
okay one lasLAST question. I've used softwares like processing and gobetwino. Done all the examples on gobetwino, so i know that it can be used for sending emails. But I am avoiding using gobetwino, because I've gota real time graph running on processing and it also saves all my values on excel for personal customer analysis later on.

basically Im planning on using a keypad attached to my device to get values inputted from the user and then the calculations from the user inputted values are then displayed on a lcd.

Now my lecturer has allowed me to use a Xigbee shield for wireless data transfer. And also I've seen tutorials on this that claim to send tweets without using any Ethernet shield, however the arduino for those projects are connected to a pc. I've done the tutorials those and my program does compile but none of them have displayed anything on twitter yet.

My question is do you think it might be possible to send an email/twitter via processing if I can send all the data from my device via the Xigbee shield?

ONCE AGAIN THANK YOU FOR SUCH QUICK REPLIES. I REALLY APPRECIATE YOUR ADVISE.

randofo (author) says: Aug 14, 2012. 8:47 AM
I am not certain. It seems plausible.
stuarthooper says: Aug 31, 2012. 12:25 PM
Is there a demonstration of a library that reads as well as tweets?

Example:

Tweet sent from phone> Tweet read by Arduino> Turn Motor on for 10 seconds> Tweet sent from Arduino> Tweet read by phone> I'm happy that the motor turned on for ten seconds.

Ideally if this could respond when it is tweeted directly from certain accounts it would work better.

Thanks and Nice Tutorial
tigerbomb8 says: Mar 28, 2012. 5:03 AM
a tutorial that explains how to post to twitter would be nice
simond says: Apr 1, 2012. 6:42 AM
You can be tweeting in 5 mins with this handy tool:

http://community.thingspeak.com/tutorials/arduino/update-twitter-with-thingtweet-and-arduino-ethernet-shield/

There are probably 101 other ways to do the same thing.
timbuckles says: Aug 12, 2012. 12:08 PM
simond - would you be willing to help me use thingspeak? i am brand new to all of this and am having a bit of an issue. let me know. thank you.
1-40 of 50Next »
Pro

Get More Out of Instructables

Already have an Account?

close

PDF Downloads
As a Pro member, you will gain access to download any Instructable in the PDF format. You also have the ability to customize your PDF download.

Upgrade to Pro today!