{"id":1561,"date":"2020-10-15T13:29:23","date_gmt":"2020-10-15T17:29:23","guid":{"rendered":"https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/?p=1561"},"modified":"2020-11-03T20:28:28","modified_gmt":"2020-11-04T01:28:28","slug":"smart-curtain","status":"publish","type":"post","link":"https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/?p=1561","title":{"rendered":"Smart Curtain"},"content":{"rendered":"<p>At the beginning of the semester, Chloe had an idea for an alarm clock that wakes people up through lights rather than sounds. I then bought <a href=\"https:\/\/www.amazon.com\/Wake-Up-Light-Sunrise-Alarm-Clock\/dp\/B07ZF5X3KQ\/ref=sr_1_8?crid=25HU9L4RKM479&amp;dchild=1&amp;keywords=alarm+clock+light+wake+up&amp;qid=1602780620&amp;sprefix=alarm+clock+light%2Cinstant-video%2C407&amp;sr=8-8\">an alarm clock, sunrise alarm clock,<\/a> that has a similar functionality, and it has been great. Then I thought, well instead of using artificial lights, why can&#8217;t we use natural lights? (Of course natural light would not work if you are waking up in the middle of the night).<\/p>\n<figure id=\"attachment_1562\" aria-describedby=\"caption-attachment-1562\" style=\"width: 341px\" class=\"wp-caption alignright\"><img loading=\"lazy\" class=\"wp-image-1562 \" src=\"https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/wp-content\/uploads\/2020\/10\/IMG_3235-768x1024.jpg\" alt=\"\" width=\"341\" height=\"455\" srcset=\"https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/wp-content\/uploads\/2020\/10\/IMG_3235-768x1024.jpg 768w, https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/wp-content\/uploads\/2020\/10\/IMG_3235-225x300.jpg 225w, https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/wp-content\/uploads\/2020\/10\/IMG_3235-1152x1536.jpg 1152w, https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/wp-content\/uploads\/2020\/10\/IMG_3235-1536x2048.jpg 1536w, https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/wp-content\/uploads\/2020\/10\/IMG_3235-1200x1600.jpg 1200w, https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/wp-content\/uploads\/2020\/10\/IMG_3235-scaled.jpg 1920w\" sizes=\"(max-width: 341px) 85vw, 341px\" \/><figcaption id=\"caption-attachment-1562\" class=\"wp-caption-text\">sketches<\/figcaption><\/figure>\n<p>I then came up with this idea of a<strong> smart curtain<\/strong> that is basically a reverse sunrise alarm clock. It serves as an <em>&#8220;alarm clock&#8221;<\/em> as it opens and lets lights in at the time you set. I also added a <em>natural light mode<\/em>: curtains are closed when the sun is down, and the curtain is opened when the sun is up. Houses\/apartments in China are much closer to one another than ones in the US, so you have to close your curtains at night. But I rely on the lights to help me wake up in the morning, so ever since I came back home in China, my mom has been yelling at me to close my curtains completely every other night.<\/p>\n<figure id=\"attachment_1558\" aria-describedby=\"caption-attachment-1558\" style=\"width: 1569px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" class=\"wp-image-1558 size-full\" src=\"https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/wp-content\/uploads\/2020\/10\/Fabulous-Waasa.png\" alt=\"\" width=\"1569\" height=\"849\" srcset=\"https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/wp-content\/uploads\/2020\/10\/Fabulous-Waasa.png 1569w, https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/wp-content\/uploads\/2020\/10\/Fabulous-Waasa-300x162.png 300w, https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/wp-content\/uploads\/2020\/10\/Fabulous-Waasa-1024x554.png 1024w, https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/wp-content\/uploads\/2020\/10\/Fabulous-Waasa-768x416.png 768w, https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/wp-content\/uploads\/2020\/10\/Fabulous-Waasa-1536x831.png 1536w, https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/wp-content\/uploads\/2020\/10\/Fabulous-Waasa-1200x649.png 1200w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><figcaption id=\"caption-attachment-1558\" class=\"wp-caption-text\">schematic<\/figcaption><\/figure>\n<p>I don&#8217;t have access to a linear stepper motor, nor a time module. So I used a servo motor to show the actions of opening and closing the curtains, and hardcoded the current time.<\/p>\n<p>In addition, I used a <strong>potentiometer<\/strong> to adjust time, and I kept on getting connection issues with the potentiometer to have consistent readings. I used a <strong>push button<\/strong> to change mode, a <strong>photo cell<\/strong> to detect day\/night(in practice, this photo cell needs to be placed such that only outdoor lightings are sensed but not indoor lightings), and an <strong>LCD<\/strong> to display mode and time.<\/p>\n<figure id=\"attachment_1560\" aria-describedby=\"caption-attachment-1560\" style=\"width: 258px\" class=\"wp-caption alignleft\"><img loading=\"lazy\" class=\"wp-image-1560 \" src=\"https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/wp-content\/uploads\/2020\/10\/IMG_3234-225x300.jpg\" alt=\"\" width=\"258\" height=\"344\" srcset=\"https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/wp-content\/uploads\/2020\/10\/IMG_3234-225x300.jpg 225w, https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/wp-content\/uploads\/2020\/10\/IMG_3234-768x1024.jpg 768w, https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/wp-content\/uploads\/2020\/10\/IMG_3234-1152x1536.jpg 1152w, https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/wp-content\/uploads\/2020\/10\/IMG_3234-1536x2048.jpg 1536w, https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/wp-content\/uploads\/2020\/10\/IMG_3234-1200x1600.jpg 1200w, https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/wp-content\/uploads\/2020\/10\/IMG_3234-scaled.jpg 1920w\" sizes=\"(max-width: 258px) 85vw, 258px\" \/><figcaption id=\"caption-attachment-1560\" class=\"wp-caption-text\">the beautiful curtain(wet wipe)<\/figcaption><\/figure>\n<p><img loading=\"lazy\" class=\" wp-image-1559 alignleft\" src=\"https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/wp-content\/uploads\/2020\/10\/IMG_3233-225x300.jpg\" alt=\"\" width=\"262\" height=\"348\" srcset=\"https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/wp-content\/uploads\/2020\/10\/IMG_3233-225x300.jpg 225w, https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/wp-content\/uploads\/2020\/10\/IMG_3233-768x1024.jpg 768w, https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/wp-content\/uploads\/2020\/10\/IMG_3233-1152x1536.jpg 1152w, https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/wp-content\/uploads\/2020\/10\/IMG_3233-1536x2048.jpg 1536w, https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/wp-content\/uploads\/2020\/10\/IMG_3233-1200x1600.jpg 1200w, https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/wp-content\/uploads\/2020\/10\/IMG_3233-scaled.jpg 1920w\" sizes=\"(max-width: 262px) 85vw, 262px\" \/><\/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<div style=\"width: 840px;\" class=\"wp-video\"><!--[if lt IE 9]><script>document.createElement('video');<\/script><![endif]-->\n<video class=\"wp-video-shortcode\" id=\"video-1561-1\" width=\"840\" height=\"473\" preload=\"metadata\" controls=\"controls\"><source type=\"video\/mp4\" src=\"https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/wp-content\/uploads\/2020\/10\/IMG_3232-1.mp4?_=1\" \/><a href=\"https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/wp-content\/uploads\/2020\/10\/IMG_3232-1.mp4\">https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/wp-content\/uploads\/2020\/10\/IMG_3232-1.mp4<\/a><\/video><\/div>\n<p>This smart curtain can be improved in some ways. In alarm mode, the curtain could be slowly opening instead of opening at once, to fake the effect of sunrise. Like the sunrise alarm clock that can be controlled by smart phones, smart curtain should do that too and maybe even integrate with a traditional alarm system, i.e. slowly opens up at curtain and then alarm rings.<\/p>\n<p>Code:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"c\">#include &lt;LiquidCrystal.h&gt;\r\n#include &lt;Servo.h&gt;\r\n\r\nLiquidCrystal lcd = LiquidCrystal(7,6,5,4,3,2);\r\nServo myservo;\r\nconst int POTPIN = A1;\r\nconst int BUTTONPIN = 13;\r\nconst int PHOTOPIN = A0;\r\nconst int SERVOPIN = 9;\r\nconst int PHOTOTHRESH = 300;\r\n\r\n\r\nbool isAlarm = true;\r\nbool isOpen = false;\r\nint clockTime = 0; \/\/ used for demo purpose\r\nlong long lastLCDTime = 0; \r\nlong long LCDinterval = 100;\r\nlong long lastDebounceTime = 0;  \r\nlong long debounceDelay = 50; \r\n\r\n\r\nvoid openCurtain() {\r\n  for (int pos = 89; pos &gt; 0; pos -= 1) {\r\n    \/\/ in steps of 1 degree\r\n    myservo.write(pos);\r\n    delay(15);\r\n  }\r\n  isOpen = true;\r\n}\r\n\r\nvoid closeCurtain() {\r\n  for (int pos = 0; pos &lt; 90; pos += 1) {\r\n    \/\/ in steps of 1 degree\r\n    myservo.write(pos);\r\n    delay(15);\r\n  }\r\n  isOpen = false;\r\n}\r\n\r\nvoid updateLCD(long long currTime, int h, int m, bool isAlarm) {\r\n  if (currTime - lastLCDTime &gt; LCDinterval) {\r\n    lcd.clear();\r\n    lcd.setCursor(2, 0);\r\n    String mode = isAlarm ? \"alarm\" : \"natural\";\r\n    lcd.setCursor(2, 1);\r\n    lastLCDTime = currTime;\r\n  }\r\n}\r\n\r\nvoid setup() {\r\n  lcd.begin(16, 2);\r\n  analogWrite(A5, 40);\r\n  myservo.attach(SERVOPIN);\r\n  myservo.write(0);\r\n  pinMode(BUTTONPIN, INPUT_PULLUP);\r\n  Serial.begin(9600);\r\n}\r\n\r\nvoid loop() {\r\n  \/\/ read button\r\n  long long currTime = millis();\r\n  if (currTime-lastDebounceTime&gt;debounceDelay) {\r\n    if (digitalRead(BUTTONPIN) == 0) {\r\n        isAlarm = !isAlarm;\r\n    }\r\n    lastDebounceTime = currTime;\r\n  }\r\n\r\n  \/\/ read potentiometer\r\n  int potVal = analogRead(POTPIN);\r\n  int potTime = potVal\/(1023.0\/(24.0*60.0));\r\n  int h = potTime\/60;\r\n  int m = potTime%60;\r\n\r\n  \/\/ read photo resistor\r\n  int photoVal = analogRead(PHOTOPIN);\r\n\r\n  updateLCD(currTime, h, m, isAlarm);\r\n  if ((!isAlarm) &amp;&amp; (!isOpen) &amp;&amp; (photoVal&gt;PHOTOTHRESH)) {\r\n    openCurtain();\r\n  }\r\n  else if (isAlarm &amp;&amp; (!isOpen) &amp;&amp; (potTime==clockTime)) {\r\n    openCurtain();\r\n  }\r\n  else if (isOpen &amp;&amp; (photoVal&lt;PHOTOTHRESH)) {\r\n    closeCurtain();\r\n  }\r\n  \r\n}<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>At the beginning of the semester, Chloe had an idea for an alarm clock that wakes people up through lights rather than sounds. I then bought an alarm clock, sunrise alarm clock, that has a similar functionality, and it has been great. Then I thought, well instead of using artificial lights, why can&#8217;t we use &hellip; <a href=\"https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/?p=1561\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Smart Curtain&#8221;<\/span><\/a><\/p>\n","protected":false},"author":19,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[16],"tags":[],"_links":{"self":[{"href":"https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/index.php?rest_route=\/wp\/v2\/posts\/1561"}],"collection":[{"href":"https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/index.php?rest_route=\/wp\/v2\/users\/19"}],"replies":[{"embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1561"}],"version-history":[{"count":3,"href":"https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/index.php?rest_route=\/wp\/v2\/posts\/1561\/revisions"}],"predecessor-version":[{"id":1787,"href":"https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/index.php?rest_route=\/wp\/v2\/posts\/1561\/revisions\/1787"}],"wp:attachment":[{"href":"https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1561"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1561"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1561"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}