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
- NodeMCU 1.0 (aka V2) development board: http://www.gearbest.com/transmitters-receivers-mo...
- Motor shield: http://www.gearbest.com/boards-shields/pp_340732....
- Geared stepper motor 28BYJ-48: http://www.gearbest.com/other-accessories/pp_2311...
- Micro switch: http://www.gearbest.com/development-boards/pp_156.... Please note that if you want to use the printed electronics box you need to get these exact switches or same dimension ones. The lid has a socket modeled after this particular switch.
- M3x8 hex socket allen screws
- MicroUSB-cable for power and programming and any USB phone charger
- 3D printer (or printing service)
- M3 knurled brass inserts M3x5x4: http://www.ebay.com/itm/252468136038
- IKEA roller shade Tupplur (or any roller shade with compatible inner radius): http://www.ikea.com/us/en/catalog/products/603091...
- Some wires, soldering equipment and basic skills
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:
- Register at CludMQTT: https://www.cloudmqtt.com/
- Creat a new broker instance
- Click the instance info and keep the info handy
- For testing purposes, download MQTT.fx: http://mqttfx.jfx4ee.org/
- Add a profile to MQTT.fx with the credentials from your newly created cloud broker.
- 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.
- 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
- 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.
- Download Flash tool: https://github.com/marcelstoer/nodemcu-pyflasher/...
- Flash the firmware using the flash tool
- Run the tool
- Connect the NodeMCU holding the flash button
- Select the serial port
- Select the firmware file
- Press Flash
Install the rollerblind code
- Download the roller blind code here: https://bitbucket.org/ehsmaes/motor_rollerblind/s...
- Download ESPlorer IDE: https://esp8266.ru/esplorer/
- Open Esplorer
- Select the serial port
- Connect
- Open all the lua files
- Edit settings.lua and enter WiFi and MQTT settings
- Upload all lua files (Save to ESP)
- 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):
- Heat the soldering iron to about 200 degrees C (400 F).
- 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).
- Remove the lever from the micro switch
- Loosen the plastic hinge on the lid button (gently push it out and back in)
- Push the micro switch in place
- Push the motor shield into place
- Insert the motor
- 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:
- Long press the button (> 2s)
- The shade starts going down
- When the shade reaches desired bottom position, short press
- When the shade reaches derired top position, short press again
- 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.
- Install and configure the openhab according to their instructions
- Install MQTT binding
- Configure MQTT binding for your previously configured broker (local or cloud)
- 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

Runner Up in the
Microcontroller Contest 2017
156 Comments
5 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.
Reply 5 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.
3 years ago
cloudmqtt disabled their "Cute cat" plan, so it is no longer free, is there a free alternative to use?
Reply 1 year ago
You could always host your own MQTT server using Mosquitto. Can run on Windows, Linux, or Mac!
2 years 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!
Question 2 years 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.
Question 2 years 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?
Answer 2 years 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
Reply 2 years ago
If you have motor shield you must to connetc two out of three pins on this borad between switch and VIN/GND sockets.
Tip 5 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
Reply 2 years 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 ... ;-)
Question 2 years ago on Step 9
Question 5 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â
Answer 5 years ago
Same here, i cannot figure out the solution for this. Can anybody help?
Reply 2 years ago
I'm stuck at the same place, my button press cause my device to crash and reboot. 3 years later, anybody?
Question 5 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?
Answer 4 years ago
Same here. Did you manage to find the problem?
Reply 2 years 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.
2 years 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.
Question 2 years 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.