The Ethernet shield allows you to connect a WizNet Ethernet controller to the Arduino via the SPI bus. It uses pins 10, 11, 12, and 13 for the SPI connection to the WizNet. Later models of the Ethernet shield also have an SD Card on board. Digital pin 4 is used to control the slave select pin on the SD card.

The shield should be connected to a network with an ethernet cable. You will need to change the network settings in the program to correspond to your network.

// Open serial communications and wait for port to open:Serial.begin(9600);while(!Serial){;// wait for serial port to connect. Needed for Leonardo only}

// attempt a DHCP connection:Serial.println("Attempting to get an IP address using DHCP:");if(!Ethernet.begin(mac)){// if DHCP fails, start with a hard-coded address:Serial.println("failed to get an IP address using DHCP, trying manually");
Ethernet.begin(mac, ip);}Serial.print("My address:");Serial.println(Ethernet.localIP());// connect to Twitter:
connectToServer();}

// if you get a newline, clear the line:if(inChar =='\n'){
currentLine ="";}// if the current line ends with <text>, it will// be followed by the tweet:if( currentLine.endsWith("<text>")){// tweet is beginning. Clear the tweet string:
readingTweet =true;
tweet ="";}// if you're currently reading the bytes of a tweet,// add them to the tweet String:if(readingTweet){if(inChar !='<'){
tweet += inChar;}else{// if you got a "<" character,// you've reached the end of the tweet:
readingTweet =false;Serial.println(tweet);// close the connection to the server:
client.stop();}}}}elseif(millis()- lastAttemptTime > requestInterval){// if you're not connected, and two minutes have passed since// your last connection, then attempt to connect again:
connectToServer();}}

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=arduino&count=1 HTTP/1.1");
client.println("HOST: api.twitter.com");
client.println("Connection: close");
client.println();}// note the time of this connect attempt:
lastAttemptTime =millis();}