Motorized WiFi IKEA Roller Blind

232,215

482

155

Introduction: Motorized WiFi IKEA Roller Blind

About: 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 with home improvement or a tech project or a combination of the t…

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
    Microcontroller Contest 2017

    Runner Up in the
    Microcontroller Contest 2017

    8 People Made This Project!

    Recommendations

    • One Board Contest

      One Board Contest
    • Anything Goes Contest 2021

      Anything Goes Contest 2021
    • Jewelry Challenge

      Jewelry Challenge

    155 Comments

    0
    paulham
    paulham

    4 years ago

    I have an issue, when the blind goes down, the lights on my stepper driver stay lit. I do not think the power to the coils is being turned off.

    When the blind goes up, the lights turn off at the end and the power to the coils stop.

    Why would the power to the coils stay on when the blind goes down? I have looked at the code and cannot see any reason why.

    In the morning when the motor should open the blind it fails due to being really hot.

    0
    ehsmaes
    ehsmaes

    Reply 4 years ago

    In the original code I left one pin active when the blind is down. The reason was that I was having problems with gravity pulling the blind down further than I wanted if there was no power. In retrospect, keeping it powered was not the best solution. I belive I changed the code in the repo a while back so that it turns all pins off but I'm not sure. There are (at least) two much better ways to fix the gravity problem. 1) cut the blind (at the top) so that when it is down it is all the way out. 2) modify and use the original spring to counteract gravity. This was suggested by another reader. Remove the spring lock and put the spring on the opposite side from the motor.

    0
    kaiserclaw
    kaiserclaw

    8 months ago

    Is there any possibility to use a 12V motor instead of a 5V? Is it possible to connect 12V directly to the board or do you have to do something further?

    Thanks in advance!

    0
    przemas5172
    przemas5172

    Question 8 months ago

    Hello all, I allmost finish this project but I have a problem with stearing steper motor through mqtt. When I publish in MQTT.fx:
    /house/masterbedroom/rollerblind/0/set
    0
    In ESplorer i see new line of code:
    mqtt_start()
    /house/masterbedroom/rollerblind/0/set: 0
    UP!
    All looks great but stepper motor is not moving. Do you have any ideas what I doing wrong?
    Stepper motor during calibrating proces is working correctly.

    0
    tomas.mraz11
    tomas.mraz11

    Question 1 year ago

    Hello,
    I have tried to finish this project, i used Svenn github code and Lua version 1.54. Everything seems to work fine, however when I try to send step_move command, my motor just vibrates instead of moving.
    Wiring is connected the same way as on the pictures above. I am using USB cable connected to PC and ESP8266 to power up the setup.

    Some advice to fix this?

    0
    dr3men
    dr3men

    Answer 1 year ago

    Hello,
    The first is the wrong motor connection. I also encountered this when I cut the board inside the motor. I tried to make it more powerful, turn it into a bipolar one.

    In the code, Svenn prescribed what connects where. Check
    stepper_pins = {1,3,2,4} -- (A-)blue, (A+)pink, (B-)yellow, (B+)orange

    0
    przemas5172
    przemas5172

    Reply 8 months ago

    If you have motor shield you must to connetc two out of three pins on this borad between switch and VIN/GND sockets.

    0
    panicozxb
    panicozxb

    Tip 3 years ago on Step 4

    I have experimented problems with the wifi_setup.lua. Diving in internet I found a problem description like mine and also the solution.

    The solution was change the line 25 of the archive:

    wifi.sta.config(key,config.SSID[key])

    with this one:

    wifi.sta.config{ssid=key, pwd=config.SSID[key]}

    Now it's working. I can'ttake any credit for that, I'm completely newbie to this kind of code, the link I found is this one. If there is any problem with the solution, I'm sorry:

    https://stackoverflow.com/questions/46287888/error-in-code-lua-on-nodemcu

    0
    Pittiplatsch
    Pittiplatsch

    Reply 9 months ago

    OK ... I also found this error and solved it. Now comes the error message:

    wifi_setup.lua: 29: attempt to call field 'alarm' (a nil value)

    This has something to do with the "old" LUA command "tmr.alarm" (after the first googling).
    But no idea how to fix that. I've never done anything with LUA before and actually just wanted to work through this (actually very good) guide.
    Would be great if the author would revise the codes for the latest LUA environment ... ;-)

    0
    Gosseux
    Gosseux

    Question 11 months ago on Step 9

    I don't get the calibration step. It should be simple enough but the script isn't working for me. It doesn't detect the long press. Actually, it seems the length of the press is calculated by measuring the duration between two clicks. As soons as the button is press, the script runs, it doesn't wait for me to release the button. I red all the comments but nobody seems to have this problem which is a bad sign for me... Anybody has an idea? Also, I had to change the line 9 of the script `
    localprev_int_time, int_time, up_time = 0` to call all variables on different lines because I was having a PANIC error and the board was rebooting...
    0
    MichaelS1175
    MichaelS1175

    Question 3 years ago

    Any one else get the panic/watchdog reset all the time?

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

    ESP8266 mode is: 1

    MAC address is: 62:01:94:45:db:84

    IP is 192.168.0.149

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

    Warning, deprecated API! autoreconnect == 1 is deprecated. It will be removed in the next version. See documentation for details.

    PANIC: unprotected error in call to Lua API (button.lua:23: attempt to perform arithmetic on upvalue '?' (a nil value))

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

    wdt reset

    load 0x40100000, len 26524, room 16

    tail 12

    chksum 0x7e

    ho 0 tail 12 room 4

    load 0x3ffe8000, len 2184, room 12

    tail 12

    chksum 0x6b

    ho 0 tail 12 room 4

    load 0x3ffe8888, len 136, room 12

    tail 12

    chksum 0x97

    csum 0x97

    „âìƒoä›r‚ûo|ìdld$`cÛž|{’lœnà‚nâ

    0
    GregorČ
    GregorČ

    Answer 3 years ago

    Same here, i cannot figure out the solution for this. Can anybody help?

    0
    Gosseux
    Gosseux

    Reply 11 months ago

    I'm stuck at the same place, my button press cause my device to crash and reboot. 3 years later, anybody?

    0
    sarekk
    sarekk

    Question 3 years ago

    New to Lua...immediately upon Saving the init.lua file to ESP8266 (using ESPlorer on Win 7) I get an error and red light. lua: init.lua:13: attempt to call field 'exists' (a nil value). I looked at line 13 in the code and it refers to a file called; "cfg_tot_steps.lua". I cannot find that file anywhere in the Git. What am I missing?

    0
    DanielW354
    DanielW354

    Answer 3 years ago

    Same here. Did you manage to find the problem?

    0
    Gosseux
    Gosseux

    Reply 11 months ago

    Those files are suppose to be created when calibrating the device. When it fails at the beginning like that, it's because you have another problem (that was my case). I commented all that section (line 13-28) using "--". Than I could see where it was falling (in my case, either the firmware, or the wifi, or the mqtt connection, don't remember which)... However, don't forget to unccomment them later, because it will fail when trying to control the motor online.

    0
    MichaelP218
    MichaelP218

    1 year ago

    Hey, did anyone already work on controlling multiple blinds with one esp? i have 4 big windows in a row and think i will have to use an arduino instead esp.

    0
    trebory6
    trebory6

    Question 1 year ago

    How well does this integrate with Alexa?

    Can this be configured in OpenHAB to have different states? Looking to schedule a blind opening and closing at sunrise/sunset.

    0
    daniyo
    daniyo

    1 year ago

    Anyone have any idea which alternative IKEA roller blinds use this same mechanism? I bought the parts and most of them are here only to see that TUPPLUR is not on the website anymore... (I was waiting for them to get stock again).