I confess. I have been sucked in to a home automation addiction. The next thing on my radar was to automate roller blinds. There are commercial products available but the ones I found are surprisingly expensive (about 80 - 90 USD). Since I need a bunch, it was hard to motivate the purchase (and less fun). I decided to design my own.

If you like this Instructable, please vote for it in the Microcontroller contest (press Vote above)!

These were my requirements:

  • WiFi capable
  • MQTT control (0% - 100%)
  • Manual push button operation
  • Use low cost standard electronic components and 3D-printable parts
  • Persist state on power off

This instructable is a followup to https://www.instructables.com/id/Motorize-IoT-With...

Step 1: Bill of Materials

The motor parts add up to about 15-20 USD per unit. The shade itself is 19 USD.

Step 2: Wiring

  • Wire the motor to the shield as seen in the pictures. Take note of the colors.
  • Solder cables to the micro switch as seen in the picture. If you can, use red, black and white as in the picture.
  • Attach the button wires to (GPIO) 5 as seen in the picture

Step 3: Set Up a MQTT Broker

MQTT is a lightweight publish/subscribe protocol suitable for small IoT devices. The devices interact with a message broker which manages the distribution of messages. You can either use a local mqtt broker, e. g. Mosquitto inside your own network or connect to a cloud MQTT broker. Which option is best? It depends on your needs. If you want to be able to connect to the broker from anywhere you may prefer the cloud option. If you prefer to keep your IoT within you network you should use a local broker.

Setting up a cloud broker:

  1. Register at CludMQTT: https://www.cloudmqtt.com/
  2. Creat a new broker instance
  3. Click the instance info and keep the info handy
  4. For testing purposes, download MQTT.fx: http://mqttfx.jfx4ee.org/
  5. Add a profile to MQTT.fx with the credentials from your newly created cloud broker.
  6. Connect. If it works you have successfully tested the connection to your fresh cloud broker.

Step 4: The Software

The ESP8266 on which the NodeMCU development board is a single chip computer with I/O capabilities and WiFi. The chip can be programmed in various ways. The two most popular options are the Arduino IDE and the Lua interpreter. For this project I chose Lua out of convenience. Some of the features in the software are easier in Lua because of the built in file system.

Flash the Lua Firmware

Even if your NodeMCU is pre-flashed with a Lua firmware I recommend that you re-flash it with a new firmware. That way you get a fresh version and can slim the binary to only contain the needed modules.

  1. Cook a LUA firmware here: https://nodemcu-build.com/ Select the following modules: file, GPIO, MQTT, net, node, PWM, timer, WiFi and optionally enable SSL
  2. Wait for the email with the firmware download link, then download. It should only take a few minutes. You may want to check your spam filter for it. That's where mine was.
  3. Download Flash tool: https://github.com/marcelstoer/nodemcu-pyflasher/...
  4. Flash the firmware using the flash tool
    1. Run the tool
    2. Connect the NodeMCU holding the flash button
    3. Select the serial port
    4. Select the firmware file
    5. Press Flash

Install the rollerblind code

  1. Download the roller blind code here: https://bitbucket.org/ehsmaes/motor_rollerblind/s...
  2. Download ESPlorer IDE: https://esp8266.ru/esplorer/
  3. Open Esplorer
    1. Select the serial port
    2. Connect
    3. Open all the lua files
    4. Edit settings.lua and enter WiFi and MQTT settings
    5. Upload all lua files (Save to ESP)
    6. Reset device

    Step 5: Dry Run

    Now would be a good time to check the software and wiring.

    • Open up esplorer and connect
    • Run the following command line (see picture). The motor should rotate 1000 steps (about a quarter of a turn.

    Step 6: 3D Printed Parts

    I designed the parts in Fusion 360.

    Download the parts from http://www.thingiverse.com/thing:2065722 and start printing!

    Step 7: Assembly

    This is what you need to do for assembly (watch video):

    1. Heat the soldering iron to about 200 degrees C (400 F).
    2. Embed the nut inserts into the plastics by placing the insert over the tip (so it heats up) and gently push it into the plastic sockets (see picture).
    3. Remove the lever from the micro switch
    4. Loosen the plastic hinge on the lid button (gently push it out and back in)
    5. Push the micro switch in place
    6. Push the motor shield into place
    7. Insert the motor
    8. Screw the plastic parts

    Important note on power: I have found that if you have a narrow window or short travel distance you are fine with just USB power (5v) but for wider and longer blinds you need external power (max 9v DC). You attach external power to the motor shield. Make sure you disconnect USB before you do or you are likely to fry something.

    Step 8: Mount Rollerblind

    Replace the springloaded end mount and insert of the Ikea rollerblind with the printed motor mount and printed insert.

    Step 9: Calibration

    Windows are of different heights; hence the gadget has to be calibrated. This is how:

    1. Long press the button (> 2s)
    2. The shade starts going down
    3. When the shade reaches desired bottom position, short press
    4. When the shade reaches derired top position, short press again
    5. Done!

    Step 10: MQTT Control

    • Download MQTT.fx from here: http://mqttfx.jfx4ee.org/index.php/download
    • Start MQTT.fx
    • Create a profile to match the broker you already set up
    • Connect
    • Subscribe to the topic from config.lua e. g. "/house/masterbedroom/#" wihtout the quotes. If you don't have anything else on your broker bus you can subscribe to everything (e. g. "#")
    • You should see heartbeat messages sent out from the device every two minutes
    • To control the device, publish to the topic matching config.lua "/house/masterbedroom/rollerblind/0/set"

    Of course, this setup is obviously not terribly useful for daily operation but it will help you weed out any potential problems. If you just want to control mqtt devices you can download a MQTT cotrol dashboard on you phone. If you want to use other general home automation software I think you should find that most support MQTT integration.

    Step 11: Integration With Openhab (optional)

    I will give you an example of integration with the home automation solution I am using. If you have a pre-installed openhab home automation solution or would like to set one up (there are guides on their home page), this is what you should do to integrate the roller blind.

    1. Install and configure the openhab according to their instructions
    2. Install MQTT binding
    3. Configure MQTT binding for your previously configured broker (local or cloud)
    4. Add the roller blind to your items and sitemap file. See example below.


    Dimmer masterbedr_blind1 "Rullgardin 1" <rollershutter> { mqtt=">[ohab:/house/masterbedroom/rollerblind/0/set:command:*:${command}],<[ohab:/house/masterbedroom/rollerblind/0/status:state:default]" } 


    Slider item=masterbedr_blind1
    <p>Can someone point me in the right direction how to make this work with Domoticz?</p>
    <p>Skipped the Mqtt integretion with Domoticz and made it with HTTP Get request. The only drawback is that I cant stop the blind. But it works.</p><p>But when I was setting this up, the blind doesnt go up. It seems like it doesnt have the power to pull it up. I have it connected to 9v 300mA. Is it too small?</p>
    <p>Hi, trying to make it work with domoticz, can you please ggive some tips on how to make it work with htt requests?</p>
    <p>Did you check this?</p><p>https://www.domoticz.com/wiki/MQTT</p>
    <p>Good tips will be taken, how to add this to Domoticz? :)</p>
    <p>Hi! Can't make it work. Motor just makes some noise - no spins. what do I do wrong? Would be appreciate for any help. Thank You!</p>
    Great project, will try it out. I have a question, maybe someone who already tried it can answer, a have 4 curtains with the same length, can I connect 4 motors parallel to one motor board? Maybe with 12V power?
    <p>Download MQTT.fx from here: <a href="http://mqttfx.jfx4ee.org/index.php/download" rel="nofollow"> http://mqttfx.jfx4ee.org/index.php/download</a> Is this only used for MQTT cloud? As Website seem to be history.</p>
    Have someone actually got this to work without overheating etc for everyday use? Can ts pls update guide to work with new motorshield or can i order old motorshield somewhere? My sausage fingers having trouble to mod The shield :) i have order parts for 4 of these(incl 3d printed parts) and would appriciate help to get this working. <br>Im stuck at the motor is only &quot;burring&quot; part :)
    <p>Of course i&acute;ve ordered wrong parts. NodeMcu V3 having different measures than V2.. It&acute;s 30x60 and pin header on motor shield do not fit.. Which pins need to be connected to motor shield? If I just use jump wires or should i use Wemos D1 mini or Pro with it as having them and with those there shouldnt be a need to re-design enclosure?</p>
    <p>mee too! ;)) Did not try yet but I hope I fixed with a diy PCB bridge</p>
    <p>The stepper gets really hot, is it the same for you?</p>
    <p>This is the second time I am typing this (seems to have disappeared the first time), sorry if this is a duplicate post.</p><p>I ordered the parts to build 18 of these. So far i have built 3, all don't work but all of them have the same symptoms</p><p>1) when using the debug command above of step_move(1000,FWD,2) the motors will just hum, not spin. its like the wire order is wrong for the motor. I have tried the order in the photos with all 3 motors (blue, pink, yellow, orange, red), i tried reversing yellow and orange because they are very close in color and its possible i got them wrong, I even tried completely reversing the colors, same result every time. I tried running the motor board off of my bench supply, same result. Its like the code is trying to drive the coils in the wrong order or something.... thoughts?</p><p>2) the link you list above for the MQTT.fx test software is dead... looks like the guy didn't pay his hosting bill.</p><p>3) Pressing the button crashes the software with this error. (all three builds do this). I am using the most recent code from Bitbucket.</p><p>================== ==================</p><p>ESP8266 mode is: 1</p><p>MAC address is: a2:20:a6:17:b7:32</p><p>IP is</p><p>====================================</p><p>mqtt_start()</p><p>short0</p><p>DOWN!</p><p>going down</p><p>PANIC: unprotected error in call to Lua API (stepper.lua:72: bad argument #2 to 'alarm' (number expected, got nil))</p><p> ets Jan 8 2013,rst cause:2, boot mode:(3,6)</p><p>load 0x40100000, len 26896, room 16 </p><p>tail 0</p><p>chksum 0x13</p><p>load 0x3ffe8000, len 2416, room 8 </p><p>tail 8</p><p>chksum 0x5d</p><p>load 0x3ffe8970, len 136, room 0 </p><p>tail 8</p><p>chksum 0x5d</p><p>csum 0x5d</p><p>&OElig;&acirc;&igrave;2&sbquo;N&igrave;|{&sbquo;&Yuml;N|&igrave;ld$l`&bdquo;&Acirc;&oelig;n&sbquo;l&OElig;</p><p>NodeMCU custom build by frightanic.com</p><p>branch: master</p><p>commit: b96e31477ca1e207aa1c0cdc334539b1f7d3a7f0</p><p>SSL: true</p><p>modules: file,gpio,mqtt,net,node,pwm,tmr,wifi,tls</p><p> build built on: 2017-03-03 02:00</p><p> powered by Lua 5.1.4 on SDK 2.0.0(656edbf)</p><p>Configuring Wifi ...</p><p>&gt; Connecting to rhbtm ...</p><p>IP unavailable, Waiting...</p><p>================== ==================</p><p>ESP8266 mode is: 1</p><p>MAC address is: a2:20:a6:17:b7:32</p><p>IP is</p><p>====================================</p><p>mqtt_start()</p><p>Thoughts? any help would be greatly appreciated. </p>
    <p>Anyone looking for MQTTFX, it can be found here. The link in the article doesnt work anymore http://www.jensd.de/apps/mqttfx/1.3.1/</p>
    <p>I figured out why the motor wont spin.</p><p>New motor control boards are wired differently. (I found another individual with a similar problem on the authors other projects)</p><p>input 2 and input 4 on the H Bridge IC are not wired to pins D1 and D2 on the NodeMCU, also Enable pin 2 on the H Bridge is wired to D2 on the nodeMCU via a resister. Enable pin 1 on the H Bridge is pulled low via a resister that is hardwired.</p><p>So to be clear it looks like stepper motors cannot be run off of this board without unsoldering the resistor, jumping the inputs and jumping the enable pin on the H Bridge.</p><p>I am jumping a board as we speak and i will let you know what i had to do to make it work.</p>
    <p>That was easier then i though</p><p>H Drive schematic is here <a href="https://www.arduino.cc/documents/datasheets/H-bridge_motor_driver.PDF" rel="nofollow">https://www.arduino.cc/documents/datasheets/H-brid...</a></p><p>To fix solder pin 1 to 20 and 11 (This will enable both motor drivers)</p><p>Solder pin 9 to D1 (its marked 1 on the motor controller board)</p><p>Solder pin 19 to D2 (its marked 2 on the motor controller board)</p><p>Remove the 2nd and 5th resistor from the motor controller board (assumes the board is rotated so the blue headers are on your left)</p><p>Now i need to figure out the switch problem that crashes the code and figure out why non of the MQTT messages ever make it to the cloud or local MQTT servers....</p>
    <p>ok the bug that stops the switch from working is in stepper.lua</p><p>change line 93 that reads &quot;step_delay = delay&quot; to &quot;-- step_delay = delay&quot;</p><p>save and it will work. Not sure why but the author was overwriting the constant set above with a nul value whenever the motor tried to move.</p>
    <p>ok last bug solved.</p><p>replace the register_myself() sub in MQ.lua with this </p><p>local function register_myself() </p><p>print(&quot;Attempting to Register &quot; .. config.MQID)</p><p> m:subscribe(config.ENDPOINT .. config.ID .. &quot;/set&quot;,0, function(client) print(&quot;Successfully subscribed to &quot; .. config.MQID) end)</p><p>end</p><p>not sure why the old subscribe statement didnt work, i have never used LUA, learning as i go.</p><p>My project is now fully functional!! Now i just need to build 17 more :-)</p>
    <p>I did your changes in mq and stepper filer... when starting only the ESP with serial monitor i get this</p><p>Communication with MCU..Got answer! Communication with MCU established.</p><p>AutoDetect firmware...</p><p>Can't autodetect firmware, because proper answer not received (may be unknown firmware). </p><p>Please, reset module or continue.</p><p>onnecting to NR.1 ...</p><p>IP unavailable, Waiting...</p><p>================== ==================</p><p>ESP8266 mode is: 1</p><p>MAC address is: a2:20:a6:16:91:eb</p><p>IP is</p><p>====================================</p><p>E:M 4440<br>E:M 4440<br>E:M 4440<br>E:M 4440</p><p>Then it only repeats E:M 4440.... any thought, is that correct?</p>
    <p>Solved it... set TLS = 0 fixed it...</p>
    <p>if you motor runs clockwise even when it should be in reverse then removing the small transistor looking device in between the resisters will fix the problem. It seems that it shorts the A- and A+ rails causing the coils to fire in the wrong sequence. I used 4 LED's hooked up in place of the stepper motor to diagnose my setup, that's what lead me to find this.</p>
    <p>I highly recommend running this at 9 Volts once completed (make sure USB is disconnected.</p><p>The motors has no power at 5 volts and is unable to move when any resistance is applied. 9 volts provides the motor with ample power to pull the blinds up and down.</p>
    <p>I'm having the same issue, would you mind posting some pictures of your board? I need to do the same and would be nice to a &quot;blueprint&quot; so i dont misinterpret your instructions</p>
    <p>Take a look at the image, that should make it clear what i did. Let me know if you have any questions.</p>
    <p>Aah much appreciated! <br>About the resistors, whats the best way to remove them, checked the backside yesterday and there was no solder point to heat up?<br>And in the above description you wrote, &quot;remove the 2nd and 5th&quot;, but in the picture there are 3 resistors marked for removal, just want to make sure ;)</p>
    <p>I can answer myself after giving it a try! <br>I'm using a pretty big soldering iron but it was not a big issue, the best way to remove the resistors are to just heat them up a little bit while pushing carefully against it and it will pop off without a struggle.<br>The transistor like thingy is the same, heat up one side untill it flips, then grab it with a plyer and heat the other side. <br><br>It seems we have the same boards because I had to remove the &quot;transistor&quot; as well.<br>Grifter, have you connected 9volts to it? I've tried with a 9v 1000mA adapter i had, but the stepper motor becomes realy warm just by being connected, i connected it to the first &quot;GND&quot; and &quot;VIN&quot; (the first = the one in the corner, not the one next to the &quot;VM&quot; connector with the red cable from the stepper engine.<br><br>Does anyone know what voltages/amps the board can support? I have 12volts 500mA adapters, would I be able to use them? <br><br>I'm working on a more complete guide for doing all of this, and to include them into a Home Assistant environment (https://home-assistant.io/)<br><br>@ehsmaes: Maybe you would care to update this guide if I provide you with the needed info and pictures? Would be nice to contribute to this guide. </p>
    <p>Love this, is it possible to get the design files, not sure if it's the overhands on my printer but could do with making the channel for the cables to run deeper and also lie the idea of trying to merge a small wemos D1 holder into the main gear box, have printed it already though as a test and just need to get a blind :-)</p>
    <p>I uploaded the design files to thingiverse. Please post a remix if you decide to use them. Enjoy!</p>
    <p>Brilliant, thanks. will of course post it as a remix. I'm thinking of doing a wemos D1 mini enclosure and maybe merge it into the bracket. I'm a complete novice in 3d modelling so this will actually make it a possibilty, thanks again.</p>
    <p>Like it!</p>
    <p>Nice project! I have it working on a Wemos D1 Mini, but occasionally the Wemos crashes here and there, mostly due to an error on stepper.lua line 72. Any idea how this happens? Have you tried to connect it to Apple Homekit using HAPNodeJS or OpenHAB or something else? I'm aiming on doing that in the next few days.</p>
    <p>thanks! What error du you get on line 72? I haven't tried any of the other integrations but I do use Openhab. Read all the way to the end of the instructable :-) Openhab example included.</p>
    <p>Hi, Great project; I'm most interested in how you got the LUA mqtt client talking to CloudMQTT reliably? I've been testing the same exact setup (yes custom NodeMCU firmware) for months and it's almost guaranteed that after 2-3 months the Node becomes an island meaning it is no longer subscribed to the topic so the only way out is a reboot; it isn't a network thing; the Node is pingable and has valid IP all along. I've always suspected the LUA mqtt client? Thank you</p>
    <p>Hi, I used CloudMQTT for this project mainly for demo purposes. I haven't used it as my daily runner which could very well be why I haven't run into these issues. I actually prefer using a lokal broker (on Raspberry Pi) for reliability and security reasons.</p>
    <p>cool idea I love it</p>
    <p>Thank you!</p>
    <p>Woww! I always wanted one of these. Great job! <br><br>Can you add a bluetooth shield to control through the smartphone?</p>
    perhaps you could but I really don't see the point. If you just want direct phone control, install a mqtt dashboard from app store or Android store
    <p>Can I use a Wemos D1 mini instead of nodemcu?</p>
    Can't see why not. I just got a few in the mail (with motor shield) so I might give it a try.

    About This Instructable




    Bio: IT-professional by day, DIY hobbyist (among other things) on my free time. I always have one or more projects going on. Usually something to do ... More »
    More by ehsmaes:Motorized WiFi IKEA Roller Blind Cheap 3D Delta Printer Improvements Motorize IoT with ESP8266 
    Add instructable to: