Arduino W5500 Ethernet Web Client with DHCP: Wiring, Code and Simulator

To build this Arduino W5500 Ethernet Web Client with DHCP project you need an Arduino Uno and a W5500 ethernet module. Ethernet.begin(mac) gets an address from the lab router by DHCP; EthernetClient resolves a name, connects and prints a web page. Make the 6 connections in the wiring table, upload the Arduino C++ code, and unplug the cable (the part’s control) and run again to see the link check. Put the logic analyzer on the SPI pins to watch the W5500 frames.

Open this circuit in the free Arduino Uno simulator

Parts list

QtyPartWhat it does
1Arduino Unothe microcontroller board
1W5500 Ethernet moduleWired Ethernet on SPI: VCC 3.3 V, GND, CS to pin 10, SCK/MOSI/MISO to the board’s SPI pins. Ethernet.begin(mac) gets an address from the lab router by DHCP; EthernetClient fetches web pages, and an EthernetServer’s page opens from the Modules tab.

Wiring

#FromTo
1Arduino Uno 3.3VW5500 Ethernet module VCC
2Arduino Uno GNDW5500 Ethernet module GND
3Arduino Uno pin 10W5500 Ethernet module CS
4Arduino Uno pin 13W5500 Ethernet module SCK
5Arduino Uno pin 11W5500 Ethernet module MOSI
6Arduino Uno pin 12W5500 Ethernet module MISO

Step by step

  1. Open the simulator. Open the BitForBytes Embedded Lab in your browser and start from the Arduino Uno. No install or account is needed.
  2. Add the parts. Add a W5500 ethernet module from the parts palette.
  3. Wire 1. Connect Arduino Uno 3.3V to W5500 Ethernet module VCC.
  4. Wire 2. Connect Arduino Uno GND to W5500 Ethernet module GND.
  5. Wire 3. Connect Arduino Uno pin 10 to W5500 Ethernet module CS.
  6. Wire 4. Connect Arduino Uno pin 13 to W5500 Ethernet module SCK.
  7. Wire 5. Connect Arduino Uno pin 11 to W5500 Ethernet module MOSI.
  8. Wire 6. Connect Arduino Uno pin 12 to W5500 Ethernet module MISO.
  9. Paste the Arduino C++ code. Paste the Arduino C++ code below into the code editor.
  10. Run it. Press Run. Unplug the cable (the part’s control) and run again to see the link check. Put the logic analyzer on the SPI pins to watch the W5500 frames.

Arduino C++ code

// W5500 Ethernet: get an address by DHCP and fetch a web page with EthernetClient.
// CS -> 10, SCK -> 13, MOSI -> 11, MISO -> 12, VCC 3.3V, GND.
#include <SPI.h>
#include <Ethernet.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
EthernetClient client;

void setup() {
  Serial.begin(115200);
  Ethernet.init(10);
  Serial.println(F("Asking the router for an address (DHCP)..."));
  if (Ethernet.begin(mac) == 0) {
    Serial.println(F("DHCP failed."));
    if (Ethernet.hardwareStatus() == EthernetNoHardware) Serial.println(F("No Ethernet chip found."));
    if (Ethernet.linkStatus() == LinkOFF) Serial.println(F("The cable is not plugged in."));
    while (true) {}
  }
  Serial.print(F("My address: "));
  Serial.println(Ethernet.localIP());

  if (client.connect("api.open-meteo.com", 80)) {
    Serial.println(F("Connected."));
    client.println(F("GET /v1/forecast?latitude=28.61&longitude=77.21&current=temperature_2m HTTP/1.1"));
    client.println(F("Host: api.open-meteo.com"));
    client.println(F("Connection: close"));
    client.println();
  } else {
    Serial.println(F("Connection failed."));
  }
}

void loop() {
  while (client.available()) Serial.write(client.read());
  if (!client.connected()) {
    Serial.println(F("\nDisconnected."));
    client.stop();
    while (true) {}
  }
}

What to try

Unplug the cable (the part’s control) and run again to see the link check. Put the logic analyzer on the SPI pins to watch the W5500 frames.

Frequently asked questions

How do I wire the W5500 Ethernet Web Client with DHCP project on an Arduino Uno?

Make 6 connections: Arduino Uno 3.3V to W5500 Ethernet module VCC; Arduino Uno GND to W5500 Ethernet module GND; Arduino Uno pin 10 to W5500 Ethernet module CS; Arduino Uno pin 13 to W5500 Ethernet module SCK; Arduino Uno pin 11 to W5500 Ethernet module MOSI; Arduino Uno pin 12 to W5500 Ethernet module MISO.

What parts do I need for this Arduino project?

An Arduino Uno and a W5500 ethernet module.

Can I simulate this Arduino project online for free?

Yes. The BitForBytes Embedded Lab runs this exact circuit and Arduino C++ code in your browser for free, with no install and no hardware. The sketch is compiled with the real Arduino toolchain and runs on an emulated ATmega328P.

What does the code do?

Ethernet.begin(mac) gets an address from the lab router by DHCP; EthernetClient resolves a name, connects and prints a web page.

Does the Arduino Ethernet library support the W5500?

Yes. Ethernet 2.x detects a W5100, W5200 or W5500 by itself; call Ethernet.init(csPin) before Ethernet.begin().

Why does Ethernet.begin(mac) return 0?

No DHCP server answered: the cable is unplugged, the router is off, or the chip is not wired. Check Ethernet.hardwareStatus() and Ethernet.linkStatus().

More Arduino Uno projects