Introduction: Motorized WiFi IKEA Roller Blind

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.

    Item:

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

    Sitemap:

    Slider item=masterbedr_blind1

    Comments

    author
    MichaelS1175 (author)2017-08-16

    Hi

    Nice project.
    I have uploaded all the files to the ESP MCU but get some issues when it's trying to connect to the WiFi. Anyone with experience out there that can help me?

    odeMCU custom build by frightanic.com

    branch: master

    commit: b62fae918b3627209fe434950cffb2506cee9a31

    SSL: false

    modules: file,gpio,mqtt,net,node,pwm,tmr,wifi

    build built on: 2017-08-16 11:52

    powered by Lua 5.1.4 on SDK 2.1.0(116b762)

    Configuring Wifi ...

    > PANIC: unprotected error in call to Lua API (wifi_setup.lua:25: bad argument #1 to 'config' (config table not found!))

    ets Jan 8 2013,rst cause:4, boot mode:(3,7)

    wdt reset

    load 0x40100000, len 27016, room 16

    tail 8

    chksum 0x2d

    load 0x3ffe8000, len 2188, room 0

    tail 12

    chksum 0xee

    ho 0 tail 12 room 4

    load 0x3ffe888c, len 136, room 12

    tail 12

    chksum 0x6a

    csum 0x6a

    Œâì‚nì’r‚òn|ìllll`b’ž|r’lœnà‚nâ

    author

    config.lula

    module.SSID = {}

    module.SSID["comhem_F113B5"] = "5455xxx"

    author
    JonasB63 (author)2017-08-09

    Did anyone have any luck flashing the board on a mac? I've tried various ways, but nothing seems to do the trick. Kinda stranded here

    author
    ssvenn (author)JonasB632017-08-12

    I tried and failed, then used a PC. If you have no PC available I bet you could make it work with Parallels or VirtualBox on a mac by USB device sharing with a VM, download the windows 10 ISO from microsoft and install a temporary virtual machine with the software you need (no license required, there is a grace period after the install)

    author
    Grifter2 (author)2017-03-02

    This is the second time I am typing this (seems to have disappeared the first time), sorry if this is a duplicate post.

    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

    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?

    2) the link you list above for the MQTT.fx test software is dead... looks like the guy didn't pay his hosting bill.

    3) Pressing the button crashes the software with this error. (all three builds do this). I am using the most recent code from Bitbucket.

    ================== ==================

    ESP8266 mode is: 1

    MAC address is: a2:20:a6:17:b7:32

    IP is 192.168.1.213

    ====================================

    mqtt_start()

    short0

    DOWN!

    going down

    PANIC: unprotected error in call to Lua API (stepper.lua:72: bad argument #2 to 'alarm' (number expected, got nil))

    ets Jan 8 2013,rst cause:2, boot mode:(3,6)

    load 0x40100000, len 26896, room 16

    tail 0

    chksum 0x13

    load 0x3ffe8000, len 2416, room 8

    tail 8

    chksum 0x5d

    load 0x3ffe8970, len 136, room 0

    tail 8

    chksum 0x5d

    csum 0x5d

    Œâì2‚Nì|{‚ŸN|ìld$l`„Âœn‚lŒ

    NodeMCU custom build by frightanic.com

    branch: master

    commit: b96e31477ca1e207aa1c0cdc334539b1f7d3a7f0

    SSL: true

    modules: file,gpio,mqtt,net,node,pwm,tmr,wifi,tls

    build built on: 2017-03-03 02:00

    powered by Lua 5.1.4 on SDK 2.0.0(656edbf)

    Configuring Wifi ...

    > Connecting to rhbtm ...

    IP unavailable, Waiting...

    ================== ==================

    ESP8266 mode is: 1

    MAC address is: a2:20:a6:17:b7:32

    IP is 192.168.1.213

    ====================================

    mqtt_start()

    Thoughts? any help would be greatly appreciated.

    author
    Lexodexo (author)Grifter22017-07-10

    I found a solution:

    Just change line 72 in stepper.lua to

    tmr.alarm(step_timerid, 10, 0, step_take )

    author
    Grifter2 (author)Grifter22017-03-04

    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/

    author
    Grifter2 (author)Grifter22017-03-04

    I figured out why the motor wont spin.

    New motor control boards are wired differently. (I found another individual with a similar problem on the authors other projects)

    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.

    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.

    I am jumping a board as we speak and i will let you know what i had to do to make it work.

    author
    Grifter2 (author)Grifter22017-03-04

    That was easier then i though

    H Drive schematic is here https://www.arduino.cc/documents/datasheets/H-brid...

    To fix solder pin 1 to 20 and 11 (This will enable both motor drivers)

    Solder pin 9 to D1 (its marked 1 on the motor controller board)

    Solder pin 19 to D2 (its marked 2 on the motor controller board)

    Remove the 2nd and 5th resistor from the motor controller board (assumes the board is rotated so the blue headers are on your left)

    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....

    author
    Grifter2 (author)Grifter22017-03-04

    ok the bug that stops the switch from working is in stepper.lua

    change line 93 that reads "step_delay = delay" to "-- step_delay = delay"

    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.

    author
    Grifter2 (author)Grifter22017-03-04

    ok last bug solved.

    replace the register_myself() sub in MQ.lua with this

    local function register_myself()

    print("Attempting to Register " .. config.MQID)

    m:subscribe(config.ENDPOINT .. config.ID .. "/set",0, function(client) print("Successfully subscribed to " .. config.MQID) end)

    end

    not sure why the old subscribe statement didnt work, i have never used LUA, learning as i go.

    My project is now fully functional!! Now i just need to build 17 more :-)

    author
    gadu74 (author)Grifter22017-03-18

    I did your changes in mq and stepper filer... when starting only the ESP with serial monitor i get this

    Communication with MCU..Got answer! Communication with MCU established.

    AutoDetect firmware...

    Can't autodetect firmware, because proper answer not received (may be unknown firmware).

    Please, reset module or continue.

    onnecting to NR.1 ...

    IP unavailable, Waiting...

    ================== ==================

    ESP8266 mode is: 1

    MAC address is: a2:20:a6:16:91:eb

    IP is 192.168.1.145

    ====================================

    E:M 4440
    E:M 4440
    E:M 4440
    E:M 4440

    Then it only repeats E:M 4440.... any thought, is that correct?

    author
    gadu74 (author)gadu742017-03-18

    Solved it... set TLS = 0 fixed it...

    author
    Grifter2 (author)Grifter22017-03-04

    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.

    author
    Grifter2 (author)Grifter22017-03-05

    I highly recommend running this at 9 Volts once completed (make sure USB is disconnected.

    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.

    author
    MattiasM4 (author)Grifter22017-03-12

    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 "blueprint" so i dont misinterpret your instructions

    author
    Grifter2 made it! (author)MattiasM42017-03-12

    Take a look at the image, that should make it clear what i did. Let me know if you have any questions.

    Boardmods.jpg
    author
    MattiasM4 (author)Grifter22017-03-12

    Aah much appreciated!
    About the resistors, whats the best way to remove them, checked the backside yesterday and there was no solder point to heat up?
    And in the above description you wrote, "remove the 2nd and 5th", but in the picture there are 3 resistors marked for removal, just want to make sure ;)

    author
    MattiasM4 made it! (author)MattiasM42017-03-13

    I can answer myself after giving it a try!
    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.
    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.

    It seems we have the same boards because I had to remove the "transistor" as well.
    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 "GND" and "VIN" (the first = the one in the corner, not the one next to the "VM" connector with the red cable from the stepper engine.

    Does anyone know what voltages/amps the board can support? I have 12volts 500mA adapters, would I be able to use them?

    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/)

    @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.

    2017-03-12 22.53.21.jpg2017-03-13 18.27.14.jpg2017-03-13 18.27.32.jpg
    author
    ssvenn made it! (author)2017-07-09

    Attempt two, added a buck converter to regulate 5V for the control logic, and I've modified the code a bit more and soldered enable1 and enable2 on the L293DD to gpio pin 6 and 7 instead of wiring it to Vs. Hopefully nothing blows up this time!

    IMG_0380.jpg
    author
    ssvenn (author)2017-07-09

    The magic smoke escaped during the night, And charred my wall :(

    Clearly it is not safe to run the nodemcu clone at 9V over time, a small capacitor failed short and my 9V 4A power supply melted the tracks right off the board!

    I have ordered some buck converters so I can run the motor with 12V and the nodemcu at 5V, and will redesign the 3d printed enclosure to add some safety, I don't want these things to start a fire.

    IMG_0376.jpgIMG_0375.jpgIMG_0372.jpg
    author
    ssvenn (author)2017-07-08

    I finally got my first rollerblind assembled and installed, I think the trick to avoid overheating is to keep the included spring and install the motor on the right side of the blind! After removing the brake and adjusting the spring tension, The blind will hold its position even with all the stepper coils disabled, which helps a lot with the overheating. The nodemcu board itself still gets hot at 9V though because the 3.3v regulator has to work pretty hard, hopefully it won't wear out.

    author
    ssvenn (author)2017-07-07

    Does anyone have this in daily use? I am planning to motorize all of my blinds but the first one I built does become worryingly hot. It seems like the nodemcu board draws almost 200mA regardless of voltage, which means the onboard regulator dissipates a ton of power when the input is 9v .. And the motor driver draws around 500mA at 9V, I think it is rated to handle 4W continuously without heatsinking.

    I love the software side of this project but it seems like the hardware would have a short, dangerously hot life.

    author
    thomasporter (author)2017-07-02

    This looks amazing, when I am out of rented accommodation I will definitely be building this!!

    author
    ErikL77 (author)2017-04-16

    Can someone point me in the right direction how to make this work with Domoticz?

    author
    ErikL77 (author)ErikL772017-04-17

    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.

    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?

    author
    AntonK67 (author)ErikL772017-05-09

    Hi, trying to make it work with domoticz, can you please ggive some tips on how to make it work with htt requests?

    author
    AntonK67 (author)2017-05-05

    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!

    author
    AntonK67 (author)2017-05-02

    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?

    author
    VictorS237 (author)2017-04-03

    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.
    Im stuck at the motor is only "burring" part :)

    author
    juhaaa (author)2017-03-22

    Of course i´ve ordered wrong parts. NodeMcu V3 having different measures than V2.. It´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?

    2017-03-22 10-01-59 f0fa2988.jpeg2017-03-22 10-03-24 afaf7196.jpeg2017-03-22 10-01-17 14d7ef0a.jpeg
    author
    ygreq (author)juhaaa2017-03-31

    mee too! ;)) Did not try yet but I hope I fixed with a diy PCB bridge

    author
    gadu74 (author)2017-03-19

    The stepper gets really hot, is it the same for you?

    author
    ColinH4 (author)2017-02-19

    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 :-)

    author
    ehsmaes (author)ColinH42017-02-25

    I uploaded the design files to thingiverse. Please post a remix if you decide to use them. Enjoy!

    author
    ColinH4 (author)ehsmaes2017-02-27

    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.

    author
    techydiy (author)2017-02-13

    Like it!

    author
    ehsmaes (author)techydiy2017-02-25

    thanks!

    author
    eybr (author)2017-02-24

    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.

    author
    ehsmaes (author)eybr2017-02-25

    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.

    author
    BoyanB (author)2017-02-20

    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

    author
    ehsmaes (author)BoyanB2017-02-25

    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.

    author
    16jwilliams (author)2017-02-16

    cool idea I love it

    author
    ehsmaes (author)16jwilliams2017-02-25

    Thank you!

    author
    arturmora (author)2017-02-15

    Woww! I always wanted one of these. Great job!

    Can you add a bluetooth shield to control through the smartphone?

    author
    ehsmaes (author)arturmora2017-02-15

    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

    author
    CliffK (author)2017-02-15

    Can I use a Wemos D1 mini instead of nodemcu?

    author
    ehsmaes (author)CliffK2017-02-15

    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

    28,041views

    193favorites

    License:

    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 BlindCheap 3D Delta Printer ImprovementsMotorize IoT with ESP8266
    Add instructable to: