Skip to content
My Account

Electronics

Blinds over MQTT with a NodeMCU and a Stepper Motor

A NodeMCU that moves blinds with a 28BYJ-48 stepper motor, set as a percentage over MQTT and used from Homebridge.

  • NodeMCU
  • Homebridge
  • Archived
  • 2 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.

Blinds that you open and close from the Home app, built on a NodeMCU and a small stepper motor, and controlled over MQTT. The sketch keeps track of the position of the blind and lets you set it as a percentage.

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 a NodeMCU with a stepper motor driver board and a 28BYJ-48 stepper motor

The hardware

PartWhat it does
NodeMCU (ESP8266)The controller
Stepper motor with a driver boardA 28BYJ-48 stepper motor on the pins D1 to D4
SupplyMarked 9 V in the diagram

The motor coils are switched off when the blind is not moving, so the motor does not get warm.

MQTT and the commands

The MQTT topics are made from the chip ID of the ESP8266, one to listen on and one to send on, so you can use several blinds without changing the code. The sketch also answers over a WebSocket. A message is one of these commands, or a number:

MessageWhat it does
(start)Stores the current position as the start position, the top of the blind
(max)Stores the current position as the maximum, a closed blind
(0)Stops
(1)Moves down without a limit, up to the maximum
(-1)Moves up without a limit, up to the top
(update)Sends the position
(ping)Does nothing
A number from 0 to 100Moves to that position in percent

The position is reported as JSON: { "set": 50, "position": 30 }, with the target and the current position in percent.

Set the limits

Before the percentages work, the sketch has to know where the blind starts and ends. Move the blind to the top with the manual commands and send (start). Then move it down to where it is closed and send (max). The positions are stored.

Two versions

The repository has two sketches. The first uses the Stepper_28BYJ_48 library, the second, version 2.0, uses the standard Stepper library at 60 rpm, and saves the configuration with a WiFi manager.

Good to know

  • 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 HomeBridge-MQTT-Blinds 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