This post will tell you everything you need to know about MQTT communication which will enable you to use it communicate between devices. We add an LED to the Arduino Nano 33 IoT board and this LED is controlled remotely from a switch that is connected to a WeMos D1 mini board. All communication occurs through the MQTT broker which also communicates with Home Assistant.
Step 1: Watch the Video
A lot of effort has been put into making the video above as we felt that a video is the best way to understand a topic like this. Please take a moment to watch the video to get a better understanding of MQTT and how we will set up the broker, use it and so on.
Step 2: Install & Configure the MQTT Broker
As this involves several steps, it is advisable to watch the video to view how to set this up correctly.
Step 3: Download & Update the Sketches
As mentioned in the video, you can use the sketches linked below to test out your setup. The file below contains two sketches – one for the Arduino Nano 33 IoT board and the other for the WeMos D1 mini board.
You will need to add your WiFi network name, and password, along with the MQTT broker details. Please watch the video for more information.
Step 4: Wire the Boards, Upload & Test
Nano 33 IoT Wiring
First, connect an LED to the Arduino Nano 33 IoT board using the reference wiring shown in the image. Once done, you would need to do the following:
- Install the board support package by using the board manager. Search for “Nano 33 IoT”
- Install the WiFiNiNa library by using the library manager so that we can use the WiFi module. Search for “WiFiNiNa”
- Install the PubSubClient library by using the library manager as this is needed for MQTT communication. Search for “PubSubClient”
Then, select the correct board, COM port and upload the sketch. You can open the serial monitor with the baud rate of 115200 to view the board status.
WeMos D1 Mini Wiring
Next, connect a switch to the WeMos D1 mini board by using the reference wiring diagram. Once done, you need to do the following:
- Add the following URL to the preferences window so that we can install the board support package.
- Install the board support package by using the board manager. Search for “ESP8266”
Then, select the correct board along with the board settings as listed in the sketch. Upload the sketch and then open up the serial monitor with a baud of 115200 to view the board status.
The boards should connect to the MQTT broker and pressing the switch should allow you to control the LED remotely. The video shows you how you can test the setup.
Please do consider subscribing to our YouTube channel as it helps us create projects like these.
Thank you for reading!