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
| Qty | Part | What it does |
|---|---|---|
| 1 | Arduino Uno | the microcontroller board |
| 1 | W5500 Ethernet module | Wired 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
| # | From | To |
|---|---|---|
| 1 | Arduino Uno 3.3V | W5500 Ethernet module VCC |
| 2 | Arduino Uno GND | W5500 Ethernet module GND |
| 3 | Arduino Uno pin 10 | W5500 Ethernet module CS |
| 4 | Arduino Uno pin 13 | W5500 Ethernet module SCK |
| 5 | Arduino Uno pin 11 | W5500 Ethernet module MOSI |
| 6 | Arduino Uno pin 12 | W5500 Ethernet module MISO |
Step by step
- Open the simulator. Open the BitForBytes Embedded Lab in your browser and start from the Arduino Uno. No install or account is needed.
- Add the parts. Add a W5500 ethernet module from the parts palette.
- Wire 1. Connect Arduino Uno 3.3V to W5500 Ethernet module VCC.
- Wire 2. Connect Arduino Uno GND to W5500 Ethernet module GND.
- Wire 3. Connect Arduino Uno pin 10 to W5500 Ethernet module CS.
- Wire 4. Connect Arduino Uno pin 13 to W5500 Ethernet module SCK.
- Wire 5. Connect Arduino Uno pin 11 to W5500 Ethernet module MOSI.
- Wire 6. Connect Arduino Uno pin 12 to W5500 Ethernet module MISO.
- Paste the Arduino C++ code. Paste the Arduino C++ code below into the code editor.
- 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¤t=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
- Arduino LED Blink: Wiring, Code and Simulator
- Arduino LDR Light Sensor: Wiring, Code and Simulator
- Arduino NTC Thermistor Thermometer: Wiring, Code and Simulator
- Arduino PWM to Analog RC Filter: Wiring, Code and Simulator
- Arduino Capacitance Meter: Wiring, Code and Simulator
- Arduino DC Motor PWM Speed Control with MOSFET: Wiring, Code and Simulator