Built in 2025

The blinds controller

A stepper motor that grips the bead chain on my roller blind and pulls it up and down, so the blind itself didn't have to change. I designed the PCB, the printed case and the firmware.

Version
1
Microcontroller
ESP32-C6
Motor driver
TMC2209
PCB
My own, made in KiCad
The white printed case fitted beside a green roller blind, with the bead chain running round a wheel on the motor
Fitted next to my blind. The round pad on the front is the touch control.

Using the chain that was already there

The blind already had a chain that worked fine, so there was no point replacing it. The controller just grabs that chain instead. A wheel on the motor pulls the beads round, and the case screws to the wall next to the window.

I can move it from the app, by voice, or with the touch pad on the front. The ESP32-C6 runs the motor, the touch pad and the schedules on its own, and keeps its settings in flash. The app talks to it over MQTT and voice goes through SinricPro.

Hand-drawn sketch of the case on dotted paper: 46 by 50 by 72 millimetres, wall mount holes, a slotted motor mount and the TTP223 touch pad on the front
My sketch of the case: about 46 × 50 × 72 mm, with wall mounts, a slotted motor mount so the motor can move up and down a little, and the TTP223 touch pad on the front.

How the parts connect

The touch pad goes into the ESP32-C6. The ESP32 tells the motor driver when to step and which way to turn, and the driver powers the motor coils. Wi-Fi connects it to the app and the other services.

How the parts connect The touch pad feeds the ESP32-C6. It sends step, direction and enable signals to the TMC2209, which drives the stepper motor. Wi-Fi connects it to three services. motor coils Wi-Fi MQTT brokerMosquitto, on the home network SinricProAlexa and Google Home OpenWeatherMapSunrise, sunset, weather Touch padTTP223 · GPIO 21 ESP32-C6reads the touch padsends the motor steps TMC2209 driverSTEP 4 · DIR 5 · EN 2signals from the ESP32 Stepper motorturns the chain wheel
  1. Touch pad→ESP32-C6

    The touch signal comes in on GPIO 21.

  2. ESP32-C6→TMC2209

    Step on GPIO 4, direction on GPIO 5, enable on GPIO 2.

  3. TMC2209→Motor

    The driver powers the coils and the motor turns the chain.

  4. ESP32-C6→Network

    Wi-Fi to the MQTT broker, SinricPro and OpenWeatherMap.

Solid lines are wires and dashed lines are network links. Power isn't drawn, but it's in the tables further down.

Driving the stepper motor

Every step pulse from the ESP32-C6 turns the motor a tiny amount through the TMC2209 driver. I chose the TMC2209 because it's quiet. With StealthChop2 and microstepping it's much less noisy than a basic driver, which matters for something that moves in a bedroom first thing in the morning.

Timing on its own

The steps come from a 20 kHz hardware timer interrupt, separate from the Wi-Fi code, so a busy network doesn't make the motor stutter.

Speeding up gently

Normal moves ramp the speed up at the start and down at the end, so the chain doesn't jerk.

Knowing where it is

There's no encoder. It counts steps from the calibrated top and bottom, so a missed step would make the position it reports slightly off.

Reading the touch pad

One pad does everything on the device itself. What a press does depends on how long you hold it and whether the blind is already moving.

Single tap

Open, close or stop

When it's stopped, a tap opens the blind if it's under 50% open and closes it if it's 50% or more. While it's moving, a tap slows it down to a stop.

Second tap within 400 ms

Go the other way

While it's moving, a double tap stops the current move and starts one in the opposite direction. When it's stopped, it acts like a single tap.

Hold 1.5 s while moving

Stop straight away

Stops the motor without the slow-down and ignores the pad until you let go. Keeping your finger on it won't go on to reset the Wi-Fi.

Hold 10 s while stopped

Set up Wi-Fi again

Clears the saved Wi-Fi details and restarts setup. The travel calibration is kept. Let go once it restarts.

Moves only work once the travel limits are calibrated. A press has to stay stable for 50 ms before the firmware believes it, which filters out short electrical glitches.

Touch pad states Idle goes to Pressed on a touch. Releasing opens a 400 millisecond window for a second tap. Holding while the blind moves stops the motor and waits for release. A second press goes back to Idle on release or after five seconds. S0Idlewaiting for a touch S1Pressedtiming the hold S4Hold handledwaiting for release S2Releasedwaiting for a 2nd tap S3Second pressdouble-tap action touch 1.5 s hold while moving release touch within 400 ms 400 ms: single tap release after the hold release the second press, or 5 s timeout
  1. Idle→Pressed

    A confirmed touch starts the hold timer.

  2. Pressed→Released

    Letting go starts the 400 ms double-tap window.

  3. Released→Idle

    If the 400 ms runs out, it's a single tap.

  4. Released→Second press

    Another touch inside the window is a double tap.

  5. Second press→Idle

    On release, or after a 5 s timeout.

  6. Pressed→Hold handled

    Holding for 1.5 s during a move stops the motor.

  7. Hold handled→Idle

    Let go before the next command.

Solid lines are touch and hold events, dashed lines include a timeout. The timings come from the TouchManager code in the firmware.

The Wi-Fi reset is a separate path. When the motor is stopped, staying in Pressed for 10 seconds clears the Wi-Fi settings and restarts the controller. If a hold has already stopped the motor, it stays in Hold handled until you let go, so the same press can't do both.

Schedules and automations

All five rules run on the controller, but they don't all get their information from it. The fixed schedules use its clock, the sunset and heat rules need weather data, and the empty-room rule depends on the light switch.

  1. Morning wake-up

    Opens the blind in small steps over a period I choose, up to two hours, so the room gets lighter gradually instead of all at once.

    Trigger
    A start time for each day of the week
    Safety
    Only ever moves towards open, and a tap cancels it
  2. Close at sunset

    Gets the sunset time from OpenWeatherMap and closes the blind then, so the schedule follows the seasons without me touching it.

    Source
    OpenWeatherMap, refreshed daily
    Offset
    A few minutes before or after sunset, if I want
  3. Night lock

    Closes the blind at night and stops the other rules moving it until the morning routine.

    Schedule
    Per day, with weekdays and weekends
    Note
    Only a lock in the software
  4. Close when the room is empty

    The light switch publishes whether the room is occupied over MQTT. If it stays empty for the delay I've set, the blind closes.

    Needs
    The light switch and the broker to be online
    Delay
    Stops it closing every time I leave for a minute
  5. Heat protection

    Closes the blind when the outside temperature from OpenWeatherMap goes above a threshold.

    Source
    Outside temperature, not a sensor in the room
    Cooldown
    15 minutes, so it doesn't keep flipping near the threshold

Pins and power

The ESP32-C6 only needs four pins for this. The rest of the board is power.

PartModelPinSignalWhat it does
Motor enableTMC2209GPIO 2Digital outEnables the driver (active low)
StepTMC2209GPIO 4Timer interrupt20 kHz step pulses
DirectionTMC2209GPIO 5Digital outWhich way the motor turns
Touch padTTP223GPIO 21Digital inCapacitive touch (active high)
Power partModelRatingWhat it does
InputUSB-C connector5 V, 2 APower from a USB supply
ProtectionTVS diode and fuse5.6 V clamp, 2 AOver-voltage and over-current protection
RegulatorAMS1117-3.35 V to 3.3 VLogic rail for the ESP32-C6 and touch pad

All the grounds (USB-C, regulator, ESP32 and the rest) join one continuous ground plane on the PCB to keep the noise down.

The network, and saving power

Wi-Fi carries the app commands and the weather and time updates, and Bluetooth is for setup and recovery. The touch pad always works, but anything that needs the network waits until it's back.

Setup and recovery

The Wi-Fi details go in over Bluetooth during setup. Holding the pad for 10 seconds with the motor stopped clears them and restarts setup, without losing the calibration.

Alexa and Google Home

Voice commands go through SinricPro, and the controller reports its estimated position back. This part needs the internet.

MQTT

It publishes its position, motor data and diagnostics to my broker, and subscribes to the light switch so the empty-room rule works.

Weather and time

Sunset and temperature come from OpenWeatherMap once a day. Time comes from NTP, and if a network blocks NTP it reads the time from an HTTP response header instead.

Target Wake Time

Wi-Fi 6 lets the controller and a compatible router agree on wake-up windows, so the radio can sleep in between. The drawing is just the idea, not a measurement. I haven't measured the saving on this one yet.

on off wake wake wake sleep sleep sleep sleep TWT interval TWT interval time →
The radio wakes briefly to send and receive MQTT messages, then sleeps. The touch pad still works while the radio is asleep.

Protecting the settings

The calibration and schedules live in flash, and a power cut in the middle of a save shouldn't lose them.

  • 2s

    Between saves

    Settings save when they change, but never more than once every two seconds, to save wear on the flash.

  • 2

    Copies, each with a CRC32

    There are two settings slots. At start-up the firmware checks the checksum and loads the other copy if the main one is broken.

  • 3

    Restarts before recovery mode

    Repeated unexpected restarts put it into recovery mode, which stops normal motor moves so I can work out what's wrong before it tries again.

If I change the format of the saved settings in a firmware update, it checks the version that's stored and moves the compatible values across.

Full spec

ProcessorESP32-C6, 32-bit RISC-V, 160 MHz
Radio2.4 GHz Wi-Fi 6 and Bluetooth LE 5, with Target Wake Time
PowerUSB-C, 5 V 2 A, with a TVS diode and fuse
Rails5 V for the motor, 3.3 V logic from an AMS1117
Memory4 MB flash and 512 KB SRAM, with the settings in two CRC32-checked slots
MotorStepper on a TMC2209 with StealthChop2, AccelStepper, 20 kHz timer
Position64-bit step counter (int64_t), no encoder
TouchTTP223 capacitive pad, five-state debounced state machine
VoiceSinricPro over a WebSocket, for Alexa and Google Home
DiagnosticsSix ring buffers covering Wi-Fi, MQTT and the motor
RecoverySafe mode, and booting from the backup settings slot

What I'd change next

The first thing I want to try is setting up the TMC2209 over UART instead of relying only on its hardware pins. That would let the firmware change the driver settings and read its diagnostics, which should make setup and fault-finding easier.

For the next one I'd also like separate up and down buttons and a clearer status light.

In the meantime you can try the blinds controls in the Zaylo Remote demo, which has pretend blinds to move around.