Arduino DHCP failed to configure

22,588

Solution 1

The solution that fixed this for me was to remove the Micro SD card from the slot, I saw your issue was related to a fault but others having this issue should remove the Micro SD card after turning off the Arduino.

Solution 2

try this code :) it worked for me

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

// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = {  
  0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };

// Initialize the Ethernet client library
// with the IP address and port of the server 
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;

void setup() {
 // Open serial communications and wait for port to open:
  Serial.begin(9600);
  // this check is only needed on the Leonardo:


  // start the Ethernet connection:
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // no point in carrying on, so do nothing forevermore:
    for(;;)
      ;
  }
  // print your local IP address:
  Serial.print("My IP address: ");
  for (byte thisByte = 0; thisByte < 4; thisByte++) {
    // print the value of each byte of the IP address:
    Serial.print(Ethernet.localIP()[thisByte], DEC);
    Serial.print("."); 
  }
  Serial.println();
}

void loop() {

}
Share:
22,588
Andrew
Author by

Andrew

Updated on February 09, 2020

Comments

  • Andrew
    Andrew over 4 years

    I am using the example ethernet sketch for a web client that comes bundled with the Arduino software without changing a thing except for the firmware address, which I changed to the one printed on the back of the ethernet shield.

    Whenever I connect the Arduino to my network and view the serial monitor, the only message I get is that it "Failed to configure Ethernet using DHCP".

    I have setup my Arduino Mega 2560 with an ethernet shield, correctly connecting ports 50 to MISO, 51 to MOSI, 52 to SCK, and 10 to SS (a.k.a. ETHCS as it is printed on the ethernet board).

    Do you guys have any idea why this DHCP error would be happening?

    Here is my code:

    #include <SPI.h>
    #include <Ethernet.h>
    
    byte mac[] = {  0x90, 0xA2, 0xDA, 0x00, 0x73, 0xE4 }; //ethernet mac
    IPAddress server(192, 168, 1, 9); //valid server IP in my network
    
    EthernetClient client;
    
    void setup() {
      Serial.begin(9600);
    
      if (Ethernet.begin(mac) == 0) {
        Serial.println("Failed to configure Ethernet using DHCP");
    
        for(;;)
          ;
      }
    
      delay(1000);
      Serial.println("connecting...");
    
      if (client.connect(server, 80)) {
        Serial.println("connected");
    
        client.println("GET /search?q=arduino HTTP/1.0");
        client.println();
      } 
      else {
        Serial.println("connection failed");
      }
    }
    
    void loop()
    {
      if (client.available()) {
        char c = client.read();
        Serial.print(c);
      }
    
    
      if (!client.connected()) {
        Serial.println();
        Serial.println("disconnecting.");
        client.stop();
    
        for(;;)
          ;
      }
    }
    
  • emmanuel honore
    emmanuel honore about 11 years
    Thanks a lot! After I removed the SD Card it worked for me the first time!
  • ThomasW
    ThomasW almost 11 years
    This question looks into the issue: electronics.stackexchange.com/questions/67045/…
  • Stanimir Stoyanov
    Stanimir Stoyanov about 4 years
    That code more than 7 years old. I would suggest to try the official documentation at arduino.cc/en/Tutorial/DhcpAddressPrinter