KinectDuino

Kinect and Arduino one step ahead to Computer Science

How to wire and test your Arduino + Ethernet Shield

Image

In this post, I will focus on how to wire Arduino UNO R3 to Arduino LAN Ethernet Shield R3 and Arduino MEGA R2 to Arduino LAN Ethernet Shield, then test whether it works or not.

Notice that, I will only use Serial Cable, Arduino UNO R3, Arduino MEGA R2, and Arduino LAN Ethernet Shield R3 as the model, because there comes a lot of problem when deals with them, so I hope this guidance will help you. Here, the good idea is we do not need to use any ethernet cable.

In order to make sure the devices, here I attached the image:

Arduino UNO R3 with ATMega 328, price IDR 279,000

Arduino MEGA R2 with ATMega 2560, price IDR 300,000 (2nd hand)

Arduino LAN Ethernet Shield with chip w5100 (relatively hot), price IDR 499,000

Here is the wiring from UNO to Ethernet Shield:

Image

Wiring UNO R3 to Ethernet Shield R3, it is better wiring them than piling them up in order to keep the feet strong (not bent)

Connect ICSP (UNO) to ICSP Header (Eth Shield) with common arrangement.

Then, pin 4 to pin 4 and pin 10 to pin 10. That’s all !

Here is the wiring from Mega to Ethernet Shield:

Image

Wiring them, from ICSP to ICSP header with common pin arrangement, then pin 4 to pin 4 and pin 10 to pin 10, that’s all!

Here is the code I upload using Arduino 1.0 IDE to Arduino UNO, also the same to Arduino Mega:

/*
Web Server

A simple web server that shows the value of the analog input pins.
using an Arduino Wiznet Ethernet shield.

Circuit:
* Ethernet shield attached to pins 10, 11, 12, 13 // this is only valid for UNO, it works also if you follow this, but keep it simple.
* Analog inputs attached to pins A0 through A5 (optional)

created 18 Dec 2009
by David A. Mellis
modified 9 Apr 2012
by Tom Igoe

*/

#include <SPI.h>
#include <Ethernet.h>

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
0x90, 0xA2, 0xDA, 0x00, 0xFE, 0xAC }; //this is only valid for my Eth Shield, check yours at the back of Eth Shield
IPAddress ip(192,168,1,177);// this is the address assigned to my eth shield, so you may create on your own, could be 192,168,1,102, etc

// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);

void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);


// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
server.begin();
Serial.print("server is at ");
Serial.println(Ethernet.localIP());
}


void loop() {
// listen for incoming clients
EthernetClient client = server.available();
if (client) {
Serial.println("new client");
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
Serial.write(c);
// 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("Connnection: close");
client.println();
client.println("<!DOCTYPE HTML>");
client.println("<html>");
// add a meta refresh tag, so the browser pulls again every 5 seconds:
client.println("<meta http-equiv=\"refresh\" content=\"5\">");
// output the value of each analog input pin
for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
int sensorReading = analogRead(analogChannel);
server.print("analog input ");
client.print(analogChannel);
client.print(" is ");
client.print(sensorReading);
client.println("<br />");
}
client.println("</html>");
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;
}
}
}
// give the web browser time to receive the data
delay(1);
// close the connection:
client.stop();
Serial.println("client disonnected");
}
}

If your uploading seems freezing (often happen to Mega R2, press reset, then try to unplug, plug, then press reset,then upload again). After finish uploading, then open serial monitor:

Serial Monitor should shows this address if the devices works well and the wirings are correct.

Finally, this is how to test and wire Arduino and Ethernet Shield, enjoy and do not hesitate to ask :D.

Advertisements

8 comments on “How to wire and test your Arduino + Ethernet Shield

  1. hussammehboob
    August 21, 2013

    Ok so I followed the tutorial but the line which is printed on my serial monitor is server at 0.0.0.0 although IP address I set is different. Possible solutions? Can it be because of different MAC address? But i heard that MAC address doesnt matter.

  2. zugiduino
    August 22, 2013

    @hunssammehboob check the wiring

  3. Rich
    September 8, 2013

    Excellent! Worked for me first time after hours diddling with other peoples code. Glad I found yours. Thanks

  4. MON
    October 21, 2013

    So i can use ethernet shield normally by this connection , right ??? i dont have to stick it to arduino mega any more ?! and does it work on mega 2560 ?

    • zugiduino
      October 21, 2013

      yes you can… you dont have to any more
      yes it does work

  5. MON
    October 21, 2013

    thanks you for quick reply and for this useful connection .I still wonder where is the ethernet shield power source ?! where is the 5v and gnd connections ?!

  6. MON
    October 21, 2013

    OKay i figured it out .. Thanks 😀

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Information

This entry was posted on July 11, 2012 by in Arduino and tagged , , , .
%d bloggers like this: