{"id":12706,"date":"2021-04-04T20:27:55","date_gmt":"2021-04-05T00:27:55","guid":{"rendered":"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/?p=12706"},"modified":"2021-04-04T20:28:39","modified_gmt":"2021-04-05T00:28:39","slug":"clap-activated-light-switch","status":"publish","type":"post","link":"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/clap-activated-light-switch\/","title":{"rendered":"Clap-Activated Light Switch"},"content":{"rendered":"<h2 id=\"overview\">Overview<\/h2>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-12741 size-full\" src=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/30780D26-CE6D-4969-BC32-93976914C1AD-scaled.jpg\" alt=\"\" width=\"1920\" height=\"2560\" srcset=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/30780D26-CE6D-4969-BC32-93976914C1AD-scaled.jpg 1920w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/30780D26-CE6D-4969-BC32-93976914C1AD-225x300.jpg 225w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/30780D26-CE6D-4969-BC32-93976914C1AD-768x1024.jpg 768w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/30780D26-CE6D-4969-BC32-93976914C1AD-1152x1536.jpg 1152w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/30780D26-CE6D-4969-BC32-93976914C1AD-1536x2048.jpg 1536w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/30780D26-CE6D-4969-BC32-93976914C1AD-973x1297.jpg 973w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/30780D26-CE6D-4969-BC32-93976914C1AD-508x677.jpg 508w\" sizes=\"(max-width: 1920px) 100vw, 1920px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>I created a device that turns a light on and off whenever it hears you clap or snap, so I can turn off my light remotely.<\/p>\n<div id=\"attachment_12742\" style=\"width: 610px\" class=\"wp-caption alignnone\"><img aria-describedby=\"caption-attachment-12742\" loading=\"lazy\" class=\"wp-image-12742 size-full\" src=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/ezgif-2-fb1916ce65b9.gif\" alt=\"\" width=\"600\" height=\"1067\" \/><p id=\"caption-attachment-12742\" class=\"wp-caption-text\">GIF<\/p><\/div>\n<div id=\"attachment_12743\" style=\"width: 2570px\" class=\"wp-caption alignnone\"><img aria-describedby=\"caption-attachment-12743\" loading=\"lazy\" class=\"wp-image-12743 size-full\" src=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/7F879408-A0C6-4446-B075-0CBECA30A437-scaled.jpg\" alt=\"\" width=\"2560\" height=\"1920\" srcset=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/7F879408-A0C6-4446-B075-0CBECA30A437-scaled.jpg 2560w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/7F879408-A0C6-4446-B075-0CBECA30A437-300x225.jpg 300w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/7F879408-A0C6-4446-B075-0CBECA30A437-1024x768.jpg 1024w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/7F879408-A0C6-4446-B075-0CBECA30A437-768x576.jpg 768w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/7F879408-A0C6-4446-B075-0CBECA30A437-1536x1152.jpg 1536w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/7F879408-A0C6-4446-B075-0CBECA30A437-2048x1536.jpg 2048w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/7F879408-A0C6-4446-B075-0CBECA30A437-973x730.jpg 973w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/7F879408-A0C6-4446-B075-0CBECA30A437-508x381.jpg 508w\" sizes=\"(max-width: 2560px) 100vw, 2560px\" \/><p id=\"caption-attachment-12743\" class=\"wp-caption-text\">Overall photo for proportion and scale<\/p><\/div>\n<div id=\"attachment_12744\" style=\"width: 1930px\" class=\"wp-caption alignnone\"><img aria-describedby=\"caption-attachment-12744\" loading=\"lazy\" class=\"wp-image-12744 size-full\" src=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/CD242DD5-6C09-41F5-B13F-CC241ADD4A04-scaled.jpg\" alt=\"\" width=\"1920\" height=\"2560\" srcset=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/CD242DD5-6C09-41F5-B13F-CC241ADD4A04-scaled.jpg 1920w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/CD242DD5-6C09-41F5-B13F-CC241ADD4A04-225x300.jpg 225w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/CD242DD5-6C09-41F5-B13F-CC241ADD4A04-768x1024.jpg 768w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/CD242DD5-6C09-41F5-B13F-CC241ADD4A04-1152x1536.jpg 1152w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/CD242DD5-6C09-41F5-B13F-CC241ADD4A04-1536x2048.jpg 1536w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/CD242DD5-6C09-41F5-B13F-CC241ADD4A04-973x1297.jpg 973w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/CD242DD5-6C09-41F5-B13F-CC241ADD4A04-508x677.jpg 508w\" sizes=\"(max-width: 1920px) 100vw, 1920px\" \/><p id=\"caption-attachment-12744\" class=\"wp-caption-text\">Detail photo of the electret microphone installment soldered to an internal breadboard<\/p><\/div>\n<div id=\"attachment_12745\" style=\"width: 1252px\" class=\"wp-caption alignnone\"><img aria-describedby=\"caption-attachment-12745\" loading=\"lazy\" class=\"wp-image-12745 size-full\" src=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/E6EA4DDD-4FCB-4A8C-92B7-8C2557D2F5E4.jpg\" alt=\"\" width=\"1242\" height=\"2196\" srcset=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/E6EA4DDD-4FCB-4A8C-92B7-8C2557D2F5E4.jpg 1242w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/E6EA4DDD-4FCB-4A8C-92B7-8C2557D2F5E4-170x300.jpg 170w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/E6EA4DDD-4FCB-4A8C-92B7-8C2557D2F5E4-579x1024.jpg 579w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/E6EA4DDD-4FCB-4A8C-92B7-8C2557D2F5E4-768x1358.jpg 768w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/E6EA4DDD-4FCB-4A8C-92B7-8C2557D2F5E4-869x1536.jpg 869w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/E6EA4DDD-4FCB-4A8C-92B7-8C2557D2F5E4-1158x2048.jpg 1158w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/E6EA4DDD-4FCB-4A8C-92B7-8C2557D2F5E4-973x1720.jpg 973w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/E6EA4DDD-4FCB-4A8C-92B7-8C2557D2F5E4-508x898.jpg 508w\" sizes=\"(max-width: 1242px) 100vw, 1242px\" \/><p id=\"caption-attachment-12745\" class=\"wp-caption-text\">Image showing the use of my device. Once I snap or clap, it&#8217;s picked up by a small microphone and moves a motor.<\/p><\/div>\n<h2 id=\"process-images-and-review\">Process images and review<\/h2>\n<p>Below are some images of my pivot points. The first big issue I had to tackle was figuring out the mechanical setup o f my device. I knew I needed an actuator that moved linearly in some way so I could turn the switch on the wall off and on. After I knew the exact linear actuator I was ordering, I made some hypotheses. At first, I thought I needed to fashion a squarish attachment that would do the moving. You can see the sketch of it in my sketchbook, and next to it is the refined version that I ideated when I realized it I didn&#8217;t want to code the extra step of having the actuator return to\u00a0 neutral position after pushing the switch.<\/p>\n<div id=\"attachment_12708\" style=\"width: 389px\" class=\"wp-caption alignleft\"><img aria-describedby=\"caption-attachment-12708\" loading=\"lazy\" class=\"wp-image-12708 \" src=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/pasted-image-0-2-e1616456391662-1024x451.jpg\" alt=\"\" width=\"379\" height=\"167\" srcset=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/pasted-image-0-2-e1616456391662-1024x451.jpg 1024w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/pasted-image-0-2-e1616456391662-300x132.jpg 300w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/pasted-image-0-2-e1616456391662-768x338.jpg 768w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/pasted-image-0-2-e1616456391662-973x429.jpg 973w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/pasted-image-0-2-e1616456391662-508x224.jpg 508w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/pasted-image-0-2-e1616456391662.jpg 1444w\" sizes=\"(max-width: 379px) 100vw, 379px\" \/><p id=\"caption-attachment-12708\" class=\"wp-caption-text\">My beginning thoughts on how I would get my linear actuator to do what I wanted<\/p><\/div>\n<div id=\"attachment_12755\" style=\"width: 235px\" class=\"wp-caption alignright\"><img aria-describedby=\"caption-attachment-12755\" loading=\"lazy\" class=\"wp-image-12755 size-medium\" src=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/9EF8ECB8-7A6B-4EFE-AD36-D3BA8AC6D15E-225x300.jpg\" alt=\"\" width=\"225\" height=\"300\" srcset=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/9EF8ECB8-7A6B-4EFE-AD36-D3BA8AC6D15E-225x300.jpg 225w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/9EF8ECB8-7A6B-4EFE-AD36-D3BA8AC6D15E-768x1024.jpg 768w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/9EF8ECB8-7A6B-4EFE-AD36-D3BA8AC6D15E-1152x1536.jpg 1152w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/9EF8ECB8-7A6B-4EFE-AD36-D3BA8AC6D15E-1536x2048.jpg 1536w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/9EF8ECB8-7A6B-4EFE-AD36-D3BA8AC6D15E-973x1297.jpg 973w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/9EF8ECB8-7A6B-4EFE-AD36-D3BA8AC6D15E-508x677.jpg 508w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/9EF8ECB8-7A6B-4EFE-AD36-D3BA8AC6D15E-scaled.jpg 1920w\" sizes=\"(max-width: 225px) 100vw, 225px\" \/><p id=\"caption-attachment-12755\" class=\"wp-caption-text\">The cardboard cutout I made to test out my original idea<\/p><\/div>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>After that, I measured out all the physical components I would need for my device, sketched it out to see how big of a box I would need to fit everything, then built a 3D model in Fusion 360.<\/p>\n<div id=\"attachment_12707\" style=\"width: 1254px\" class=\"wp-caption alignnone\"><img aria-describedby=\"caption-attachment-12707\" loading=\"lazy\" class=\"wp-image-12707 size-full\" src=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/pasted-image-0-1-e1616455725983.jpg\" alt=\"\" width=\"1244\" height=\"800\" srcset=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/pasted-image-0-1-e1616455725983.jpg 1244w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/pasted-image-0-1-e1616455725983-300x193.jpg 300w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/pasted-image-0-1-e1616455725983-1024x659.jpg 1024w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/pasted-image-0-1-e1616455725983-768x494.jpg 768w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/pasted-image-0-1-e1616455725983-973x626.jpg 973w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/pasted-image-0-1-e1616455725983-508x327.jpg 508w\" sizes=\"(max-width: 1244px) 100vw, 1244px\" \/><p id=\"caption-attachment-12707\" class=\"wp-caption-text\">measurement sketches<\/p><\/div>\n<div id=\"attachment_12709\" style=\"width: 1610px\" class=\"wp-caption alignnone\"><img aria-describedby=\"caption-attachment-12709\" loading=\"lazy\" class=\"wp-image-12709\" src=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/unnamed-e1616456431716.png\" alt=\"\" width=\"1600\" height=\"741\" srcset=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/unnamed-e1616456431716.png 460w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/unnamed-e1616456431716-300x139.png 300w\" sizes=\"(max-width: 1600px) 100vw, 1600px\" \/><p id=\"caption-attachment-12709\" class=\"wp-caption-text\">my Fusion 360 model<\/p><\/div>\n<p>When I started actually building the model, I realized I drastically overestimate the size of the hole in the actuator arm. It would not be able to hook the switch, so I just made it push the switch, measuring carefully in my Arduino Sketch the amount it needed to press down.<\/p>\n<h2 id=\"discussion\">Discussion<\/h2>\n<p><strong>Response<\/strong><\/p>\n<p>During the crits, no had many critiques, but they asked good questions that I needed to consider:<\/p>\n<ol>\n<li>How does the linear actuator work?\n<ol>\n<li>At the time, I thought I had a pretty good idea, but I really didn&#8217;t. I figured that it works like a servo and I can just write to it to move to a certain position. I also thought it would be easy to wire, like one wire to power in and one to power out. Luckily, I got help from the course professor, Zach, who knew how that works. An L293D motor driver was key in the process.<\/li>\n<\/ol>\n<\/li>\n<li>How will the device pick up sound?\n<ol>\n<li>The render I showed them in my crit actually had no microphone, so I&#8217;m glad they pointed that out so I could explain the concept more clearly.<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<div id=\"attachment_12714\" style=\"width: 310px\" class=\"wp-caption alignright\"><img aria-describedby=\"caption-attachment-12714\" loading=\"lazy\" class=\"wp-image-12714 size-medium\" src=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/pasted-image-0-4-e1616651819397-300x178.jpg\" alt=\"\" width=\"300\" height=\"178\" srcset=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/pasted-image-0-4-e1616651819397-300x178.jpg 300w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/pasted-image-0-4-e1616651819397-1024x608.jpg 1024w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/pasted-image-0-4-e1616651819397-768x456.jpg 768w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/pasted-image-0-4-e1616651819397-973x578.jpg 973w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/pasted-image-0-4-e1616651819397-508x302.jpg 508w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/pasted-image-0-4-e1616651819397.jpg 1516w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><p id=\"caption-attachment-12714\" class=\"wp-caption-text\">parts were loose because I cut out 0.2mm of space that I did not need to cut out<\/p><\/div>\n<p><strong>Self critique<\/strong><\/p>\n<p>I was satisfied that my device at least worked, but I did not have time to make it look as nice as i would had hoped. I wanted everything to be neatly encased in clear acrylic including the actuator.<\/p>\n<p><strong>What you learned<\/strong><\/p>\n<p>I learned a lot about Fusion. I taught myself how to make finger joints, though I&#8217;m sure I used a method that could have been a lot easier. I learned how to prepare a 3D drawing for laser cutting. I learned how to bevel out the edges that I wanted to be curved as well. I realized that my panels would not fit together the way I designed them in Fusion, thanks to my laser-cut cardboard model.<\/p>\n<p><strong>Next steps<\/strong><\/p>\n<p>A clap-activated light switch would actually be super useful to me, so I would like to iterate again. But the device would be right next to my door which I slam sometimes and that triggers the switch, so that would get annoying. If I were to iterate, I would make then enclosing fit together nicer and make it out of more long-lasting material. I would also attach a hook to the actuator to make it actually switch the light on and of all the way. Finally, I would fit everything in the enclosing so it can attach directly over the light switch, use adhesive so tape isn&#8217;t sticking out everywhere, and switch to a battery to power my Arduino so no wires are plugged into the wall. I actually had to unplug my Xbox for the device, so that is not ideal at all.<\/p>\n<h2 id=\"technical-information\">Technical information<\/h2>\n<p><strong>Schematic and block diagrams<\/strong><\/p>\n<div id=\"attachment_12758\" style=\"width: 861px\" class=\"wp-caption alignnone\"><img aria-describedby=\"caption-attachment-12758\" loading=\"lazy\" class=\"wp-image-12758 size-full\" src=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/clap-activated-light-switch-block-diagram.jpg\" alt=\"\" width=\"851\" height=\"243\" srcset=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/clap-activated-light-switch-block-diagram.jpg 851w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/clap-activated-light-switch-block-diagram-300x86.jpg 300w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/clap-activated-light-switch-block-diagram-768x219.jpg 768w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/clap-activated-light-switch-block-diagram-508x145.jpg 508w\" sizes=\"(max-width: 851px) 100vw, 851px\" \/><p id=\"caption-attachment-12758\" class=\"wp-caption-text\">block diagram<\/p><\/div>\n<div id=\"attachment_12759\" style=\"width: 794px\" class=\"wp-caption alignnone\"><img aria-describedby=\"caption-attachment-12759\" loading=\"lazy\" class=\"wp-image-12759 size-full\" src=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/Project-2-Prototype.jpg\" alt=\"\" width=\"784\" height=\"842\" srcset=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/Project-2-Prototype.jpg 784w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/Project-2-Prototype-279x300.jpg 279w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/Project-2-Prototype-768x825.jpg 768w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/Project-2-Prototype-508x546.jpg 508w\" sizes=\"(max-width: 784px) 100vw, 784px\" \/><p id=\"caption-attachment-12759\" class=\"wp-caption-text\">schematic<\/p><\/div>\n<p><strong>Code submission<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"c\">\/****************************************\r\n * Clap-Activated Light Switch Sketch\r\n * Dominique Aruede\r\n * \r\n * Description:\r\n * This sketch moves an actuator to turn a light on and off whenever it hears\r\n * you clap or snap, so you can turn off your light remotely.\r\n\r\n  Pin mapping:\r\n  Arduino pin | type   | description\r\n  ------------|--------|-------------\r\n  A3           output   linear actuator\r\n  A4           output   linear actuator\r\n  A1            input   electret microphone\r\n\r\n  Collaboration and sources:\r\n  Example Sound Level Sketch for the\r\n  Adafruit Microphone Amplifier\r\n****************************************\/\r\n\r\nconst int LINEARARMPIN1 = A3;\r\nconst int LINEARARMPIN2 = A4;\r\nconst int MICPIN = A1;\r\nconst int WAIT = 1000;\r\nunsigned long timerVariable = 0;\r\nconst int sampleWindow = 50; \/\/ Sample window width in mS (50 mS = 20Hz)\r\nunsigned int sample;\r\nboolean toggle = 1;\r\n\r\nint micState = 0;\r\nint armState = HIGH;\r\n\r\nvoid setup()\r\n{\r\n  Serial.begin(9600);\r\n  pinMode(MICPIN, INPUT);\r\n  pinMode(LINEARARMPIN1, OUTPUT);\r\n  pinMode(LINEARARMPIN2, OUTPUT);\r\n}\r\n\r\n\r\nvoid loop()\r\n{\r\n  unsigned long startMillis = millis(); \/\/ Start of sample window\r\n  unsigned int peakToPeak = 0;   \/\/ peak-to-peak level\r\n  micState = peakToPeak;\r\n  armState = analogRead(LINEARARMPIN1);\r\n  timerVariable = millis();\r\n\r\n  unsigned int signalMax = 0;\r\n  unsigned int signalMin = 1024;\r\n\r\n  \/\/ collect data for 50 mS\r\n  while (millis() - startMillis &lt; sampleWindow)\r\n  {\r\n    sample = analogRead(MICPIN);\r\n    if (sample &lt; 1024)  \/\/ toss out spurious readings\r\n    {\r\n      if (sample &gt; signalMax)\r\n      {\r\n        signalMax = sample;  \/\/ save just the max levels\r\n      }\r\n      else if (sample &lt; signalMin)\r\n      {\r\n        signalMin = sample;  \/\/ save just the min levels\r\n      }\r\n    }\r\n  }\r\n  peakToPeak = signalMax - signalMin;  \/\/ max - min = peak-peak amplitude\r\n  double micState = (peakToPeak * 5.0) \/ 1024;  \/\/ convert to volts\r\n\r\n\/\/ if mic hears sound, move up or down depending on position of switch\r\n   if (micState &gt; 2 &amp;&amp; toggle == 0){\r\n    Serial.println(\"hey\");\r\n    \r\n    while (millis() - timerVariable &lt; WAIT) {\r\n      digitalWrite(LINEARARMPIN1, HIGH);\r\n      digitalWrite(LINEARARMPIN2, LOW);\r\n      delay(1000);\r\n      toggle = !toggle;\r\n    }\r\n  }\r\n  if (micState &gt; 3 &amp;&amp; toggle == 1) {\r\n    Serial.println(\"whats up\");\r\n    \r\n    while (millis() - timerVariable &lt; WAIT) {\r\n      digitalWrite(LINEARARMPIN1, LOW);\r\n      digitalWrite(LINEARARMPIN2, HIGH);\r\n      delay(1000);\r\n      toggle = !toggle;\r\n    }\r\n  }\r\n  \/\/  Serial.println(timerVariable);\r\n  digitalWrite(LINEARARMPIN1, LOW);\r\n  digitalWrite(LINEARARMPIN2, LOW);\r\n  if (millis() - timerVariable &gt; sampleWindow) {\r\n    Serial.print(\"mic state: \");\r\n    Serial.println(micState);\r\n    Serial.print(\"arm position: \");\r\n    Serial.println(armState);\r\n    timerVariable = millis();\r\n  }\r\n\r\n}<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Overview &nbsp; I created a device that turns a light on and off whenever it hears you clap or snap, so I can turn off my light remotely&#8230;.<\/p>\n","protected":false},"author":169,"featured_media":12741,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[89],"tags":[],"_links":{"self":[{"href":"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-json\/wp\/v2\/posts\/12706"}],"collection":[{"href":"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-json\/wp\/v2\/users\/169"}],"replies":[{"embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-json\/wp\/v2\/comments?post=12706"}],"version-history":[{"count":9,"href":"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-json\/wp\/v2\/posts\/12706\/revisions"}],"predecessor-version":[{"id":12760,"href":"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-json\/wp\/v2\/posts\/12706\/revisions\/12760"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-json\/wp\/v2\/media\/12741"}],"wp:attachment":[{"href":"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-json\/wp\/v2\/media?parent=12706"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-json\/wp\/v2\/categories?post=12706"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-json\/wp\/v2\/tags?post=12706"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}