Inexpensive motorized shades are the holy grail for DIY smart home enthusiasts. Many have tried and many have failed to produce a product that is comparable to the multi-thousand dollar shades offered by the big name automation companies.
Making a successful project starts with picking the right materials for the job.
The following are the materials I used:
These stepper motors and drivers are not only super high quality but also relatively inexpensive.
This driver has 3 pins that need to be connected to your microcontroller:
The OPTO pin needs to be powered by 5V to power the optoisolator LEDS. You’ll also need to make sure that your board and your driver share a common ground.
Since a stepper motor needs to have a relatively large current pulsed rapidly, you’ll also need a stepper motor driver to handle the heavy lifting. I used the DM320T driver because it can provide controlled current levels at fairly high voltage.
For a microcontroller, I used an ESP8266 based node-mcu because I’m very comfortable with them. But any ESP8266 based microcontroller would work.
Next, you’ll attach the 4 wires of your stepper motor to the driver. The black wire connects to A positive, Green to A negative, Red to B positive and Blue to B negative and attaches your 12V power supply to Vdc and Ground.
Let's talk briefly about the important differences between a stepper motor and a normal DC motor. When you apply current to a DC motor it spins in one direction, raise the voltage and it spins faster, flip the polarity and it spins in the opposite direction. Those are all useful things, but one thing you can’t do with a DC motor is move it to a specific location and lock it in that location.
That’s where a stepper motor shines. A stepper motor uses 4 wires instead of 2. Applying current to two of those wires will advance the motor exactly 1 step. If I want it to go to the next step, I’ll need to apply current to the other two wires. The motor we selected has a step angle of .35 degrees, which means every step rotates the shaft by only .35 degrees.
This is really useful information when we consider that this will allow us to know the exact amount that our shades have been rolled down at any given time. For this specific case, we know that we’ll need to do 1028 steps in order to move 360 degrees without using microstepping.
The decision to use a planetary gear is just as important as the decision to use a stepper motor. Planetary gears allow us to amplify the torque of the stepper motor by a factor of 5 in this case, and that’s important because it means that a less torquey stepper motor will still be able to supply the needed rotational force to roll the shades up and down, but the other reason it is important is that it also makes it 5 times more difficult for the weight of the shades to rotate the shaft of the stepper which will prevent slippage between steps.
Before we plug it in, let's double-check that our dip switches are in the right place. Our stepper motor is rated for 1.68 amps, so we’re going to set the current limiting driver to 1.34 amps RMS just to make sure we don’t overload our motor. We also want to set the resolution to 800 pulses per revolution.
This means our dip switch setup is going to on off off, and off on on.
To test it I’d recommend turning the shaft of the motor manually before you plug it in to line it up with one of the screws we want to make sure that our motor moves in full rotations, so send your motor a command to move 13 full rotations and if it rotates 13 times and ends up in roughly the same position that it started you’re ready to install.
Mount the brackets loosely on either side of the shade and slide the mounting hub onto the stepper motor shaft. Once everything is in place, slide the brackets closer together to make everything fit nicely, and tighten the mounting bracket screws.
If everything went according to plan you’re done and you should be able to control your shades via MQTT! Test it out by sending different values to the shades.
Let’s talk briefly about the code. My code is fairly simple and utilizes the AH_easydriver library for stepper motors. The code is based on the fact that these shades will go from completely rolled to completely unrolled in 13 full rotations. Because I’m using a stepper motor I’ll be able to precisely control the number of rotations by sending a specific number of steps.
The great part about this code is it won’t get confused if you send it a new value before the old one has finished processing. If you find that your shades are rolling up the wrong way, you can just reverse the + and – wires for each of the A and B motor pairs on your driver and the motor will spin in the opposite direction.
And there you have it, a motorized shade for your smart home at a fraction of the cost of one of the major brands.