---
title: "WizFi360 & Arduino Mega IoT Demo - MQTT"
url: "https://maker.wiznet.io/austin/projects/wizfi360-arduino-mega-iot-demo-mqtt/"
markdown_url: "https://maker.wiznet.io/austin/projects/wizfi360-arduino-mega-iot-demo-mqtt/md"
type: "UCC: User Created Content"
author: "austin"
original_author: "Austin"
original_url: "https://github.com/Wiznet/WizFi360_arduino_library"
published: "2022-12-15"
language: "en"
hardware: ["WIZnet WizFi360-EVB-Shield", "Arduino Mega 2560"]
likes: 4
views: 908
comments: 0
source: "WIZnet Makers (https://maker.wiznet.io/)"
---

# WizFi360 & Arduino Mega IoT Demo - MQTT

> Introduces how to use MQTT with WizFi360-EVB-Shield & Arduino Mega 2560

Original author: Austin (source: https://github.com/Wiznet/WizFi360_arduino_library)

## Components

- **WIZnet WizFi360-EVB-Shield** x 1 ([docs](https://docs.wiznet.io/Product/Wi-Fi-Module/WizFi360/wizfi360_evb_shield))
- **Arduino Mega 2560** x 1 ([docs](https://www.farnell.com/datasheets/1674878.pdf?_ga=2.12759806.871556650.1519619484-654667508.1508905608&_gac=1.209399078.1518779130.EAIaIQobChMI97my66Sq2QIV77ftCh01kgA_EAMYASAAEgKPyvD_BwE))
- Software: **Arduino IDE** ([docs](https://www.arduino.cc/en/software))

## Documents and links

- [WizFi360_arduino_library](https://github.com/Wiznet/WizFi360_arduino_library) (code)
- [WizFi360-EVB-Shield](https://github.com/Wiznet/Hardware-Files-of-WIZnet/blob/master/07_WizFi_Module/WizFi360-EVB-Shield/WizFi360-EVB-Shield_V100/Schematic/WizFI360-EVB-Shield_SCH_V101.pdf) (schematics)

## Article

In this document I will provide instructions how to use **MQTT** with WIZnet's Wi-Fi product - **WizFi360-EVB-shield** and **Arduino Mega 2560**.

I used **WizFi360_arduino_library** provided by WIZnet.

- [WizFi360_arduino_library](https://github.com/Wiznet/WizFi360_arduino_library)

And for the MQTT test, the example below was used.

- [WizFi360_arduino_library/examples/MqttClient](https://github.com/Wiznet/WizFi360_arduino_library/tree/main/examples/MqttClient)

### **1. Development environment Preparation**

To use the WizFi360 Arduino library & examples, the development environment must be configured to use Arduino platform.

Please note that in this guide examples were configured and tested using **Arduino IDE** in **Windows** environment.

Before starting, download and install the Arduino IDE from the link below.

- [Arduino IDE](https://www.arduino.cc/en/software)

### **2. H/W Preparation**

① Combine WizFi360-EVB-Shield with Arduino Mega 2560.

② Setup DIP switch on WizFi360-EVB-Shield.

- SW1 : Off

- SW2 : Off

- SW3 : On

③ Connect WizFi360-EVB-Shield and Arduino Mega 2560 with jumper cable.

- WizFi360-EVB-Shield : D7 - Arduino Mega 2560 : 18

- WizFi360-EVB-Shield : D6 - Arduino Mega 2560 : 19

![Connect WizFi360-EVB-Shield and Arduino Mega 2560 with jumper cable](https://hackster.imgix.net/uploads/attachments/1536926/image_PVeHbDAKBL.png?auto=compress%2Cformat&w=740&h=555&fit=max)

Connect WizFi360-EVB-Shield and Arduino Mega 2560 with jumper cable

④ Connect Arduino Mega 2560 to desktop or laptop using USB type B cable.

### **3. S/W Preparation**

The following Mosquitto to use as MQTT broker and serial terminal program are required for example test.

Serial terminal program is okay to use whatever you prefer.

Download and install from below link.

- [Mosquitto](https://mosquitto.org/download/)

- [Tera Term](https://osdn.net/projects/ttssh2/releases/)

### **4. Example Settings**

To test the MQTT example, minor settings shall be done in code.

① Setup device setting according to device you use.

Serial port configuration is different depending on the board used.

- Arduino Mega 2560 : ARDUINO_MEGA_2560

- WizFi360-EVB-Pico : WIZFI360_EVB_PICO

Set it to **ARDUINO_MEGA_2560** because it uses **Arduino Mega 2560**.

```plaintext
// setup according to the device you use
#define ARDUINO_MEGA_2560
```

![Setup device setting](https://hackster.imgix.net/uploads/attachments/1536971/image_LC2Z8bZh36.png?auto=compress%2Cformat&w=740&h=555&fit=max)

Setup device setting

② Setup Wi-Fi configuration.

```plaintext
/* Wi-Fi info */
char ssid[] = "wiznet";       // your network SSID (name)
char pass[] = "0123456789";   // your network password
```

![Setup Wi-Fi configuration](https://hackster.imgix.net/uploads/attachments/1536972/image_kO4OW4X0OW.png?auto=compress%2Cformat&w=740&h=555&fit=max)

Setup Wi-Fi configuration

③ Setup broker IP.

```plaintext
// Note: Local domain names (e.g. "Computer.local" on OSX) are not supported
// by Arduino. You need to set the IP address directly.
char broker[] = "xxx.xxx.xxx.xxx";
```

![Setup broker IP](https://hackster.imgix.net/uploads/attachments/1536983/image_WHldy26p3X.png?auto=compress%2Cformat&w=740&h=555&fit=max)

Setup broker IP

### **5. Example Build & Upload**

① After completing the configuration, click Verify button.

![Click Verify button](https://hackster.imgix.net/uploads/attachments/1537023/image_CDGrQEc0XR.png?auto=compress%2Cformat&w=740&h=555&fit=max)

Click Verify button

② When the build is completed, click Upload button to upload the firmware to Arduino Mega 2560.

![Click Upload button](https://hackster.imgix.net/uploads/attachments/1537024/image_AiuTCDYHdt.png?auto=compress%2Cformat&w=740&h=555&fit=max)

Click Upload button

### **6. Running Example**

① Connect to the serial COM port of Arduino Mega 2560 with Tera Term.

![Serial COM port configuration](https://hackster.imgix.net/uploads/attachments/1536995/image_Rn1SGIrvqg.png?auto=compress%2Cformat&w=740&h=555&fit=max)

Serial COM port configuration

② If the MQTT example works normally on Arduino Mega 2560, you can see the Wi-Fi connection log, information such as IP address, RSSI, etc... and connecting to broker.

![Arduino Mega 2560 log](https://hackster.imgix.net/uploads/attachments/1537026/image_uUlb6HmyVq.png?auto=compress%2Cformat&w=740&h=555&fit=max)

Arduino Mega 2560 log

![Broker log](https://hackster.imgix.net/uploads/attachments/1536999/image_gflgemhtnC.png?auto=compress%2Cformat&w=740&h=555&fit=max)

Broker log

③ You can see that the subscriber receives the message that Arduino Mega 2560 sends every 10 seconds.

![Subscriber receiving messages sent by Arduino Mega 2560](https://hackster.imgix.net/uploads/attachments/1537018/image_1mGUpmzWNz.png?auto=compress%2Cformat&w=740&h=555&fit=max)

Subscriber receiving messages sent by Arduino Mega 2560

④ If you send a message from the publisher, you can see that Arduino Mega 2560 receives it.

![Publisher sending messages](https://hackster.imgix.net/uploads/attachments/1537019/image_mWUaioCyL4.png?auto=compress%2Cformat&w=740&h=555&fit=max)

Publisher sending messages

![Arduino Mega 2560 receiving messages sent by the publisher](https://hackster.imgix.net/uploads/attachments/1537027/image_b89QkqKxPG.png?auto=compress%2Cformat&w=740&h=555&fit=max)

Arduino Mega 2560 receiving messages sent by the publisher

---

Source: https://maker.wiznet.io/austin/projects/wizfi360-arduino-mega-iot-demo-mqtt/
