UPDATE 14-01-2016 -I've now also shared the MIT app inventor 2 app file for those who want it.
Hello boys and girls!
Feeling like making something today? Own a 3d printer but mostly been printing phone cases, miniature yodas, toothbrush holders and spare parts? Now its time to really make good use of that 3d printer and make a useful and fun product that nobody else have!
What we'll be making today are fully automatic app controlled blinds.
Why? Because we can. And it's also quite handy and cool.
It can be particularly handy if you have many blinds, in cumbersome positions such as ceiling windows or if you pull them up and down often (sun on computer screen, using a projector and so on).
But the main reason for me was that I prefer to sleep in complete darkness but waking up in the same complete darkness makes me tired and glues me to the bed in the morning. This is where the app comes handy.
When i set my alarm at night I also set the timer of the blinds, I usually set it 15 minutes before my alarm so when I wake up the room is full with daylight. Pretty nice.
Step 1: General Outline of Project
Skills needed for this project.
- Basic knowledge of electronics and experience from a couple of arduino projects. I will not go into detail on how to solder a cable or what you should connect your GND cable to.
- Basic CAD skills. Depending on your window/wall you might have to adjust one of the parts so it suits your needs. I will share a general mounting bracket for this which you can adjust to your needs. The last thing you will need to make yourself is the control box. Depending on how many blinds you wish to control, the components you want use and where you want to place them (wall, floor..) will make it impossible to find one component housing that will fit all solutions. This box however doesn't have to be near the blinds so it can be hidden, so it doesn't really matter what it looks like.
Before ordering any parts make sure you have;
1. Android phone with Bluetooth
2. Soldering iron
4. About a day to print, build and install this. Best case scenario is about 2-3 hours but those scenarios are quite rare.
Got it? Good! Start by downloading my app and install it. You might have to go into settings and enable apps from unverified sources or something similar. Nothing fishy with the app, promise. Start the app. Does it start and displays "Connect to bluetooth"? Good! Now we know it works on your phone before you order any parts!
How it works
Before we jump into the details I want give you a rough outline of how it works.
We will use cheap ikea blinds but replace the mounting brackets with our own. One of them will only hold the curtain in place and the other one will house a step motor which will rotate the curtain axle.
This step motor will be connected with a cable to the component box placed on the ground or wall containing stepmotor drivers, Bluetooth receiver and a arduino.
When the user starts the app it will connect to the Bluetooth device. The first thing the user does is to calibrate the blinds (this only needs to be done once). This process will start to roll down the blinds and when they are fully extended the user presses "stop calibration" in the app.
Now the arduino knows how much to be rolled in/out every time. (so you don't have to stop it manually).
I mentioned earlier that there is also an alarm. When you set the alarm time the app will also set the current time to the arduino so it can keep track on the time without the being connected to your phone. This means you can turn off the app/bluetooth/phone after you've set the alarm and it will still trigger the alarm.
Sounds reasonable? Lets get going!
Step 2: Parts
Parts you need
You can use components of your choosing, just make sure you use a powerful enough Nema 17 sized step motor so it fits the mounting bracket. I had the parts laying around at home but the supplied links are equivalent. Dx is probably the cheapest site I know for electronics but delivery usually takes about a decade. If you want to get started asap i suggest you use another site.
Nema 17 Step Motor 17 $ (4800g-cm, 68-70oz-in, could probably use less)
Step driver 2A 6 $ (my setup never use more than 0.76A, make sure to check the temperature and use appropriate heat sink if needed)
Arduino Pro Micro 9 $
Roller blind Tupplur 20 $
Bluetooth receiver HC-06 7$
Connection cables, solderless breadboard, cat5/6 network cable to connect component box with motor bracket, power supply (i used an old 12v, 2A adapter)
4 M3 screws and suitable mounting screws for your wall type.
Total: 59 $
If you wish to extend the setup to several windows you need to buy x of each listed above, except the arduino and Bluetooth receiver which you only need one of each, so about 40 $ per extra window including blinds. If you decide to go for a more high current/dual step driver you can simply parallel connect the motors for two windows using the built in "cable channel" in the mounting bracket. This minimizes wiring and cost further, down to just a 17$ step motor per extra window.
Step 3: Start Printing the Parts
Okay we're going to let the 3d printer fulfill it's destiny while we work on the electronics.
1. Start by printing the motor mounting bracket (Motor_bracket.stl). Place the bracket with the screw holes touching the bed. Most printers should be able print this without support structures despite the small overhang near the top. If yours can't, print with supports and remove afterwards.
2. Print the cover (cover.stl). To minimize support structures you can print it standing.
3. Print the axle mount (Axle_mount.stl). Preferably with the largest diameter facing the bed.
4. Print the wall mounts. (Motor_bracket_wall_mount.stl and Wall_mount). The motor bracket wall mount is the one I've used due to the shape of my "window frame". Depending on how yours look you will probably reshape this file. If your surface is flat you can just extrude the backside so it has the same thickness. Note. Do not cut away the "thick part" it needs to be there (a screw will go in there later).
Check fitting & Mount the parts
When everything is ready make sure the parts fits together.
1. Insert motor into bracket and use 4 M3 screws to lock it.
2. Test the cover, does it slide on properly?
3. Now we're going to fix the axle_mount to the motor shaft. Slide a nut into the hole and screw in a screw from the side to fix it. Now press the axle mount into the blinds axle. It should be a really tight fit. When pushing it in, only push on axle_mount outer ring, not the motor housing as this might damage your motor.
4. On the other side of the axle is a plastic insert from ikea. We will keep this one, but drill a hole in it's center and push through a screw. This screw will go inside the Wall_mount and serve as our axle. Find a screw that fits the hole in the Wall_mount. It should provide some friction when rotating. If you don't have enough friction at this point your blinds will unroll themselves in the top position when the motor turns off. Too much friction and the motor wont be able to roll up the blinds. You can put rubber bands or paper around your screw to increase friction if needed. (initially i put a mini ball bearing in mine which allowed my blinds to accelerate to near lightspeed when the motor was turned off and snap off the brackets.).
Put nuts on the screw, on each side of the plastic insert, so you can fine tune the position later. Measure carefully how the whole assembly should be placed, drill holes and mount it.
All working? Great!
Now remove the motor housing and the motor, we need to test everything before we start attaching long cables to our walls.
Step 4: Connecting Power and the Step Driver
Now pull out your solderless breadbord! No need to solder or make fancy connections at this stage, first we only want to check that everything works.
I will not go into so much detail with the electronics and the app, I assume you know your stuff and also may have different components than I have. I will just explain what goes where.
Power to arduino (Assuming you have 12 V, 2A power supply )
You will power your step driver and arduino separately so make a parallel connection (4 cables) with your supply. GND1 to arduino gnd, VCC1 to VI on arduino (voltage in, not 5 V if you don't use 5 volt supply!).
Depending on what step driver you have, you may have a pin called "sleep". When we´re not using the blinds we will either set the driver to sleep or turn them off to keep power consumption down. In this project we will not use the sleep feature but instead turn the driver on and off just before we use it (in case your driver doesn't have the sleep feat). Waking the driver from sleep is faster than starting it, its usually around 1 ms but in our case that's not necessary.
Power to motor
See the attached image. We're going to start with our 12V supply. Connect VCC2 and GND2 to VMOT and GND. You can (should) also connect a 100uF capacitor between them.
Okay now the motor have power. Now we supply the driver with power!
Power to driver
Connect the other GND (the lower one in the image) to your GND. The VDD pin will power up the driver, this is the one we will turn on and off. Connect this to pin 16 on your arduino.
Okay step driver have power. Now we´re gonna give it some signals to work with.
Connect DIR to pin 14 on arduino. Connect STEP to pin 15 on arduino. Depending your step driver you might have pins like MS1, MS2, MS3. These are for "microstepping", this process enables your motor to make smaller steps. We're not interested in this as 200/400 steps per rotation is already above our needs. Microstepping usually enables by connecting the pin(MS1, MS2...) to VCC or GND. Check your stepper data sheet. Be wary that using smaller step might give you less torque (and might overflow the int variable in the code by counting super many steps).
Step motor signals
Okay we're now going to make a temporary connection between the driver and the step motor. This is to make sure everything works before we continue.
Since different steppers use different colors on the cables I will describe a method that works for all steppers. What we want to know is which cable goes where. The four cables are in pairs, two per coil (the motor have 2 coils). The easiest way is to take either a multimeter or a LED and connect them to two pins. Now rotate the motor shaft, if the multimeter reads a voltage you´ve found a pair! If you use a LED it will light up, make sure you switch the pins if it doesn't work (as LEDS only allows current to flow in one direction).
Now connect them in pairs to the stepper. Pair 1 goes to 1B, 1A and pair 2 to 2A, 2B. Later when we test them, if you discover that they rotate in the wrong direction you can change the position of the pairs.
Calculating the current and adjusting the Vref
Depending on you step driver type, check out this url or check your datasheet.
If you plan to use one driver and two motors, make sure to calculate the parallel resistance of the motors or you might burn your driver!
Brief explanation how it works
Arduino writes HIGH to the STEP pin for 500 micro seconds, delays and writes again repeatedly. The stepper interpenetrates this signal and activates the coils in the step motor in a sequence to make it rotate 1 step.
The DIR pin is either HIGH or LOW depending on which direction we want the stepper to rotate.
If your motor is freaking out and all the connections are correct you might want to try changing the 500 micro seconds to a higher/lower value in the arduino code.
Not working at all or is the motor just making weird sounds?
- If you rotate the step motor shaft by hand (disconnect power first) it should rotate freely and it should feel "clicky", one "click" is a step. If it doesn't you might have a faulty motor.
- Check connections, check connections, check connections.
- Check the step driver datasheet. First check if you've connected the phases correctly. Then check if you need to ground one of the microstepping pins (MS1, MS2...). Check if you can adjust voltage on the driver and do this very carefully, making sure only to touch the adjustment screw with your screwdriver (risking to short circuit the driver if you're not careful). Lastly check if it has a built in current limit that's somehow set too low.
- Change the write period in the arduino code (the 500 us part) or the delay time after the write.
- Still not working? Check with a multimeter or oscilloscope if you have access to one. Whats happening between the driver and motor? Whats happening between the arduino and the driver, are the pins writing correctly?
- Remove all connections, have a cup of coffee and assemble again. (works surprisingly often)
- Send me a message and I'll see if I can help.
Step 5: Connecting Bluetooth Device
Okay, time to go wireless
Connect gnd and vcc on your bluetooth device to your arduino (3.3V or 5 depending on your device). Connect bluetooth TXD to arduino RXD and bluetooth RXD to arduino TXD.
Using these pins can sometimes cause problems when uploading sketches to arduino (as they are data communication pins). If you get a problem while uploading, disconnect the power to the device using these pins and it should work.
Upload the sketch
Okay its time for the fun part, begin by downloading the sketch. If you don't have the time libraries, download them and put them in your arduino/libraries folder.
If you don't use the arduino micro pro you need to replace all "Serial1.." with simply "Serial..". If you use the micro pro you don't have to change anything.
Upload the sketch, connect your power supply, turn on bluetooth on your phone and start the app. Connect to bluetooth and click on the device in the list. If it connects properly new menus should appear. Click "Calibrate", your motor should start rotating. If you click "raise/lower blinds" before calibration nothing will happen. Calibration sets the number of steps of a full cycle, before calibration that is equal to 0.
Hopefully everything worked, otherwise check your connections.
If you have the sun straight through your window in the mornings you might want the roll up process to be super smooth and slow, perhaps during 30 minutes or so, more like the Philips Wake-up light-experience. If that's the case you can change this;
In the void MorningAlarm(), after "steps++;" add delay(10). So after each write to the step driver, it delays the next step with 0.01 s. Start with this and increase the delay until you're happy. Your stepper will probably have 200-400 steps for each full turn so this value should be really low!
A smarter but more complicated way to set this time is to serial print the "steps" value after you have calibrated the blinds. Then you'll know how many steps its taking for a full cycle and can do division on how much time it needs to pause per step to end up at 30 min or what ever value you wish. You could also manually roll down the blinds and count how many turns it takes and multiply with your steppers value (usually 200/400).
Remember that longer delays are "ugly", they freeze the microcontroller completely, not being able to receive important commands like stop, so avoid using repeating delays longer than 300 ms. You can use millis() or the time library if you need longer pauses.
Step 6: Putting the Pieces Together
Okay now we know everything works its time to make it permanent.
Design a little simple casing for your arduino + other stuff and mount on the wall or just on the floor. Connect the step motor driver and motor with a cat5/6 (network cable) of the appropriate length. You can use any 4 pin cable but most people have them laying around and they come in a nice package. Remove the 4 ends you don't need and connect the other ones to the motor and driver, make sure to remember which ones goes where!
I used RJ45 connectors on my cables (regular network cable connectors) and females in my component box. In hindsight it just wasn't worth it, clamping those connectors can be very annoying and the box is placed under my sofa anyways :D
First test in position.
Before you test drive it, pre drill a small hole in the motor wall mount and and use a small wood screw to secure the motor housing and wall mount together. If you don't do this your motor housing might get ripped out if the blinds roll down too fast.
Now that everything is locked into place we can finally test it. When calibrating make sure you press "stop calibration" exactly when your blinds are fully extended. If you stop before that, the blinds will roll down completely as soon as the motors turn off risking to break your mounts. If you for some reason don't want your blinds to extend fully, cut off a part of your blinds and glue it back on the cylinder.
If everything worked nicely you're done! Now make it permanent and good looking by soldering it together and placing the parts in the component box.
Good job and I hope you will enjoy using the blinds!