Skip to content
My Account

Electronics

Switch a Led over MQTT with an ESP-01

An ESP-01 that subscribes to an MQTT topic and switches a led on and off, the starting point for MQTT devices.

  • MQTT
  • Archived
  • 1 min read
No ratings yet, be the first.

Archived project

The GitHub repository for this project is archived: it is read-only and no longer updated. What follows describes the project as it was, so check for a newer alternative before you build it.

The smallest MQTT project: an ESP-01 that switches a led on and off when it receives a message. It is the first step to any MQTT device.

Homebridge is a program that runs on a computer such as a Raspberry Pi, and makes devices that do not support HomeKit show up in the Apple Home app. This project dates from the Homebridge years, before the native HomeKit firmware of this site. For how the site builds HomeKit devices today, see HomeKit or Matter for your ESP32.

MQTT is a light messaging protocol: devices publish messages on a topic, and other devices that subscribe to that topic receive them, through a broker.

Diagram of an ESP-01 with a led, a capacitor and an FTDI adapter on a breadboard

How it works

The ESP8266 joins your WiFi, connects to the broker at a fixed address and subscribes to a topic, InTopic. Change it to a name of your own. When a message arrives, the sketch compares the text:

MessageWhat happens
OnGPIO2 goes high, and the led lights up
Anything elseGPIO2 goes low

The sketch reconnects by itself when the WiFi or the broker drops.

Good to know

  • The sketch is version 0.2.1 and uses the PubSubClient library.
  • The repository is under the MIT licence.
  • Apple, HomeKit and Homebridge are trademarks of their owners. This project is not made or approved by them.

The project is in the Apple-Homebridge—MQTT-LED repository on GitHub.

Advertisement
All projects

More projects

Keep building.

Electronics, 3D printing and CNC builds, documented from the first idea to the last screw.

All projects