Step-by-Step Guide to Remote LED Control with ESP32C3

To avoid missing my updates, remember to check the public account in the upper right corner and set it to a star mark, and send me a star.

Step-by-Step Guide to Remote LED Control with ESP32C3
Step-by-Step Guide to Remote LED Control with ESP32C3
This article is the 5th in the series of practical IoT projects, and we finally arrive at the practical stage, starting with a demonstration of remote LED control.
Summary of Practical IoT Projects Series:
First article: Choosing a cloud server and how to get it for free
Second article: Connecting the ESP-12F module to the MQTT message server
Third article: Overview of 6 commonly used wireless communication modules in IoT

Fourth article: An introduction to network devices in IoT

The Practical Work Begins

In previous tutorials, we introduced the setup of an MQTT message server based on a cloud server, tested the communication of ESP series modules with the MQTT message server, common IoT modules, and IoT testing devices. In this section, we will complete a practical task using the ESP32C3 module, connecting it to the MQTT message server, and then using an MQTT debugger to remotely light up an LED. After completing this section, we can design our own smart light. Although it is just a lighting program, the implementation method is different from the traditional WiFi direct connection or Bluetooth direct connection methods.
Next, we will not discuss specific code yet, but first demonstrate the operation method and implementation means of the demo. The ESP32C3 module has already downloaded the demo program by default.
First, we need to prepare the hardware. Here, I prepared 2 ESP32C3 modules, 1 power supply, and a wireless router for the demonstration.

Step-by-Step Guide to Remote LED Control with ESP32C3

Preparing the test hardware environment
Then, connect the module power supply. I configured the program to automatically connect to WiFi upon power up, and after powering up, the power indicator light is normal, indicating that the module is powered properly.

Step-by-Step Guide to Remote LED Control with ESP32C3

Connecting the module power supply
Enter the router management interface, and you can see that ESP32C3_Node1 and ESP32C3_Node2 have connected successfully.

Step-by-Step Guide to Remote LED Control with ESP32C3

Check whether WiFi is connected successfully
Next, enter the EMQX control panel, where we can see that ESP32C3_Node1 and ESP32C3_Node2 are both connected successfully, with a heartbeat time of 15S.

Step-by-Step Guide to Remote LED Control with ESP32C3

Check if the ESP32C3 module is connected to the MQTT message server
Next, we will use the MQTT testing tool to check if the module control is normal. There are many MQTT testing tools available; on PC, we can use MQTTX. Here, for convenience, I choose to use the MQTT debugger on Android. Similarly, connect the MQTT debugger to my MQTT message server. For testing convenience, I set some shortcut commands in the MQTT debugger. The subscription message for ESP32C3_Node1 is esp32c3/test01, and for ESP32C3_Node2, it is esp32c3/test02. The ESP32C3 module has an integrated RGB LED, allowing us to control the RGB color through different control commands. I defined some character commands: Q to turn off the LED, R to set RGB to red, G to set RGB to green, and B to set RGB to blue.

Step-by-Step Guide to Remote LED Control with ESP32C3

Mobile MQTT debugger connected successfully

Step-by-Step Guide to Remote LED Control with ESP32C3

Mobile MQTT debugger online
Using the MQTT debugger, we can independently control the RGB colors of the two modules through the defined control commands. Below is the actual control effect, and when sending control commands, we can see the messages coming in and out on the EMQX message monitoring interface.

Step-by-Step Guide to Remote LED Control with ESP32C3

ControllingNode1‘slight

Step-by-Step Guide to Remote LED Control with ESP32C3

Independently controlling Node1 and Node2’s lights

Step-by-Step Guide to Remote LED Control with ESP32C3

EMQX message monitoring
The demonstration of the operation method and implementation means of the demo ends here. Next, let’s take a look at some of its code to understand its implementation principles. Here, we will use Arduino 1.8 for code editing and uploading, taking the ESP32C3_Node2 code as an example.
First, we will import the WiFi and PubSubClient libraries. The ESP8266WiFi library allows the ESP32 to connect to the Wi-Fi network, and the PubSubClient library enables the ESP32C3 to connect to the MQTT server to publish messages and subscribe to topics.
Set the Wi-Fi name and password, as well as the MQTT server connection address and port, and set the topic to “esp32c3/test02”.
Step-by-Step Guide to Remote LED Control with ESP32C3

Code snippet

Use PubSubClient to connect to your own MQTT Broker. After successfully connecting to the MQTT server, the ESP32C3 will publish messages to the MQTT server at esp32c3/test02 and subscribe to the esp32c3/test02 topic messages.
Step-by-Step Guide to Remote LED Control with ESP32C3

Code snippet

Set up a callback function to print the topic name to the serial port and print the messages received from the esp32c3/test02 topic. Here, I defined some character commands: Q to turn off the LED, R to set RGB to red, G to set RGB to green, and B to set RGB to blue.
Step-by-Step Guide to Remote LED Control with ESP32C3

Code snippet

After completing the code, download the program to the module for execution. In the menu bar, select the development board as ESP32C3, and set the serial port according to the serial number displayed on your computer.

Step-by-Step Guide to Remote LED Control with ESP32C3

Program download configuration

Step-by-Step Guide to Remote LED Control with ESP32C3

Program upload completed
It is also important to note that some friends cannot find the ESP development board. You need to add it manually. First, add the URL in preferences, and then you can select it in the board manager.

Step-by-Step Guide to Remote LED Control with ESP32C3

Development board management
Alright, this practical session ends here. If you have modules in hand, you can experiment with this. This practice is just a small introductory project. Based on MQTT and the ESP32 series modules, many fun projects can still be done, and I will continue to work on interesting projects in the future.
END
Step-by-Step Guide to Remote LED Control with ESP32C3
Recommended Reading:

Project Sharing | Electric Competition Series | Artificial Intelligence | Postgraduate Entrance Examination

Essential Knowledge Points | Graduation Design | Switch Power Supply | Job Seeking

We are Nimo, the founder of Darwin, who only talks about technology and does not flirt. Darwin is an online education platform aimed at serving professionals in the electronics industry, providing skill training videos covering popular topics in various sub-fields, such as embedded systems, FPGA, artificial intelligence, etc. We tailor learning content for different groups, such as common knowledge points, disassembly assessments, electric competitions/smart cars/postgraduate entrance exams, etc. Welcome to follow us.

Official website: www.darwinlearns.com
Bilibili: Darwin
QQ Group: Group 1: 786258064 (full)
Group 2: 1057755357 (full)
Group 3: 871373286Step-by-Step Guide to Remote LED Control with ESP32C3

Leave a Comment

Your email address will not be published. Required fields are marked *