ESP32 S3 UNO - MQTT

This ESP32 S3 Uno MQTT tutorial shows you how to connect the ESP32 S3 Uno form board to an MQTT broker over WiFi. You will publish JSON messages to a topic and subscribe to a topic to get messages back. You will try two brokers: the free online Mosquitto test server, and a Mosquitto broker that runs on your own PC.

In this tutorial, you will:

  1. Connect the ESP32 S3 Uno to an online MQTT broker
  2. Publish data to an MQTT topic with the MQTT library
  3. Subscribe to a topic and print the received messages
  4. Install and run the Mosquitto broker on a Windows PC
  5. Send messages between your PC and the board in both directions
ESP32 S3 Uno MQTT

Hardware Preparation

1×ESP32 S3 Uno-form Board
1×USB Cable Type-A to Type-C (for USB-A PC)
1×USB Cable Type-C to Type-C (for USB-C PC)

Or you can buy the following kits:

1×DIYables Sensor Kit (18 sensors/displays)
Disclosure: Some of the links provided in this section are Amazon affiliate links. We may receive a commission for any purchases made through these links at no additional cost to you.
Additionally, some of these links are for products from our own brand, DIYables .

Overview of ESP32 S3 Uno and MQTT

MQTT is the most common way for small IoT boards to talk to each other and to the cloud. It is light, fast, and easy to use. Once you know the basics, you can plug your ESP32 S3 Uno into dashboards, home automation systems, and cloud services.

MQTT (Message Queuing Telemetry Transport) is a small publish/subscribe protocol. It was made for devices with little memory and for slow or unstable networks. The ESP32 S3 Uno joins a broker as a client. It can send data to topics and listen to topics at the same time.

The broker (also called the MQTT server) can run in many places. It can be an online service such as Mosquitto or AWS IoT. It can be a program on your computer, such as Mosquitto or HiveMQ. It can also run on a Raspberry Pi, or on a cloud server such as AWS EC2.

Key Concepts

The broker is the central server. It passes messages from one client to another.

A topic is a text string that names a channel, for example esp32-s3-uno-001/send. The broker uses it to decide who gets each message.

To publish means to send a message to a topic. To subscribe means to tell the broker "send me every message on this topic".

In this guide, you first test the board with an online Mosquitto broker. Then you install Mosquitto on your PC and use it as a local broker.

ESP32 S3 Uno Pinout

The image below shows the pinout diagram of the ESP32 S3 Uno form board. This project needs no wiring, but the sample code reads the A0 pin (GPIO2) as test data, so you can use this image to find it if you want to connect a sensor later.

ESP32 S3 Uno pinout diagram

Connect ESP32 S3 Uno to an Online MQTT Broker

The fastest way to test MQTT is a public broker, because you do not need to install anything. Here you will use test.mosquitto.org, a free broker from the Mosquitto project. It is only for testing, so do not use it for real products.

ESP32 S3 Uno Code

This sketch joins your WiFi network, connects to the online broker, and subscribes to a loopback topic. Every 5 seconds it publishes a small JSON message to the same topic, so you see each message go out and come back.

/* * This ESP32 S3 Uno code was developed by newbiely.com * * This ESP32 S3 Uno code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/esp32-s3-uno/esp32-s3-uno-mqtt */ #include <WiFi.h> #include <MQTTClient.h> #include <ArduinoJson.h> const char WIFI_SSID[] = "YOUR_WIFI_SSID"; // CHANGE TO YOUR WIFI SSID const char WIFI_PASSWORD[] = "YOUR_WIFI_PASSWORD"; // CHANGE TO YOUR WIFI PASSWORD const char MQTT_BROKER_ADRRESS[] = "test.mosquitto.org"; // CHANGE TO MQTT BROKER'S ADDRESS const int MQTT_PORT = 1883; const char MQTT_CLIENT_ID[] = "YOUR-NAME-esp32-s3-uno-001"; // CHANGE IT AS YOU DESIRE const char MQTT_USERNAME[] = ""; // CHANGE IT IF REQUIRED, empty if not required const char MQTT_PASSWORD[] = ""; // CHANGE IT IF REQUIRED, empty if not required // The MQTT topics that ESP32 S3 Uno should publish/subscribe const char PUBLISH_TOPIC[] = "YOUR-NAME-esp32-s3-uno-001/loopback"; // CHANGE IT AS YOU DESIRE const char SUBSCRIBE_TOPIC[] = "YOUR-NAME-esp32-s3-uno-001/loopback"; // CHANGE IT AS YOU DESIRE const int PUBLISH_INTERVAL = 5000; // 5 seconds WiFiClient network; MQTTClient mqtt = MQTTClient(256); unsigned long lastPublishTime = 0; void setup() { Serial.begin(9600); // set the ADC attenuation to 11 dB (up to ~3.3V input) analogSetAttenuation(ADC_11db); WiFi.mode(WIFI_STA); WiFi.begin(WIFI_SSID, WIFI_PASSWORD); Serial.println("ESP32 S3 Uno - Connecting to Wi-Fi"); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(); connectToMQTT(); } void loop() { mqtt.loop(); if (millis() - lastPublishTime > PUBLISH_INTERVAL) { sendToMQTT(); lastPublishTime = millis(); } } void connectToMQTT() { // Connect to the MQTT broker mqtt.begin(MQTT_BROKER_ADRRESS, MQTT_PORT, network); // Create a handler for incoming messages mqtt.onMessage(messageHandler); Serial.print("ESP32 S3 Uno - Connecting to MQTT broker"); while (!mqtt.connect(MQTT_CLIENT_ID, MQTT_USERNAME, MQTT_PASSWORD)) { Serial.print("."); delay(100); } Serial.println(); if (!mqtt.connected()) { Serial.println("ESP32 S3 Uno - MQTT broker Timeout!"); return; } // Subscribe to a topic, the incoming messages are processed by messageHandler() function if (mqtt.subscribe(SUBSCRIBE_TOPIC)) Serial.print("ESP32 S3 Uno - Subscribed to the topic: "); else Serial.print("ESP32 S3 Uno - Failed to subscribe to the topic: "); Serial.println(SUBSCRIBE_TOPIC); Serial.println("ESP32 S3 Uno - MQTT broker Connected!"); } void sendToMQTT() { StaticJsonDocument<200> message; message["timestamp"] = millis(); message["data"] = analogRead(2); // A0 (GPIO2). Or you can read data from other sensors char messageBuffer[512]; serializeJson(message, messageBuffer); mqtt.publish(PUBLISH_TOPIC, messageBuffer); Serial.println("ESP32 S3 Uno - sent to MQTT:"); Serial.print("- topic: "); Serial.println(PUBLISH_TOPIC); Serial.print("- payload:"); Serial.println(messageBuffer); } void messageHandler(String &topic, String &payload) { Serial.println("ESP32 S3 Uno - received from MQTT:"); Serial.println("- topic: " + topic); Serial.println("- payload:"); Serial.println(payload); }

The JSON message holds the time (millis()) and the value read from A0 (GPIO2). The sketch calls analogSetAttenuation(ADC_11db) in setup(). By default, the ESP32 S3 Uno ADC can only measure a small voltage. With 11 dB attenuation, the analog pin reads the full range from 0V up to about 3.3V, so the value goes from 0 to 4095 and does not hit 4095 too early.

Detailed Instructions

  1. New to the ESP32 S3 Uno? Follow ESP32 S3 Uno - Getting Started first.
  2. Connect the board to your computer with a USB Type-C cable.
  3. Open Arduino IDE, choose the ESP32S3 Dev Module board and the correct COM port.
  4. Open the Library Manager by clicking the Library Manager icon on the left side of Arduino IDE.
  5. Find the MQTT library: type MQTT in the search box and look for the MQTT library by Joel Gaehwiler.
  6. Install it by clicking Install.
  • Search for MQTT created by Joel Gaehwiler and click the Install button.
∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
ESP32S3 Dev Module
Library Manager
Type:
All
Topic:
All
MQTT by Joel Gaehwiler
This library bundles the lwmqtt client and adds a thin wrapper to get an Arduino like API. More info
2.5.2
INSTALL
Newbiely.ino
···
1 void setup() {
Output
Serial Monitor
Ln 1, Col 1
ESP32S3 Dev Module on COM15
1
  1. Find the JSON library: type ArduinoJson in the search box and look for the ArduinoJson library by Benoit Blanchon.
  2. Install it by clicking Install.
  • Search for ArduinoJson created by Benoit Blanchon and click the Install button.
∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
ESP32S3 Dev Module
Library Manager
Type:
All
Topic:
All
ArduinoJson by Benoit Blanchon
⭐ 6953 stars on GitHub! Supports serialization, deserialization, MessagePack, streams, filtering, and more. Fully tested and documented. More info
7.4.2
INSTALL
Newbiely.ino
···
1 void setup() {
Output
Serial Monitor
Ln 1, Col 1
ESP32S3 Dev Module on COM15
1
  1. Copy the code above and open it in Arduino IDE.
  2. Set your WiFi: replace YOUR_WIFI_SSID and YOUR_WIFI_PASSWORD with your own network name and password.
  3. Make the names unique: the code has YOUR-NAME three times. Change it to your name or some random letters (no spaces). Many people test with the same public broker, so the client ID and topic must be unique.
  4. Upload the code by clicking Upload in Arduino IDE.
  5. Open the Serial Monitor and set it to 9600 baud.
  6. Tip: If the board never connects to the broker, check your WiFi details and make sure your network does not block port 1883.

Serial Monitor Output

After the board connects, you will see each message being sent and then received again:

∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
ESP32S3 Dev Module
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'ESP32S3 Dev Module' on 'COM15')
New Line
9600 baud
ESP32 S3 Uno - Connecting to Wi-Fi ...... ESP32 S3 Uno - Connecting to MQTT broker ESP32 S3 Uno - Subscribed to the topic: YOUR-NAME-esp32-s3-uno-001/loopback ESP32 S3 Uno - MQTT broker Connected! ESP32 S3 Uno - sent to MQTT: - topic: YOUR-NAME-esp32-s3-uno-001/loopback - payload:{"timestamp":10425,"data":1023} ESP32 S3 Uno - received from MQTT: - topic: YOUR-NAME-esp32-s3-uno-001/loopback - payload: {"timestamp":10425,"data":1023} ESP32 S3 Uno - sent to MQTT: - topic: YOUR-NAME-esp32-s3-uno-001/loopback - payload:{"timestamp":15426,"data":1047} ESP32 S3 Uno - received from MQTT: - topic: YOUR-NAME-esp32-s3-uno-001/loopback - payload: {"timestamp":15426,"data":1047}
Ln 11, Col 1
ESP32S3 Dev Module on COM15
2

The board gets back every message it sends. This is because it subscribes to the same topic that it publishes to. If you do not want this, use one topic for publishing and a different topic for subscribing.

Connect ESP32 S3 Uno to the MQTT Broker Installed on Your PC

A local broker gives you full control. It works without the internet, it is private, and you can watch every message on your PC. This part sets up Mosquitto on Windows and then connects the ESP32 S3 Uno to it.

Installing Mosquitto MQTT Broker

  1. Download the Mosquitto MQTT Broker.
  2. Install it on the D: drive, not the C: drive. This avoids file permission problems.

Run Mosquitto MQTT Broker

First, start the broker and check that it runs.

  1. Go to the folder where you installed Mosquitto, for example D:\Draft\mosquitto.
  2. Make a new file named test.conf in that folder, paste the lines below into it, and save it.
listener 1883 allow_anonymous true
  1. Open a Command Prompt as Administrator. We call it the Broker Window. Keep it open until you finish the tutorial.
Windows command prompt administrator
  1. Run these commands one by one:
cd /d D:\Draft\mosquitto mosquitto -v -c test.conf
  1. The broker starts and shows this:
Command Prompt
Microsoft Windows [Version 10.0.19045.3930] (c) Microsoft Corporation. All rights reserved. C:\WINDOWS\system32>cd /d D:\Draft\mosquitto D:\Draft\mosquitto>mosquitto -v -c test.conf 1710918939: mosquitto version 2.0.18 starting 1710918939: Config loaded from test.conf. 1710918939: Opening ipv6 listen socket on port 1883. 1710918939: Opening ipv4 listen socket on port 1883. 1710918939: mosquitto version 2.0.18 running
  1. Open another Command Prompt as Administrator.
  2. Find your PC's IP address with this command:
ipconfig
Command Prompt
C:\WINDOWS\system32>ipconfig Windows IP Configuration Ethernet adapter: Subnet Mask . . . . . . . . . . . : 255.0.0.0 IPv4 Address. . . . . . . . . . . : 192.168.0.26 Subnet Mask . . . . . . . . . . . : 255.255.255.0 Default Gateway . . . . . . . . . :
  1. Write down the IP address. You need it later. In this example it is 192.168.0.26.

Test if the Mosquitto Broker Works

Before you add the board, check the broker with two more windows on your PC.

  1. Open another Command Prompt as Administrator. We call it the Subscriber Window.
  2. Subscribe to a topic with these commands (use your own IP address):
cd /d D:\Draft\mosquitto mosquitto_sub -h 192.168.0.26 -p 1883 -t esp32-s3-uno-001/send
  1. Open one more Command Prompt as Administrator. We call it the Publisher Window.
  2. Publish a message to the same topic with these commands (use your own IP address):
cd /d D:\Draft\mosquitto mosquitto_pub -h 192.168.0.26 -p 1883 -t esp32-s3-uno-001/send -m "Hello, MQTT!"
  1. The Publisher Window shows:
Command Prompt
Microsoft Windows [Version 10.0.19045.3930] (c) Microsoft Corporation. All rights reserved. C:\WINDOWS\system32>cd /d D:\Draft\mosquitto D:\Draft\mosquitto>mosquitto_pub -h 192.168.0.26 -p 1883 -t esp32-s3-uno-001/send -m "Hello, MQTT!" D:\Draft\mosquitto>

The broker passes the message on, and it appears in the Subscriber Window:

Command Prompt
Microsoft Windows [Version 10.0.19045.3930] (c) Microsoft Corporation. All rights reserved. C:\WINDOWS\system32>cd /d D:\Draft\mosquitto D:\Draft\mosquitto>mosquitto_sub -h 192.168.0.26 -p 1883 -t esp32-s3-uno-001/send Hello, MQTT!

Your local Mosquitto broker works. Do NOT close the three windows: Broker Window, Subscriber Window and Publisher Window. You will use them in the next steps.

ESP32 S3 Uno Code

This sketch connects the ESP32 S3 Uno to the broker on your PC. It subscribes to the topic esp32-s3-uno-001/receive and publishes a JSON message to esp32-s3-uno-001/send every 5 seconds. Because the two topics are different, data flows both ways without the loopback.

/* * This ESP32 S3 Uno code was developed by newbiely.com * * This ESP32 S3 Uno code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/esp32-s3-uno/esp32-s3-uno-mqtt */ #include <WiFi.h> #include <MQTTClient.h> #include <ArduinoJson.h> #define CLIENT_ID "ESP32-S3-UNO-001" // CHANGE IT AS YOU DESIRE const char WIFI_SSID[] = "YOUR_WIFI_SSID"; // CHANGE TO YOUR WIFI SSID const char WIFI_PASSWORD[] = "YOUR_WIFI_PASSWORD"; // CHANGE TO YOUR WIFI PASSWORD const char MQTT_BROKER_ADRRESS[] = "192.168.0.26"; // CHANGE TO MQTT BROKER'S IP ADDRESS const int MQTT_PORT = 1883; const char MQTT_USERNAME[] = ""; // CHANGE IT IF REQUIRED const char MQTT_PASSWORD[] = ""; // CHANGE IT IF REQUIRED // The MQTT topics that this device should publish/subscribe #define PUBLISH_TOPIC "esp32-s3-uno-001/send" #define SUBSCRIBE_TOPIC "esp32-s3-uno-001/receive" #define PUBLISH_INTERVAL 5000 // 5 seconds WiFiClient network; MQTTClient mqtt = MQTTClient(256); unsigned long lastPublishTime = 0; void setup() { Serial.begin(9600); // set the ADC attenuation to 11 dB (up to ~3.3V input) analogSetAttenuation(ADC_11db); WiFi.mode(WIFI_STA); WiFi.begin(WIFI_SSID, WIFI_PASSWORD); Serial.println("ESP32 S3 Uno - Connecting to Wi-Fi"); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(); connectToMQTT(); } void loop() { mqtt.loop(); if (millis() - lastPublishTime > PUBLISH_INTERVAL) { sendToMQTT(); lastPublishTime = millis(); } } void connectToMQTT() { // Connect to the MQTT broker mqtt.begin(MQTT_BROKER_ADRRESS, MQTT_PORT, network); // Create a handler for incoming messages mqtt.onMessage(messageHandler); Serial.print("ESP32 S3 Uno - Connecting to MQTT broker"); while (!mqtt.connect(CLIENT_ID, MQTT_USERNAME, MQTT_PASSWORD)) { Serial.print("."); delay(100); } Serial.println(); if (!mqtt.connected()) { Serial.println("ESP32 S3 Uno - MQTT broker Timeout!"); return; } // Subscribe to a topic, the incoming messages are processed by messageHandler() function if (mqtt.subscribe(SUBSCRIBE_TOPIC)) Serial.print("ESP32 S3 Uno - Subscribed to the topic: "); else Serial.print("ESP32 S3 Uno - Failed to subscribe to the topic: "); Serial.println(SUBSCRIBE_TOPIC); Serial.println("ESP32 S3 Uno - MQTT broker Connected!"); } void sendToMQTT() { StaticJsonDocument<200> message; message["timestamp"] = millis(); message["data"] = analogRead(2); // A0 (GPIO2). Or you can read data from other sensors char messageBuffer[512]; serializeJson(message, messageBuffer); mqtt.publish(PUBLISH_TOPIC, messageBuffer); Serial.println("ESP32 S3 Uno - sent to MQTT:"); Serial.print("- topic: "); Serial.println(PUBLISH_TOPIC); Serial.print("- payload:"); Serial.println(messageBuffer); } void messageHandler(String &topic, String &payload) { Serial.println("ESP32 S3 Uno - received from MQTT:"); Serial.println("- topic: " + topic); Serial.println("- payload:"); Serial.println(payload); // You can process the incoming data as json object, then control something /* StaticJsonDocument<200> doc; deserializeJson(doc, payload); const char* message = doc["message"]; */ }

Like the first sketch, it reads A0 (GPIO2) as sample data and uses analogSetAttenuation(ADC_11db) so the reading covers 0V to about 3.3V (0 to 4095).

Detailed Instructions

  1. New to the ESP32 S3 Uno? Follow ESP32 S3 Uno - Getting Started first.
  2. Copy the code above and open it in Arduino IDE.
  3. Set your WiFi: replace YOUR_WIFI_SSID and YOUR_WIFI_PASSWORD with your own details.
  4. Set the broker address: change MQTT_BROKER_ADRRESS to your PC's IP address (or a domain name).
  5. Upload the code by clicking Upload in Arduino IDE.
  6. Tip: Your PC firewall must allow incoming connections on port 1883. If it blocks them, the board cannot reach the local broker.

Send Message from ESP32 S3 Uno to PC via MQTT

The board publishes to the topic esp32-s3-uno-001/send. The Subscriber Window on your PC listens to that topic, so it gets every message. Open the Serial Monitor to see the board send a message every few seconds:

∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
ESP32S3 Dev Module
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'ESP32S3 Dev Module' on 'COM15')
New Line
9600 baud
ESP32 S3 Uno - Connecting to Wi-Fi ..... ESP32 S3 Uno - Connecting to MQTT broker ESP32 S3 Uno - Subscribed to the topic: esp32-s3-uno-001/receive ESP32 S3 Uno - MQTT broker Connected! ESP32 S3 Uno - sent to MQTT: - topic: esp32-s3-uno-001/send - payload:{"timestamp":10612,"data":1245} ESP32 S3 Uno - sent to MQTT: - topic: esp32-s3-uno-001/send - payload:{"timestamp":15613,"data":1198} ESP32 S3 Uno - sent to MQTT: - topic: esp32-s3-uno-001/send - payload:{"timestamp":20614,"data":1163} ESP32 S3 Uno - sent to MQTT: - topic: esp32-s3-uno-001/send - payload:{"timestamp":25615,"data":1144}
Ln 11, Col 1
ESP32S3 Dev Module on COM15
2

Now look at the Subscriber Window. The same messages show up there:

Command Prompt
Microsoft Windows [Version 10.0.19045.3930] (c) Microsoft Corporation. All rights reserved. C:\WINDOWS\system32>cd /d D:\Draft\mosquitto D:\Draft\mosquitto>mosquitto_sub -h 192.168.0.26 -p 1883 -t esp32-s3-uno-001/send Hello, MQTT! {"timestamp":10612,"data":1245} {"timestamp":15613,"data":1198} {"timestamp":20614,"data":1163} {"timestamp":25615,"data":1144}

Send Message from PC to ESP32 S3 Uno via MQTT

The board subscribes to the topic esp32-s3-uno-001/receive. When the Publisher Window sends a message to that topic, the broker forwards it to the board.

  1. Run this command in the Publisher Window:
mosquitto_pub -h 192.168.0.26 -p 1883 -t esp32-s3-uno-001/receive -m "Hello, ESP32 S3 Uno!"
  1. The message appears on the Serial Monitor:
∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
ESP32S3 Dev Module
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'ESP32S3 Dev Module' on 'COM15')
New Line
9600 baud
ESP32 S3 Uno - received from MQTT: - topic: esp32-s3-uno-001/receive - payload: Hello, ESP32 S3 Uno!
Ln 11, Col 1
ESP32S3 Dev Module on COM15
2

Applications

MQTT with the ESP32 S3 Uno is the base of many IoT projects. Once the board can publish and subscribe, you only need to change what it sends and what it does with the messages it gets.

Remote Sensor Monitoring

Publish temperature, humidity or air quality readings to a dashboard such as Node-RED or Grafana.

Remote Device Control

Send commands from a phone app over MQTT to switch a relay, move a servo, or change LED colors.

Multi-Board Projects

Let several ESP32 S3 Uno boards share one broker, so they can work together, for example to turn on lights in many rooms at once.

Home Automation

Connect the board to Home Assistant or openHAB through MQTT and control your home with your own firmware.

Cloud Pipelines

Forward messages from a local broker to AWS IoT Core or Azure IoT Hub to store and analyze the data.

Alerts

Subscribe the board to a motion or water-leak topic and turn on a buzzer or relay when an alert arrives.

Video Tutorial

Watch the video below to see this ESP32 S3 Uno project step by step.

Challenges

These small tasks help you practice what you just learned. Start with the easy ones and move up.

  1. Beginner, change the publish interval: Make the board publish every 2 seconds instead of 5. Watch the faster messages in the Serial Monitor and the Subscriber Window.
  2. Beginner, add a second topic: Subscribe to another topic, such as esp32-s3-uno-001/config. Publish a value to it from the PC and print it on the Serial Monitor.
  3. Intermediate, send real sensor data: Connect a DHT22 sensor to the ESP32 S3 Uno and publish its temperature and humidity as JSON every 5 seconds.
  4. Intermediate, control an LED: Subscribe to esp32-s3-uno-001/led. Turn an external LED on D13 (GPIO12) on when the payload is "ON" and off when it is "OFF". Test it from the Publisher Window.
  5. Advanced, retained messages: Set the retain flag to true when you publish. Restart the board and see that it gets the last message right after it reconnects.
  6. Advanced, TLS: Give your local Mosquitto broker a self-signed TLS certificate. Change the code to connect on port 8883 with SSL, and check that plain connections are refused.

FAQ

Do I need any extra hardware to use MQTT on the ESP32 S3 Uno?

No. The ESP32 S3 Uno has WiFi built in, so the board and a USB Type-C cable are enough. You only need extra parts when you want to send real sensor data or control something.

Why does the code call analogSetAttenuation(ADC_11db)?

It sets the ESP32 S3 Uno ADC input range to about 0 to 3.3V, so the full signal maps to 0 to 4095. Without it, the range is smaller and readings reach 4095 too early. The UNO R4 does not need this line, because it is only for ESP32 boards. Keep any sensor output at 3.3V or less.

Why is the "data" value much bigger than on the UNO R4?

The ESP32 S3 Uno ADC is 12-bit, so analogRead() gives 0 to 4095 instead of 0 to 1023. Nothing is connected to A0 in this example, so the pin floats and the value moves around. Connect a sensor to A0 (GPIO2) to send real data.

Why does the code use analogRead(2) and not analogRead(0)?

On the ESP32 S3 Uno, the number in analogRead() is a GPIO number. The A0 header pin is GPIO2, so you write 2. GPIO0 is a boot pin and is not on the Uno headers.

Can I use a different MQTT library, such as PubSubClient?

Yes. PubSubClient also works with the ESP32 S3 Uno and the WiFi.h library. This tutorial uses the MQTT library by Joel Gaehwiler because its message handler is simple. The broker setup stays the same.

What if my project needs more pins than the Uno headers give?

The ESP32 S3 Uno has two extra rows of holes with more GPIOs: GPIO15 and GPIO16 (I/O, PWM, analog), GPIO45 and GPIO35 to GPIO42 (I/O, PWM), and GPIO47/GPIO48 (output only, PWM). Solder pin headers to use them and write the GPIO number in code. For an MQTT project, GPIO15/GPIO16 are good for extra analog sensors, and GPIO35 to GPIO42 are good for buttons or relays. Be careful with two groups. GPIO47 and GPIO48 may run at 1.8V instead of 3.3V on some modules (mostly ones with "V" in the name, like R8V or R16V), so 3.3V devices can be damaged or act strangely. GPIO0, GPIO3 (D6), GPIO45 and GPIO46 (D9) are boot strapping pins, and a wrong connection can stop the board from booting or uploading code. Use the other extra pins first.

Troubleshooting

Problem Possible Cause Solution
No COM port in Arduino IDE USB driver missing or board not in upload mode Install the CP210x or CH340 driver, try another cable, or hold BOOT while you press RESET
Board does not power on or keeps restarting Bad USB cable or weak USB port Use a data USB Type-C cable and plug it straight into the computer
Serial Monitor prints only dots after Connecting to Wi-Fi Wrong SSID or password, or a 5 GHz only network Check the WiFi details and use a 2.4 GHz network
Stuck at Connecting to MQTT broker Wrong broker address or port 1883 is blocked Check the address in the code and allow port 1883 on the network and the PC firewall
Messages from other people appear Topic name is not unique on the public broker Replace YOUR-NAME with your own unique text
Board disconnects again and again Two devices use the same client ID Give each board its own client ID
Compile error MQTTClient.h or ArduinoJson.h not found Library not installed Install the MQTT library by Joel Gaehwiler and ArduinoJson by Benoit Blanchon
Serial Monitor shows strange characters Baud rate does not match Set the Serial Monitor to 9600 baud

※ OUR MESSAGES

  • As freelancers, We are AVAILABLE for HIRE. See how to outsource your project to us
  • Please feel free to share the link of this tutorial. However, Please do not use our content on any other websites. We invested a lot of effort and time to create the content, please respect our work!