Wiznet makers


Published November 01, 2022 ©

75 UCC

18 WCC

35 VAR

0 Contests


0 Following

Original Link


Let's try MQTT communication with Arduino using WIZnet's W5500 .

COMPONENTS Hardware components

WIZnet - W5500

x 1

Arduino - Arduino UNO

x 1

Software Apps and online services

Arduino - Arduino IDE

x 1


1. Prepare

Purchase W5500 on Aliexpress etc.

1pcs USR ES1 W5500 Chip New SPI LAN Ethernet Convert TCPIP Mod - AliExpress.com | Integrated Circuits - AliExpress



very compact


Arduino uses UNO R3.

2. Connection

To communicate with Arduino via SPI, connect the W5500 as follows. The IO level is 3.3V, but it is also 5V tolerant, so it can be directly connected to Arduino . Another point to note is that the current consumption of the W5500 is large, so the 3.3V is supplied externally instead of from the Arduino .

W5500 | WIZnet Co., Ltd.



Connection diagram


D10 (SS)CS

According to the data sheet, it consumes 132mA at 100M Transmitting, so it is better to prepare an external power supply that can supply 200mA or more.

products:w5500:datasheet [Document Wiki]



Current consumption of W5500 (Excerpt from data sheet)




W5500 module pinout


[Caution] When connecting with a breadboard, keep the wires as short as possible. If the wire is long, the communication will be unstable.

3. Library installation

When using W5500 , unlike ENC28J60, you can control the module with the standard Ethernet library , so install only PubSubClient that handles the MQTT part.


The library can be searched by name from the library manager of the Arduino IDE and installed.


4. Code

Write the following code to Arduino .

#include <Ethernet.h>
#include <PubSubClient.h>

byte mac[] = { 0x70, 0x69, 0x69, 0x2D, 0x30, 0x31 };
byte server[] = { 10, 0, 1, 5 };

void callback(char* topic, byte* payload, unsigned int length) {
  payload[length] = '\0';
  String msg = String((char*) payload);

EthernetClient ethClient;
PubSubClient client(server, 1883, callback, ethClient);

void reconnect() {
  while (!client.connected()) {
    Serial.println("Attempting MQTT connection...");
    if (client.connect("myClient")) {
      Serial.println("MQTT PubSub Ready");
      client.publish("output", "ready");
      Serial.println("subscribe input");
    } else {
      Serial.println("MQTT PubSub failer");
      Serial.println("try again in 2 seconds");

void setup() {
  Ethernet.init(10);// CS pin 10

  // Check for Ethernet hardware present
  if (Ethernet.hardwareStatus() == EthernetNoHardware) {
    Serial.println("Ethernet shield was not found.  Sorry, can't run without hardware. :(");
    while (true) {
      delay(1); // do nothing, no point running without Ethernet hardware
  if (Ethernet.linkStatus() == LinkOFF) {
    Serial.println("Ethernet cable is not connected.");

  Serial.print("IP: ");

void loop() {
  if (!client.connected()) {

PubSubClient also has API documentation.

Arduino Client for MQTT

Change the MAC address and server address according to your environment. The server address is the address of MQTT Broker, and MQTT Broker is required to check the operation. The easiest and recommended way to build MQTT Broker is to install mosqitto on Raspberry Pi .

5. Run

After confirming that the MQTT Broker is working, check the log on the serial monitor connected to the Arduino . If everything works fine, you should see something like this:


When you install mosquitto, PubSub client is installed in addition to Broker, so let's check the operation by launching terminals for Publish (Pub) and Subscribe (Sub).



Subscribe screen


Subscribe to topic output. You can confirm that ready is sent when Arduino starts up. If you miss it , reset the Arduino and it will be sent again.



Publish screen


If you send a message (payload) to the input topic, you can check the reception on the Arduino 's serial monitor.

6. Summary

In this blog, I have introduced that TCP and UDP communication is possible even with weak microcomputers by using W5500 and ENC28J60 . Recently, with the advent of ESP8266 and ESP32 equipped with Wi-Fi , it has become possible to easily create IoT devices by themselves. I think there are situations where you want it.

When communicating with a microcomputer , it would be nice to be able to select wired, wireless, and protocols in consideration of cost, application, usage environment, etc.

Comments Write