Arduino Ethernet Shield Tutorial
Arduino Ethernet Shield Tutorial
by randofo
The Arduino Ethernet Shield allows you to easily remotely from a website, or ring a bell every time you
connect your Arduino to the internet. This shield get a new twitter message. This shield opens up
enables your Arduino to send and receive data from endless amounts of possibility by allowing you to
anywhere in the world with an internet connection. connect your project to the internet in no-time at.
You can use it to do fun stu like control robots
Step 1: Setup
Setting it up is as simple as plugging the header pins *I have not personally con rmed this. Buyer beware!
from the shield into your Arduino.
(Note that some of the links on this page are a liate
Note that the Ethernet Shield used here used to be links. This does not change the cost of the item for
sold at RadioShack. However, since RadioShack is no you. I reinvest whatever proceeds I receive into
more, the shield is harder to come by. This generic making new projects. If you would like any
ethernet shield available on Amazon should also suggestions for alternative suppliers, please let me
work.* It is meant to be used with the Arduino Uno know.)
Rev. 3 boards (or later). It has too many pins to plug
into earlier version Arduino boards.
The Ethernet Shield is based upon the W51000 chip, the use of an external SD library, which does not come
which has an internal 16K bu er. It has a connection bundled with the software. Using the SD card is not
speed of up to 10/100Mb. This is not the fastest covered in this Instructable. However, it is covered in
connection around, but is also nothing to turn your the Step 8 of the Wireless SD card instructable.
nose up at.
The board also has space for the addition of a Power
It relies on the Arduino Ethernet library, which comes over Ethernet (PoE) module, which allows you to
bundled with the development environment. power your Arduino over an Ethernet connection.
There is also an on-board micro SD slot which enables For a full technical overview, see the o cial Ethernet
you to store a heck-of-a-lot of data, and serve up Shield page.
entire websites using just your Arduino. This requires
Plug the Arduino into your computer's USB port, and File --> Examples --> Ethernet --> DhcpAddressPrinter
the Ethernet shield into your router (or direct internet
connection). Once open, you may need to change the Mac address.
On newer versions of the Ethernet shield, you should
Next, open the Arduino development environment. I see this address on a sticker attached to the board. If
highly recommend upgrading to Arduino 1.0 or later you are missing a sticker, simply making up a unique
(if you have not done so already). This version of the mac address should work. If you are using multiple
software has built in DHCP support, and does not shields, make sure each has a unique mac address.
require manually con guring an IP address.
Once the mac address is properly con gured, upload
To gure out what IP address has been assigned to the sketch to your Arduino, and open the serial
your board, open the DhcpAddressPrinter sketch. This monitor. It should print out the IP address in use.
can be found at:
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:
<pre>/*
Web Server Demo
thrown together by Randy Sarafan
A simple web server that changes the page that is served, triggered by a button press.
Circuit:
* Ethernet shield attached to pins 10, 11, 12, 13
* Connect a button between Pin D2 and 5V
Arduino Ethernet Shield Tutorial: Page 3
* Connect a button between Pin D2 and 5V
* Connect a 10K resistor between Pin D2 and ground
Based almost entirely upon Web Server by Tom Igoe and David Mellis
Edit history:
created 18 Dec 2009
by David A. Mellis
modified 4 Sep 2010
by Tom Igoe
*/
#include <SPI.h>
#include <Ethernet.h>
int buttonPress = 1;
void setup()
{
pinMode(2, INPUT);
void loop()
{
buttonPress = digitalRead(2);
// listen for incoming clients
EthernetClient client = server.available();
if (client) {
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
// if you've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so you can send a reply
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();
break;
}
if (c == '\n') {
// you're starting a new line
currentLineIsBlank = true;
}
else if (c != '\r') {
// you've gotten a character on the current line
currentLineIsBlank = false;
Arduino Ethernet Shield Tutorial: Page 4
}
}
}
// give the web browser time to receive the data
delay(1);
// close the connection:
client.stop();
}
}
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 turn it on:
http://your-IP-address/$1
To turn it off:
http://your-IP-address/$2
Circuit:
* Ethernet shield attached to pins 10, 11, 12, 13
* Connect an LED to pin D2 and put it in series with a 220 ohm resistor to ground
Based almost entirely upon Web Server by Tom Igoe and David Mellis
Edit history:
created 18 Dec 2009
by David A. Mellis
modified 4 Sep 2010
by Tom Igoe
*/
#include <SPI.h>
#include <Ethernet.h>
boolean incoming = 0;
void setup()
{
pinMode(2, OUTPUT);
void loop()
{
// listen for incoming clients
EthernetClient client = server.available();
if (client) {
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
// if you've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so you can send a reply
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.
Arduino Ethernet Shield Tutorial: Page 6
To turn on the LED enter this into your browser:
http://[ YO UR IP ADDRES S HERE] /$1
Note: You should obviously replace [ YO UR IP ADDRES S HERE] with your IP address.){ incoming = 1; } //Checks for
the URL string $1 or $2 if(incoming == 1){ Serial.println(c); if(c == '1'){ Serial.println("ON"); digitalWrite(2, HIGH); } if(c
== '2'){ Serial.println("OFF"); digitalWrite(2, LOW ); } }
if (c == '\n') { // you're starting a new line currentLineIsBlank = true; } else if (c != '\r') { // you've gotten a character on
the current line currentLineIsBlank = false; } } } // give the web browser time to receive the data delay(1); // close the
connection: client.stop(); } }
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.
Note: You should obviously replace [ YO UR IP ADDRES S HERE] with your IP address.
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 modi ed 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.
This sketch connects to Twitter using an Ethernet shield. It parses the XML
returned, and looks for <text>this is a tweet</text>
You can use the Arduino Ethernet shield, or the Adafruit Ethernet shield,
either one will work, as long as it's got a Wiznet Ethernet module on board.
This example uses the DHCP routines in the Ethernet library which is part of the
Arduino core from version 1.0 beta 1
This example uses the String library, which is part of the Arduino core from
version 0019.
Circuit:
* Ethernet shield attached to pins 10, 11, 12, 13
void setup() {
pinMode(2, OUTPUT);
// initialize serial:
Serial.begin(9600);
// attempt a DHCP connection:
if (!Ethernet.begin(mac)) {
// if DHCP fails, start with a hard-coded address:
Ethernet.begin(mac, ip);
}
// connect to Twitter:
connectToServer();
}
void loop()
{
if (client.connected()) {
if (client.available()) {
// read incoming bytes:
char inChar = client.read();
void connectToServer() {
// attempt to connect, and wait a millisecond:
Serial.println("connecting to server...");
if (client.connect(serverName, 80)) {
Serial.println("making HTTP request...");
// make HTTP GET request to twitter:
client.println("GET /1/statuses/user_timeline.xml?screen_name=RandyMcTester&count=1 HTTP/1.1");
client.println("HOST: api.twitter.com");
client.println();
}
// note the time of this connect attempt:
lastAttemptTime = millis();
}
Presumably you are going to want to read something other than the recent post on the RandyMcTester Twitter
feed.
And also some cheap W5100 shields has a problem with a resistor array situated near the RJ45
socket. It should be 510 instead of 511 (51Ohm instead of 510ohm)
That's the case with my Ethernet shield. I do not have the right equipment to replace the
resistors....
So how do you know if your buying the good one if there is no version numbers on these board ?
Also Are you saying the ones with the Bad Resistor values are NO GOOD at all or flakey ?
Hi, This post is really informative.
I'm facing difficulty connecting arduino ethernet with PC using a switch (Dlink). When both are
connected directly(p2p) using ethernet cable, arduino device can be pinged. However, when
connected via switch - ping doesn't work, and both devices can't communicate with each other;
updated the MAC addr. several times, nothing worked. I'm stuck. Can you suggest something on
this?
i've got the same problem. set a fixed ip.. it doesn't solve the problem but you go further
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.
Thanks in advance hopefully someone can help!!
Can i ask if whats your mac adress for your ethernet? We have a project and its the same ethernet
shield we use, but we dont know the mac address. Reply asap. Thank you
The Arduino shield and the computer both have the same RJ45 connections. That is, the send and
receive pins are on the same pin for both sender and receiver. If you connect them directly with a
cable, the send pins match up and the receive pins match up and therefore you get no
communications.
You either need an Ethernet hub/switch or a cross over cable that crosses over the Send and
Receive pins. The hub/switch is definetly the easiest way to go and you can pick them up cheaply
from amazon.
the twitter api updated and now you need authentication, which i have no idea how you get
authentication...
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
I am unable to copy the sample code that you provided. Is it available somewhere that it copied?
Thanks.
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.
Does anyone know how to connect the radio module NRF24L01
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]
can you use this shield connected to your computers ethranet port
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. :)
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.
You need to port forward the IP and port you are using of the ethernet shield to the internet
This website may help: http://portforward.com/
I guess the local dynamic IP has to be changed, right..?
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.
http://arduino.cc/en/Reference/EthernetIPAddress
you can find your DNS servers, gateway, and subnet by typing ipconfig /all in a windows command
line.
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 ipconfig /all and change the numbers after the last dot to 254 and
put that in the arduino code as its IP.
Where to get that IP?
Nice Tutorial!!
I'm a engineer in WIZnet providing W5100 to the official Arduino Ethernet Shield.
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.
Thank you.
my ethernet shields ic gets hot will u plsplspls help me for that
am using arduino leonardo board
pls help me
regards
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.