Frustrated with Arduino Mega2560 R2!!! [SOLVED!]

I am trying sketch example: WebServer.ino

  Web Server
 A simple web server that shows the value of the analog input pins.
 using an Arduino Wiznet Ethernet shield.
 * Ethernet shield attached to pins 10, 11, 12, 13
 * 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 };
IPAddress ip(192,168,1,177);

// 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:
  pinMode (53, OUTPUT);
  digitalWrite (53, HIGH);

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

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 =;
        // 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("<!DOCTYPE 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(" is ");
        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
    // close the connection:
    Serial.println("client disonnected");

Then I upload it to UNO, then it is successfully working!
in the serial monitor it displays:
server is at

But then when I am trying to upload it to Mega, connect from Mega to Eth Shield:
pin 53 to pin 10 (then set it High)
pin 52 to pin 13
pin 51 to pin 11
pin 50 to pin 12
in the serial monitor it displays:
server is at
my code? but it works at UNO!
my wiring? which one?

Please help!

The w5100 library underlying Ethernet uses Pin 10 for Slave Select, not necessarily the ATmega "Slave Select" pin (10 on UNO and 53 on Mega). Instead of connecting Pin 10 of the shield to Pin 53 on the Mega you should try connecting it to Pin 10 on the Mega.

Since you mentioned SD on your other thread, then you should know this: If you use that code, and insert a microSD card into the shield's slot without either initializing or disabling it, you will get even more frustrated.

Thank you so much for the help! The problem has been solved here:,111855.0.html


creativen: PROBLEM SOLVED!

Please modify your original post / topic line with the word "SOLVED".