Arduino Ethernet Shield Rev3 DHCP "Failed to configure Ethernet using DHCP"

Hello guy
i am new to this things this is my first project that i have ever done so dont be harsh on me if i have any mistakes

i got an Arduino uno and a Arduino Ethernet Shield Rev3 and i tried to do connect the ethernet shield with the router using a lan cable and on Arduino IDE went to File-> examples -> Ethernet -> DHCPAddressPrinter which i think is tells me my ip address for my Arduino but the output is "Failed to configure Ethernet using DHCP" did some research didnt find anything to work

this is the code which is provided in the IDE :


/*
  DHCP-based IP printer

  This sketch uses the DHCP extensions to the Ethernet library
  to get an IP address via DHCP and print the address obtained.
  using an Arduino Wiznet Ethernet shield.

  Circuit:
   Ethernet shield attached to pins 10, 11, 12, 13

  created 12 April 2011
  modified 9 Apr 2012
  by Tom Igoe
  modified 02 Sept 2015
  by Arturo Guadalupi

*/

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

  // 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:
  printIPAddress();
}

void loop() {

  switch (Ethernet.maintain())
  {
    case 1:
      //renewed fail
      Serial.println("Error: renewed fail");
      break;

    case 2:
      //renewed success
      Serial.println("Renewed success");

      //print your local IP address:
      printIPAddress();
      break;

    case 3:
      //rebind fail
      Serial.println("Error: rebind fail");
      break;

    case 4:
      //rebind success
      Serial.println("Rebind success");

      //print your local IP address:
      printIPAddress();
      break;

    default:
      //nothing happened
      break;

  }
}

void printIPAddress()
{
  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();
}

The purpose of the project is to send data to a database
thanks for helping

think you need to tidy the code of post #1 - it is a mess and very difficult to read
what is the problem? what happens when you run the code?
what is the network and does it have a DHCP server with general access?
upload a printout of the serial monitor?

I didnt know how to tide up the code its the sample code that it is available in the Arduino IDE the output is failed
I have connected my ethernet rev3 to my router and yes it has DHCP Server with this code it shows me the ip address of the arduino but the output it says failed to configure ethernet using DHCP
i the arduino to send data to a database through ethernet

if I run the code of post #1 on my Ethernet shield V1 the DHCP works OK

My IP address: 192.168.1.222.

do you have the correct chip select pin?

void setup() {
  // You can use Ethernet.init(pin) to configure the CS pin
  //Ethernet.init(10);  // Most Arduino shields
  //Ethernet.init(5);   // MKR ETH shield
  //Ethernet.init(0);   // Teensy 2.0
  //Ethernet.init(20);  // Teensy++ 2.0
  //Ethernet.init(15);  // ESP8266 with Adafruit Featherwing Ethernet
  //Ethernet.init(33);  // ESP32 with Adafruit Featherwing Ethernet

think it defaults to pin 10
is it a home network?

try a web search for Arduino Ethernet Shield Rev3 you will get plenty of links


see lots of vidoes and i belive i have set it correctly but still no ip address

the photo appears to show a stack of 3 boards- Arduino, Ethernet shield and ??
I have had problems when using multiple boards of devices using the same pins for CS etc

Its not 3 boards
Its arduino and the shield

I remember I had problems connecting the Ethernet shield to a new router (old one was OK)
I replaced the default arduino Ethernet libnrary with WIZ_Ethernet_Library

still same thing it says failed to connect

is it your home network?
can other devices connect via ethernet, e.g. desktop, laptop, etc?
can you look at the router and check its configuration?

it is home network and yes i can connect my laptop through ethernet no problem
i have searched everywhere still no cure what i have done wrong

what do the various LEDs on the board do?
try wireshark to monitor the traffic on the Ethernet ?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.