Ethernet Shield is not getting IP from DHCP

i am also facing the same issue it is stuck at
“Trying to get an IP address using DHCP”

i am connecting cable to my router which should assign ip address

i am using the standard sketch of DhcpChatServer for my ethernet shield for UNO

details below

it is a HANRUN HR911105A 15/10 WIZNET W5100

i have tried the Blink sketch it works fine

can anybody help

Sketch Below

DHCP Chat Server

A simple server that distributes any incoming messages to all
connected clients. To use, telnet to your device’s IP address and type.
You can see the client’s input in the serial monitor as well.
Using an Arduino Wiznet Ethernet shield.

THis version attempts to get an IP address using DHCP


  • Ethernet shield attached to pins 10, 11, 12, 13

created 21 May 2011
modified 9 Apr 2012
by Tom Igoe
modified 02 Sept 2015
by Arturo Guadalupi
Based on ChatServer example by David A. Mellis


#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.
// gateway and subnet are optional:
byte mac = {
0xCD, 0xAA, 0xBB, 0xCC, 0xDD, 0x03
IPAddress ip(192, 168, 1, 1);
IPAddress myDns(192, 168, 1, 1);
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 255, 0);

// telnet defaults to port 23
EthernetServer server(23);
boolean gotAMessage = false; // whether or not you got a message from the client yet

void setup() {
// Open serial communications and wait for port to open:
// 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:
Serial.println(“Trying to get an IP address using DHCP”);
if (Ethernet.begin(mac) == 0) {
Serial.println(“Failed to configure Ethernet using DHCP”);
// initialize the Ethernet device not using DHCP:
Ethernet.begin(mac, ip, myDns, gateway, subnet);
// print your local IP address:
Serial.print(“My IP address: “);
ip = Ethernet.localIP();
for (byte thisByte = 0; thisByte < 4; thisByte++) {
// print the value of each byte of the IP address:
Serial.print(ip[thisByte], DEC);
// start listening for clients


void loop() {
// wait for a new client:
EthernetClient client = server.available();

// when the client sends the first byte, say hello:
if (client) {
if (!gotAMessage) {
Serial.println(“We have a new client”);
client.println(“Hello, client!”);
gotAMessage = true;

// read the bytes incoming from the client:
char thisChar =;
// echo the bytes back to the client:
// echo the bytes to the server as well:

Do you have a SD card in the shield's slot? Is it connected directly to a router or is there a switch in between the two?

It takes about 2 minutes to return a fail from the DHCP request. Are you waiting that long?

yes SD card slot is there but no SD card in it,

yes more than 2 -5 mins , no change in the message.

I am connecting cable to my router no switch in middle.

Remove the card, power down the Arduino for a few seconds, then try it again.

Compile and upload this test code. You don’t need to change anything. What does the serial monitor show? Does it show If so, the SPI bus and SPI side of the w5100 is ok. If it shows anything else, like, it is failing. Insure the shield is connected to the Arduino correctly and inserted completely into the pin sockets. Insure the ethernet shield controller is in fact a w5100, and not a w5200, w5500, or enc28j60.

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

byte mac[] = {  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,0,2);

void setup() {

  // disable SD card if one in the slot

  Serial.println("Starting w5100");


void loop() {

i am getting output below

Starting w5100

blink is working fine on D13 pin and also checked Ultrasonic sensor on pin D9 both work fine

verified again it is a W5100

except the Ip address.

Then you have a SPI bus hardware failure.

yes i replaced with a new Ethernet Shield W5100 it is working fine now , I am able to connect to MQTT broker .