Saturday 22 June 2013

Automated / Motorized Curtains with a Raspberry Pi Part 1 - Smart Home Part I

Its waaaay to much effort to open curtains yourself, so why not get your Pi to do it for you? And thats exactly what I did. Luckily I already had all the parts I would need to build it, which is why I chose motorized curtains as the first port of call on my smart home list.

I salvaged some parts from old printers earlier this week, yielding some rather good motors and gears besides other good parts like IR optical break sensors. The only other major things I needed was my Pi, a motor driver (see previous posts for that) and some software to drive it all, oh and of course the curtains! (plus electrical tape, no project is complete without a bit of tape ;) ).

First off, to start any smart home project, you need a stable way to control all your devices. Hardware and software. Before I started any hardware, I wrote a little python script using the python library that comes with the new update of WebIOPi 0.6.0, and a webpage to go with it. The python code can be made to be executed at boot, hosting the server which is the back end of the system. This server also hosts the webpage which gives the front end to the whole system. The webpage has a secure log in to increase security and to stop other people using it.


Once logged in, you have access to the main page where you can control the system. In order for this to work, your browser must support JavaScript (or have it enabled), which is pretty good as most browsers support this so I can control it via my phone too! (Note: Make app in future!)


Open is for starting the motor which pulls the curtains open. Close does the opposite, and stop stops both motors (even though it isn't possible to have both on at once with this, because then it enables H-Bridge use). Code for this is taken from the demo code from the makers of WebIOPi (http://webiopi.googlecode.com) and from Issues 9 and 10 of the MagPi magazine. I ended up re-writing a fair lot of it to fit my ideas. (Eventually, the buttons will enable the motor when held down, like a pulse). The code I used can all be found over at my GitHub Repo. (https://github.com/Jamie-/SmartHome) (The webpage UI over at GitHub looks slightly different to the screenshot above, but does exactly the same thing)

Part 2 will be up at some point, as the curtains came down, they have gone for a wash so I'm waiting on them to post about the hardware side of things, as this post is mainly software based.

Jamie

No comments:

Post a Comment

Thanks for your comment! If it's a query or question, I'll try to get back to you as soon as I can. I hope this blog has helped or inspired you!