MQTT is an easy to use protocol that enables IoT devices to pass messages. In this project, I used the integrated WiFi capability of the RTL8195 Ameba-1 development board to send and receive MQTT messages and control a LED over the internet.
In this project I am using the Ameba-1 development board from Realtek, based on the RTL8195/RTL8710 soc, part of its AmebaIoT ecosystem. This board can be programmed using the Arduino IDE and is pin compatible with many sensors and expansion boards. It also has WiFi, NFC, and USB Host functionality as well, making it suitable for many IoT applications. Any other development boards capable of a WiFi connection can also be used, but the code will need to be changed.
To begin with, ensure that you have the Arduino IDE installed and configured for programming the Ameba-1 board. Instructions to do this can be found at https://www.amebaiot.com/en/ameba-arduino-getting-started/.
Next, connect the LED and push button to the board by following the wiring diagram in the youtube video here. The wiring for this project is rather straightforward, but make sure that you connect a resistor of at least 220 ohm between the LED and the board. This resistor is vital to protecting the LED from too much current, without it, the LED could burn out and fail.
Once the wiring is done, connect the board to the computer. Download the code provided at the GitHub link and open it in the Arduino IDE. Before you upload the code to the board, there are a few changes that need to be made to the code. Please make the following changes:
- Line 31 - enter the name of the WiFi network the board will connect to
- Line 32 - enter the corresponding password of the WiFi network
- Line 35 - enter the URL or IP address of the MQTT server to use. If you do not have your own server to use, you can choose to use the free server at test.mosquitto.org
Upload the code to the board once these changes are made.
On your Android/iOS mobile device, download and install a MQTT client from the app store if you do not have one already. Configure the app to use the same MQTT server, and subscribe to the outTopic. Push the push button and the Ameba-1 board will send a MQTT message with the current state of the LED. Publish either a '1' or '0' to the topic "inTopic", and the LED will turn on or off respectively once the message is received by the board.
MQTT provides a powerful and simple method to control and interact with IoT devices over the internet. This project can be used as a base for complicated systems, such as getting the temperature and humidity from a sensor, or controlling motors to move something.