Demo GIF
" data-cpx-injected="1"> ESP8266 MQTT Sensor Node — ESP32 & ESP8266 Build | CodeProven

ESP32 & ESP8266 Connectivity · Intermediate · MQTT

ESP8266 MQTT Sensor Node

A sensor that publishes to your own broker and subscribes to a command topic.

Firmware status: Generated from this project's own pin map and compiled with arduino-cli for esp8266:esp8266:nodemcuv2 before publication; bench validation on your hardware is still required..

Hardware scope

MQTT publish and subscribe, retained state, reconnect with backoff. Pins assigned by the generator: out 1 → GPIO5, sense → GPIOA0.

Components

  • ESP8266 board
  • Analog sensor on A0
  • LED or relay on a GPIO
  • Local MQTT broker (Mosquitto on any machine)

Tools

  • USB programming cable
  • Multimeter
  • Current-limited bench supply (for anything that switches a load)
  • Small screwdriver and wire cutters

Build steps

  1. Run a broker and confirm it is reachable from the network with a laptop client first.
  2. Set the broker address and flash. Watch the connect line and the subscribe acknowledgement.
  3. Publish `1` to `<prefix>/set` from the broker's own client and watch the output change.
  4. Stop the broker, watch the node report failures, restart it and watch the node reconnect unattended.

Test and expected result

Telemetry appears on the broker every fifteen seconds, the command topic switches the output, and the node reconnects after the broker restarts.

Acceptance checks

telemetry published, command switches output, reconnect after broker restart

Safety and limits

MQTT here is unencrypted and unauthenticated on the local network. Do not carry credentials or personal data over it.

Guide source: Generated from this project's own pin map and compiled with arduino-cli for esp8266:esp8266:nodemcuv2 before publication; bench validation on your hardware is still required.

Download Arduino source code

Download connection diagram SVG

Related projects

Back to all project guides · Study the course