Motorized WiFi IKEA Roller Blind

53,964

239

123

Posted

Introduction: Motorized WiFi IKEA Roller Blind

Microcontroller Contest 2017

Runner Up in the
Microcontroller Contest 2017

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

    6 People Made This Project!

    Recommendations

    • Spotless Contest

      Spotless Contest
    • Science of Cooking

      Science of Cooking
    • Microcontroller Contest

      Microcontroller Contest
    user

    We have a be nice policy.
    Please be positive and constructive.

    2 Tips

    The board layout seems to have changed since this intractable was originally published.

    It's all in the comments somewhere, so here's a little heads up (thank you @ssvenn for helping me with this) I was confused because there is some explanation to the pictures, but no explanation as to why those steps are necessary.

    - You must (there's no way around this unfortunately) solder the wires to the motor shield and connect them to GPIO 2,3,6 and 7. Jumper wires help cut the soldering in half, but the chip is pretty tough, it's doable though

    - Remove the highlighted resistors and the transistor. According to ssvenn, if you want to power it with 9v, leave one of them in place (I don't know which one though). If you remove the highlighted ones, you're "stuck" with 9v

    - get a cheap buck converter and preferably some connectors to fit your power brick (like these https://www.amazon.de/gp/product/B019HAC6V4/ref=o... and integrate them into your box (basic 3d modelling skills required)

    - Attach one wire from the 9v output directly to VM, the other one to the buck converter and from there to VIN. Same for GND. Purpose of this being that you only need one power source, it is technically possible to still power it over USB and have the 9v. That's what I'm doing for testing purposes right now

    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

    7 Questions

    0

    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?

    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â

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

    Hi!

    Trying the "Dry-run" to see if the motor can spin but it seems that there is some issues when I change the GPIO pins for the motor. I have a custom made card where the pins are fixed to:

    * A: = GPIO 16

    * B: = GPIO 14

    * C: = GPIO 12

    * D: = GPIO 13

    stepper_pins = {16,14,12,13}

    Any tip on the error-message below?

    step_move(1000,FWD,2)

    stepper.lua:36: bad argument #1 to 'mode' (Invalid pin)

    stack traceback:

    [C]: in function 'mode'

    stepper.lua:36: in function 'pins_enable'

    stepper.lua:64: in function 'step_take'

    stepper.lua:91: in function 'step_move'

    stdin:1: in main chunk

    Never mind, my mistake in reading how the GPIO are named :-)

    stepper_pins = {0,5,6,7}

    0

    Hey. I finally received my parts today and couldn't wait to try everything but now I'm stuck.

    First off, I ordered the parts exactly as described, only difference being the manual switch which I picked up locally. I flashed it - check. Did the WiFi fix - check. WiFi connection established - check (according to my router) Ran it in ESPlorer - worked.

    However… the motor does nothing. When I enter the code in ESPlorer, the blue light lights up and goes off after a couple of seconds, giving me a confirmation that the new status is now X+/-25. But it doesn't rotate.

    I tried wiring it as depicted, then I changed it like it's described in the stepper.lua (A+ Pink, A- Blue, B- Yellow, B+ Orange, VH(?) Red) but it still doesn't move.

    I ordered two motors/boards since I have two blinds, neither of which works. Any ideas what I'm doing wrong?

    Yes, check out the tip I posted above as well as the pictures by ssvenn. You have to modify the motor shield - there's no way around it

    i have the same problem any ideas?

    0

    hi, some people seem to have this problem. I think there may be two variants of the driver board. I remember this (or a simial) problem with a solution months ago in the comments. There was a solution too. Unfortunately I couldn't find it right now but maybe you can!

    0

    I bought mine from Amazon last week. Did you do the same? I think next steps are to verify they can move at all using an arduino and the provided motor shield

    56 Comments

    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.

    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.

    I did have a lot of modifications but the biggest problem is the connection to shield. Do you know that there is a sot-26 I.C. next to the L293DD at least on my motor shield which I believe is the same than yours. The inverter I.C. changes the behavior of the L293. So D1 is connected to ENABLE1, D2 is connected to ENABLE2, D3 is connected to IN1 and inverted to IN2 and finally D4 is connected to D3 and inverted to IN4. I did figure it out When I connect my scope on the signal. Now I change your stepper.lua and I did have to swap two coils wire. Now I do have more torque and it is working way better. All the documentation I found point to the same thing https://legacy.gitbook.com/book/smartarduino/user-mannual-for-esp-12e-motor-shield/details

    04.png

    Ok I clone your code and made the modification to fix for my esp-12-e motor shield. I also fix some bugs like the missing module.step_ms in config.lua . the state==2 or 0 which force the system not to operate if your not fully close or open. Lua has a big problem with the speed of the stepper. I don't want my blind to take 15 mins to go down so I made a 'C' version. N.B. The wiring is different and check the .ino file to find the correct stepper wire color. B.T.W. the original source code has no licenses so I put M.I.T. on mine

    https://github.com/danjperron/ESP12EMotorShieldRol...

    Hi,

    a great job. thank you for your tutorial.

    Do you know the consumption of this installation ?

    I ask it because I want to know if it should be power with a small pocket solar powerbank placed just on the concerned window. A 4000mAh

    Thanks you for your constructive answer.

    my motor only buzz and no turn. what i do wrong?

    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

    I have. I just flash the firm downloaded from nodemcu-build.com (any of the two you are gona get) with nodemcu flash, here is the link for the osx version, the one in the tutorial is incomplete:

    https://github.com/marcelstoer/nodemcu-pyflasher/releases

    Then, when you have flashed the firm, you need the ESPlorer (it runs on java) and you can open, edit and flash every file of the code in the board.

    I hope it helps

    Have you find a solution to flash the board on a mac?

    Did you guys see this post? https://diyprojects.io/esptool-update-of-firmware-nodemcu-esp8266-on-macos/ Maybe useful. I haven't tried it myself though.