{"id":2641,"date":"2015-04-03T14:40:06","date_gmt":"2015-04-03T14:40:06","guid":{"rendered":"http:\/\/www.knightware.net\/?p=2641"},"modified":"2015-04-03T14:40:06","modified_gmt":"2015-04-03T14:40:06","slug":"garage-door-opener-project-part-1","status":"publish","type":"post","link":"https:\/\/www.knightware.net\/?p=2641","title":{"rendered":"Garage Door Opener Project: Part 1"},"content":{"rendered":"<p>So a few weekends ago I\u00a0decided that I&#8217;d like to embark on a fun project of making a network enabled garage door opener.\u00a0\u00a0A few weeks ago I was walking home from a neighbors, and found myself wishing I could open the garage from my phone, or ideally from my <a title=\"Band\" href=\"https:\/\/www.microsoft.com\/microsoft-band\/en-us\" target=\"_blank\" rel=\"noopener\">Band<\/a>.\u00a0 This seemed\u00a0like enough of a pretense to embark on a new project, and after a few weeks of\u00a0tinkering I&#8217;ve emerged\u00a0with the following working home accessory:<\/p>\n<p><iframe loading=\"lazy\" src=\"https:\/\/www.youtube.com\/embed\/BQUbMMrSyMw\" width=\"560\" height=\"315\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/p>\n<h1>The Plan<\/h1>\n<p>When I started this project, I laid out a few key requirements:<\/p>\n<ol>\n<li>Build an application targeting\u00a0an existing Wi-Fi enabled <a title=\"Raspberry Pi\" href=\"https:\/\/www.raspberrypi.org\/\" target=\"_blank\" rel=\"noopener\">Raspberry Pi <\/a>I had laying around.<\/li>\n<li>Build and debug\u00a0the application on the Pi,\u00a0and write it in modern\u00a0C++.<\/li>\n<li>Setup Git on the Pi, and keep the code up in <a title=\"Github\" href=\"https:\/\/github.com\/dsmithson\/GarageDoorApp\" target=\"_blank\" rel=\"noopener\">GitHub<\/a>.<\/li>\n<li>Breadboard\u00a0the hardware required to switch the garage light and door.<\/li>\n<li>Integrate\u00a0a temperature\/humidity sensor to allow me to play with garage cooling options over the upcoming\u00a0summer months.<\/li>\n<li>Add a garage door closure sensor so the device can tell when the door is open or closed, so the app can provide open\/closed\u00a0status back to network clients.<\/li>\n<li>Integrate my X10 Firecracker dongle, to allow me to control my existing X10 outlets\/lights<\/li>\n<\/ol>\n<p>The C++ requirement came partly from a desire to tackle a &#8216;real&#8217; project with the language using modern language\u00a0features like smart\u00a0pointers, and to try out some of the Boost library&#8217;s programming constructs for asynchronous networking.\u00a0 I&#8217;ve\u00a0also been playing around with\u00a0building basic electronic circuits, and making some necessary hardware\u00a0for the Pi seemed like a fun time.<\/p>\n<h1>The Hardware<\/h1>\n<p>It took a while to get the electronics working, and I learned a decent amount along the way (even though there really isn&#8217;t much to this).\u00a0 I started trying to\u00a0trigger my\u00a03.3v relays directly using the GPIO pins on the Pi, and when that didn&#8217;t work I had to go back and figure out that\u00a0GPIO pins\u00a0can&#8217;t drive the level of\u00a0current required.\u00a0 I was also using a shift register initially to reduce the number of pins coming off of the Pi, but it ended up being unnecessary and was eventually removed.<\/p>\n<div id=\"attachment_2651\" style=\"width: 635px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.knightware.net\/wp-content\/uploads\/2015\/04\/WP_20150216_18_48_33_Pro.jpg\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-2651\" class=\"wp-image-2651 size-large\" src=\"https:\/\/www.knightware.net\/wp-content\/uploads\/2015\/04\/WP_20150216_18_48_33_Pro-1024x576.jpg\" alt=\"\" width=\"625\" height=\"352\" \/><\/a><p id=\"caption-attachment-2651\" class=\"wp-caption-text\">Testing first iteration using shift registers<\/p><\/div>\n<p>&nbsp;<\/p>\n<p>The second iteration two introduced some diodes and transistors, and then I was up and running.\u00a0 I added a couple momentary contact switches to provide local light and door control, and picked up some DHT11 to do my temperature\/humidity sensing.<\/p>\n<p>I put everything together on\u00a0a breadboard, with a plan to solder everything together and put it into a clean enclosure with my couple of surface mounted switches, but I quickly fell in love with the idea of just putting an acrylic top over it, and mounting the Pi and breadboard together on another sheet of acrylic (spray painted black on the back), as-is.\u00a0 It has a fun look to it, and that might be what I like about the whole project most.<\/p>\n<div id=\"attachment_2661\" style=\"width: 635px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.knightware.net\/wp-content\/uploads\/2015\/04\/WP_20150309_22_27_34_Pro.jpg\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-2661\" class=\"wp-image-2661 size-large\" src=\"https:\/\/www.knightware.net\/wp-content\/uploads\/2015\/04\/WP_20150309_22_27_34_Pro-1024x576.jpg\" alt=\"Second iteration of electronics using transistors, diodes, and opto-couplers\" width=\"625\" height=\"352\" \/><\/a><p id=\"caption-attachment-2661\" class=\"wp-caption-text\">Second iteration of electronics using transistors, diodes, and opto-couplers<\/p><\/div>\n<p>The one part that sadly hasn&#8217;t made the cut yet is the <a title=\"X10 Firecracker\" href=\"https:\/\/www.x10.com\/cm17a.html\" target=\"_blank\" rel=\"noopener\">X10 firecracker<\/a>.\u00a0 This is a control device I used to have connected to my PC (back when I had a serial port), which\u00a0works in conjunction with a\u00a0wireless receiver to send\u00a0On\/Off power commands to outlets and switches throughout my house.\u00a0 I found and installed an RS-232 shield\u00a0on the\u00a0Pi, but later found out that it doesn&#8217;t connect the RTS\/CTS lines\u00a0used to power and signal the Firecracker.\u00a0 Oh well, I&#8217;ll think of something in the future&#8230;<\/p>\n<h1>The Software<\/h1>\n<p>I chose <a title=\"CodeBlocks\" href=\"https:\/\/www.codeblocks.org\/\" target=\"_blank\" rel=\"noopener\">CodeBlocks <\/a>as my IDE of choice on the Pi, after seeing a few recommendations online for people coding in C++ on the Pi.\u00a0 I was able to target C++ 11 features, and although it took a while to figure out how to get the Boost libraries to link up to my project, the process wasn&#8217;t too bad.\u00a0 In general, however, I wouldn&#8217;t recommend that people try to write code directly\u00a0on the Gen 1 Raspberry Pi, at least when you&#8217;re trying to do it using an IDE on top of x-windows.\u00a0 It&#8217;s really slow, not only when trying to compile (which takes a long time even for trivial programs), but even typing code into the editor is noticeably delayed.\u00a0 I eventually started writing and testing as much as I could in Visual Studio, and then bringing the code files over to the Pi for final testing and implementation.\u00a0 For final debugging\/testing I eventually ended\u00a0up editing files using VI over SSH to skip the UI overhead on the PI, and that seemed much more usable.<\/p>\n<div id=\"attachment_2681\" style=\"width: 635px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.knightware.net\/wp-content\/uploads\/2015\/04\/Running-CodeBlocks-on-Pi.jpg\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-2681\" class=\"wp-image-2681 size-large\" src=\"http:\/\/www.knightware.net\/wp-content\/uploads\/2015\/04\/Running-CodeBlocks-on-Pi-1024x576.jpg\" alt=\"Running CodeBlocks on the Pi\" width=\"625\" height=\"352\" srcset=\"https:\/\/www.knightware.net\/wp-content\/uploads\/2015\/04\/Running-CodeBlocks-on-Pi-1024x576.jpg 1024w, https:\/\/www.knightware.net\/wp-content\/uploads\/2015\/04\/Running-CodeBlocks-on-Pi-300x169.jpg 300w, https:\/\/www.knightware.net\/wp-content\/uploads\/2015\/04\/Running-CodeBlocks-on-Pi-768x432.jpg 768w, https:\/\/www.knightware.net\/wp-content\/uploads\/2015\/04\/Running-CodeBlocks-on-Pi-1536x864.jpg 1536w, https:\/\/www.knightware.net\/wp-content\/uploads\/2015\/04\/Running-CodeBlocks-on-Pi.jpg 1921w\" sizes=\"auto, (max-width: 625px) 100vw, 625px\" \/><\/a><p id=\"caption-attachment-2681\" class=\"wp-caption-text\">Running CodeBlocks on the Pi<\/p><\/div>\n<p>I have the project checked into GitHub, and you can <a title=\"check it out here\" href=\"https:\/\/github.com\/dsmithson\/GarageDoorApp\" target=\"_blank\" rel=\"noopener\">check it out here<\/a>.\u00a0 With any luck I&#8217;ll actually come back and check in some schematics for the hardware portion of the application, but for now at least the software is up there in case the Pi dies in the extreme heat of my garage over the summer.<\/p>\n<h1>Trying it Out<\/h1>\n<p>I was pretty excited the first time I was able to trigger the door and light manually using the new Pi-based controller, and even more so when triggering it from my desk.\u00a0 The design has two LEDs, one that blinks on\/off at roughly a one second interval, and one that lights red when the door is open.<\/p>\n<div id=\"attachment_2691\" style=\"width: 671px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.knightware.net\/wp-content\/uploads\/2015\/04\/talking-to-the-door.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-2691\" class=\"wp-image-2691 size-full\" src=\"http:\/\/www.knightware.net\/wp-content\/uploads\/2015\/04\/talking-to-the-door.jpg\" alt=\"\" width=\"661\" height=\"418\" srcset=\"https:\/\/www.knightware.net\/wp-content\/uploads\/2015\/04\/talking-to-the-door.jpg 661w, https:\/\/www.knightware.net\/wp-content\/uploads\/2015\/04\/talking-to-the-door-300x190.jpg 300w\" sizes=\"auto, (max-width: 661px) 100vw, 661px\" \/><\/a><p id=\"caption-attachment-2691\" class=\"wp-caption-text\">Talking to the garage door using Putty<\/p><\/div>\n<h1>What&#8217;s Next?<\/h1>\n<p>In the next post, I&#8217;ll cover writing\u00a0Windows Phone and hopefully a \u00a0Microsoft Band apps to talk to our garage door.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>So a few weekends ago I\u00a0decided that I&#8217;d like to embark on a fun project of making a network enabled garage door opener.\u00a0\u00a0A few weeks ago I was walking home from a neighbors, and found myself wishing I could open the garage from my phone, or ideally from my Band.\u00a0 This seemed\u00a0like enough of a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2641","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.knightware.net\/index.php?rest_route=\/wp\/v2\/posts\/2641","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.knightware.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.knightware.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.knightware.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.knightware.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2641"}],"version-history":[{"count":0,"href":"https:\/\/www.knightware.net\/index.php?rest_route=\/wp\/v2\/posts\/2641\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.knightware.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2641"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.knightware.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2641"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.knightware.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2641"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}