Ethernet W5100 problem with connecting Ethernet cable

hi there,

I recently bought Ethernet Shiled w5100, I tried to connect it to arduino, found the code, plugged in and nothing happened.

Today I tired to find out what I did wrong 2 months ago. And found out that timing is the problem, but not these 2 months!
After countless restarts of the board and connecting ethernet cable over and over again to the board, I found that my board is working if I connect cable around a one sec after I press restart button.

To be sure about this, I uploaded another sketch and did the same thing and got my board is on network.
BUT if I leave the cable in ethernet port and restart the board, arduino will not appear on the network.

I used sketch that is built in arduino ide.

So, my question is why this is happening and how can I fix this issue, so my board can connect to the network without removing the ethernet cable?

EDIT:

Youtube link with recorded issue.

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

byte mac[] = { 0x00, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address 
byte ip[] = { 192, 168, 0, 150 }; // IP address in LAN – need to change according to your Network address 
byte gateway[] = { 192, 168, 0, 1 }; // internet access via router 
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask 
EthernetServer server(80); //server port

String readString; 
int ledPin = 2;

void setup(){
    Serial.begin(9600);
    pinMode(ledPin, OUTPUT); //pin selected to control 
    // Test LED 
    digitalWrite(ledPin, HIGH); // set pin high 
    delay(500); 
    digitalWrite(ledPin, LOW); // set pin low 
    
    //start Ethernet 
    Ethernet.begin(mac, ip, gateway, subnet); 
    server.begin(); 
    Serial.print("server is at ");
    Serial.println(Ethernet.localIP());
}

void loop(){ 
    // Create a client connection 
    EthernetClient client = server.available(); 
//    if(server.available()){
//      Serial.println("Server ok");
//    } else {
//      Serial.println("No Good");
//      client = server.available();
//    }
    if (client) { 
        while (client.connected()) { 
            if (client.available()) { 
                char c = client.read();

                //read char by char HTTP request 
                if (readString.length() < 100) {

                    //store characters to string 
                    readString += c; 
                }

                //if HTTP request has ended– 0x0D is Carriage Return \n ASCII 
                if (c == 0x0D) { 
                    client.println("HTTP/1.1 200 OK"); //send new page 
                    client.println("Content-Type: text/html"); 
                    client.println();

                    client.println("<HTML>"); 
                    client.println("<HEAD>"); 
                    client.println("<TITLE> ARDUINO ETHERNET SHIELD</TITLE>"); 
                    client.println("</HEAD>"); 
                    client.println("<BODY>"); 
                    client.println("<hr>"); 
                    client.println("<hr>"); 
                    client.println("
"); 
                    client.println("<H3 style=\"color:green;\">ARDUINO ETHERNET SHIELD — LED ON/OFF FROM WEBPAGE</H3>"); 
                    client.println("<hr>"); 
                    client.println("
");

                    client.println("<H5><a href=\"/?LEDON\"\">Turn On LED</a>
</H5>"); 
                    client.println("<H5><a href=\"/?LEDOFF\"\">Turn Off LED</a>
</H5>");

                    client.println("</BODY>"); 
                    client.println("</HTML>");

                    delay(10); 
                    //stopping client 
                    client.stop();

                    // control arduino pin 
                    if(readString.indexOf("?LEDON") > -1) //checks for LEDON 
                    { 
                        digitalWrite(ledPin, HIGH); // set pin high 
                    } 
                    else{ 
                        if(readString.indexOf("?LEDOFF") > -1) //checks for LEDOFF 
                        { 
                            digitalWrite(ledPin, LOW); // set pin low 
                        } 
                    } 
                    //clearing string for next read 
                    readString="";
                } 
            } 
        } 
    } 
}

Thanks,
Lazar

I have asked the moderators to move your thread into the networking section; this is not an installation and troubleshooting question.

SD card is not inserted? if yes remove it.
try the examples of the latest version of the Ethernet library

@Juraj no sd card
@DrAzzy no problem :slight_smile:

@Juraj I have added Ethernet lib version 2, no changes.

library downloaded from here

I don't know if you are aware, but the W5100 Ethernet shields from China have wrong resistor values.

I don't know if that is the cause of your problem. Ethernet Shield W5100 connection issue - Networking, Protocols, and Devices - Arduino Forum

ieee488:
I don't know if you are aware, but the W5100 Ethernet shields from China have wrong resistor values.

I don't know if that is the cause of your problem. Ethernet Shield W5100 connection issue - Networking, Protocols, and Devices - Arduino Forum

I read about it, but this shield under some conditions start working just fine.

I am not sure if resistors are root cause, but however it behaves strange.
EDIT

i measured this resistor and value is 501 ohm, is that correct? And mark is 511 on it.
Do you know what ethernet shield will work fine?

thanks :slight_smile:

I tried to solder two resistors according to this video,and my shield does not work.
:frowning:

lazarvgd:
@Juraj I have added Ethernet lib version 2, no changes.

library downloaded from here

the library is in Library Manager in IDE, you don't need to download it.

what does the WebServer example print to Serial Monitor?

Juraj:
the library is in Library Manager in IDE, you don’t need to download it.

what does the WebServer example print to Serial Monitor?

Image:
Imgur
it says that older w5100 based shileds are not supported.

any way I tried and serial monitor says:

server is at 0.0.0.0

code used:

/*
  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
 * 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 <Ethernet2.h>

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress ip(192, 168, 0, 150);

// 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);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }


  // 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("Connection: close");  // the connection will be closed after completion of the response
          client.println("Refresh: 5");  // refresh the page automatically every 5 sec
          client.println();
          client.println("<!DOCTYPE HTML>");
          client.println("<html>");
          // output the value of each analog input pin
          for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
            int sensorReading = analogRead(analogChannel);
            client.print("analog input ");
            client.print(analogChannel);
            client.print(" is ");
            client.print(sensorReading);
            client.println("
");
          }
          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 disconnected");
  }
}

Ethernet2 1.04 is not Ethernet 2.00
Ethernet2 is obsolete and doesn't support W5100

Juraj:
Ethernet2 1.04 is not Ethernet 2.00
Ethernet2 is obsolete and doesn't support W5100

That Is the only one that I found, can you please share your version of lib?

lazarvgd:
That Is the only one that I found, can you please share your version of lib?

see Library Manager in IDE

lm-ethernet.png