How to Use W5500 Ethernet Module with ESP32 38-Pin
Introduction
In this tutorial, you will learn how to use the W5500 Ethernet module with an ESP32 38-pin development board to build a simple web-based relay control system.
This project does not use WiFi, MQTT, or cloud services. Instead, it uses pure Ethernet communication, making it ideal for stable, low-latency, and offline IoT applications.
I have already designed the circuit wiring diagram, so in this blog post we will focus on:
- Understanding how W5500 works with ESP32
- Network configuration
- Running a web server
- Controlling a relay on GPIO 25
Why Use W5500 Ethernet Module with ESP32?
Using W5500 with ESP32 has many advantages compared to WiFi-based projects:
- No WiFi disconnection issues
- Stable communication for 24×7 systems
- Low latency response
- Better security in LAN networks
- Suitable for industrial and commercial projects
If you are building production-level IoT systems, Ethernet is always a reliable choice.
Hardware Used
For this project, I am using:
- ESP32 (38-Pin Development Board)
- W5500 Ethernet Module
- Relay Module
- Ethernet Cable
- Router / LAN Network
- Power Supply
⚠️ Circuit diagram and wiring connections are already designed separately and are not repeated here.
Edit this project interactively in Cirkit Designer.
ESP32 (38-Pin) and W5500 SPI Pins
The ESP32 communicates with the W5500 module using SPI protocol.
Below are the SPI pin definitions used in this project:
#define W5500_CS 5
#define W5500_SCK 18
#define W5500_MISO 19
#define W5500_MOSI 23
These pins work perfectly with ESP32 38-pin boards and are commonly used for SPI communication.
Relay Connection (GPIO 25)
In this project:
- The relay control pin is connected to GPIO 25
- GPIO 25 is configured as an OUTPUT
- Relay logic:
HIGH→ Relay ONLOW→ Relay OFF
You can use this relay to control:
- Lights
- Fans
- AC appliances
- Motors (with proper relay & isolation)
How the Project Works (Simple Explanation)
- ESP32 starts and initializes the W5500 Ethernet module.
- A static IP address is assigned to the ESP32.
- ESP32 runs a web server on port 80.
- When you open the IP address in a browser:
- A web page loads
- You see ON and OFF buttons
- Clicking the buttons sends HTTP requests:
/on→ Turns relay ON/off→ Turns relay OFF
- Relay state updates instantly on the web page.
Everything works inside your local network, no internet required.
Network Configuration Used
You can modify these values based on your network:
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x01 };
IPAddress ip(192, 168, 1, 210);
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 255, 0);
After uploading the code, open this in your browser:
http://192.168.1.210/
Complete ESP32 + W5500 Web Server Code (Relay on Pin 25)
Below is the complete working code for this project:
#include <SPI.h>
#include <EthernetESP32.h>
/* ==================== W5500 SPI PINS ==================== */
#define W5500_CS 5
#define W5500_SCK 18
#define W5500_MISO 19
#define W5500_MOSI 23
/* ==================== RELAY ==================== */
#define RELAY_PIN 25
/* ==================== ETHERNET ==================== */
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x01 };
IPAddress ip(192, 168, 1, 210);
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 255, 0);
/* ==================== DRIVER & SERVER ==================== */
W5500Driver ethDriver(W5500_CS);
EthernetServer server(80);
/* ==================== GLOBAL ==================== */
bool relayState = false;
/* ==================== HTML PAGE ==================== */
String htmlPage() {
return R"rawliteral(
<!DOCTYPE html>
<html>
<head>
<title>ESP32 Ethernet Relay</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body { font-family: Arial; text-align: center; background:#111; color:#0f0; }
button { padding: 20px 40px; font-size: 22px; margin: 15px; }
.on { background: #00ff00; }
.off { background: #ff0033; }
</style>
</head>
<body>
<h1>ESP32 + W5500 Relay Control</h1>
<p>Status: <b>%STATE%</b></p>
<a href="/on"><button class="on">ON</button></a>
<a href="/off"><button class="off">OFF</button></a>
</body>
</html>
)rawliteral";
}
void setup() {
Serial.begin(115200);
pinMode(RELAY_PIN, OUTPUT);
digitalWrite(RELAY_PIN, LOW);
SPI.begin(W5500_SCK, W5500_MISO, W5500_MOSI, W5500_CS);
Ethernet.init(ethDriver);
Ethernet.begin(mac, ip, gateway, gateway, subnet);
server.begin();
}
void loop() {
EthernetClient client = server.available();
if (client) {
String req = "";
while (client.connected()) {
if (client.available()) {
char c = client.read();
req += c;
if (c == '\n') break;
}
}
if (req.indexOf("GET /on") >= 0) {
relayState = true;
digitalWrite(RELAY_PIN, HIGH);
}
if (req.indexOf("GET /off") >= 0) {
relayState = false;
digitalWrite(RELAY_PIN, LOW);
}
String page = htmlPage();
page.replace("%STATE%", relayState ? "ON" : "OFF");
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close");
client.println();
client.println(page);
client.stop();
}
}
Testing the Project
- Upload the code to ESP32
- Connect Ethernet cable
- Open Serial Monitor to confirm IP
- Open IP address in browser
- Click ON / OFF buttons
- Relay responds instantly
Real-World Applications
- Ethernet-based home automation
- Industrial relay control
- Smart distribution boards
- Secure LAN automation
- Factory control panels
Conclusion
This project demonstrates how to use the W5500 Ethernet module with an ESP32 38-pin board to create a reliable, offline web-controlled relay system.
If you want stability, speed, and security, Ethernet is the best choice.
