When MQTT Refused to Work
- ceceliazhen
- Jun 11
- 2 min read
Recently I upgraded one of my ESP32 robotics exercises in Wokwi by adding MQTT communication, a PCA9685 servo driver, and a small LED warning system. I originally thought it would be a fairly straightforward “remote servo control” project. It turned out to be much more chaotic than expected in a good way.
The biggest problem was simple: MQTT did not work.
The ESP32 connected to WiFi perfectly fine, but nothing appeared in the MQTT broker. The servo ignored commands, sensor data refused to publish correctly, and sometimes the board just kept reconnecting endlessly without giving a useful error message. For a while I assumed I had wired something incorrectly, only to slowly realize most of the problems were happening between communication timing, sensor reading, and servo control all competing with each other.
What surprised me most was that every individual part technically worked on its own:
the MPU6050 returned values
the ultrasonic sensor measured distance
the servo moved
MQTT connected occasionally
But once everything started running together simultaneously, tiny timing problems suddenly mattered.
Later I upgraded the system further by replacing the direct ESP32 servo control with a PCA9685 module. Instead of having the ESP32 generate PWM signals directly, the PCA9685 handled the servo timing separately through I2C communication. Almost immediately, the servo became smoother and the MQTT communication stabilized much more consistently.
I also added a small red warning LED that turns on whenever the system detects dangerous conditions such as excessive tilt, close obstacles, high pressure, heavy weight, or when the robot is stopped. The warning state is also published through MQTT, so the robot can now report its own “stress state” remotely.
At some point during debugging, the project stopped feeling like a simple microcontroller exercise and started feeling more like a tiny nervous system:
sensors collecting information
MQTT handling communication
feedback logic reacting to motion
external controllers managing actuators
warning signals responding to environmental changes

I think this was one of the first robotics exercises where I genuinely understood that robots are rarely built from perfectly working parts. Most of the work is actually about making many imperfect systems cooperate together at the same time.
Here is my little video:



Comments