{"id":1833,"date":"2020-11-10T15:40:28","date_gmt":"2020-11-10T20:40:28","guid":{"rendered":"https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/?p=1833"},"modified":"2020-11-10T19:36:41","modified_gmt":"2020-11-11T00:36:41","slug":"%e6%ac%a2%e8%bf%8e%e5%85%89%e4%b8%b4-a-motion-sensor-that-welcomes-customers","status":"publish","type":"post","link":"https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/?p=1833","title":{"rendered":"\u201d\u6b22\u8fce\u5149\u4e34\u201c A motion sensor that welcomes customers"},"content":{"rendered":"<p>Years ago(when I was a kid) in China, when you walk into most convenience stores and small shops, an accessory by the door will welcome you by saying <a href=\"https:\/\/youtu.be\/EuUwQFukMQE\">&#8220;welcome&#8221;<\/a>, and it also serves to notify the store owners that they have customers. I remember when I was a kid, I found it really annoying, because it makes the sound not only when you walk in, but also when you walk out. And if you stand by the door, it will keep &#8216;welcoming&#8217; you. It&#8217;s probably because the accessory sensor only detects for distance, and it&#8217;s not smart enough to distinguish when not to make the sound.<\/p>\n<p>Nowadays, I don&#8217;t hear it as often, and I&#8217;m not sure if it&#8217;s because the sensing accessory it too annoying, or simply because people associate this sound with &#8216;low-end&#8217; stores. But I thought if this sensing accessory could become smarter, maybe it&#8217;s not a bad idea to bring it back?<\/p>\n<p>So I added 2 features:<\/p>\n<ol>\n<li style=\"list-style-type: none\">\n<ol>\n<li>only makes the sound when someone walks in, not out;<\/li>\n<li>don&#8217;t make the sound if the store owner is already by the door or near the door<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<p>I initially wanted to use 2 ultrasonic distance sensors(1 to sense the person walking through the door, and another to sense the store owner being nearby the door), but I only had 1 distance sensor, so I used a button to indicate the event of &#8220;the owner is nearby the door&#8221;.<\/p>\n<p>Input: Button, Photo-resistor, ultrasonic distance sensors<\/p>\n<p>Output: buzzer speaker<\/p>\n<p>I wasn&#8217;t able to get the speaker to play &#8220;Welcome&#8221; in Chinese, but I tried to mimic the tones of the way &#8220;Welcome&#8221; sounds with these sensing accessories(shoutout to my musically talented friend Michelle).<\/p>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-1835 size-large\" src=\"https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/wp-content\/uploads\/2020\/11\/Screen-Shot-2020-11-10-at-3.10.32-PM-1024x690.png\" alt=\"\" width=\"840\" height=\"566\" srcset=\"https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/wp-content\/uploads\/2020\/11\/Screen-Shot-2020-11-10-at-3.10.32-PM-1024x690.png 1024w, https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/wp-content\/uploads\/2020\/11\/Screen-Shot-2020-11-10-at-3.10.32-PM-300x202.png 300w, https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/wp-content\/uploads\/2020\/11\/Screen-Shot-2020-11-10-at-3.10.32-PM-768x517.png 768w, https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/wp-content\/uploads\/2020\/11\/Screen-Shot-2020-11-10-at-3.10.32-PM-1536x1035.png 1536w, https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/wp-content\/uploads\/2020\/11\/Screen-Shot-2020-11-10-at-3.10.32-PM-2048x1380.png 2048w, https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/wp-content\/uploads\/2020\/11\/Screen-Shot-2020-11-10-at-3.10.32-PM-1200x808.png 1200w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><\/p>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-1834 size-large\" src=\"https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/wp-content\/uploads\/2020\/11\/IMG_3812-768x1024.jpg\" alt=\"\" width=\"768\" height=\"1024\" srcset=\"https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/wp-content\/uploads\/2020\/11\/IMG_3812-768x1024.jpg 768w, https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/wp-content\/uploads\/2020\/11\/IMG_3812-225x300.jpg 225w, https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/wp-content\/uploads\/2020\/11\/IMG_3812-1152x1536.jpg 1152w, https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/wp-content\/uploads\/2020\/11\/IMG_3812-1536x2048.jpg 1536w, https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/wp-content\/uploads\/2020\/11\/IMG_3812-1200x1600.jpg 1200w, https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/wp-content\/uploads\/2020\/11\/IMG_3812-scaled.jpg 1920w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/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-1833-1\" width=\"840\" height=\"865\" preload=\"metadata\" controls=\"controls\"><source type=\"video\/mp4\" src=\"https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/wp-content\/uploads\/2020\/11\/IMG_3810-1.mp4?_=1\" \/><a href=\"https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/wp-content\/uploads\/2020\/11\/IMG_3810-1.mp4\">https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/wp-content\/uploads\/2020\/11\/IMG_3810-1.mp4<\/a><\/video><\/div>\n<p>I used a photoresistor to detect whether the person is going in or out, but this scheme is far from reliable. A real motion sensor can do a much better job than what I have.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"c\">#include&lt;Wire.h&gt;\r\n\r\n\r\n\/\/ PIN INIT\r\nconst int SPEAKERPIN = 3;\r\nconst int TRIGPIN = 4;\r\nconst int ECHOPIN = 5;\r\nconst int BUTTONPIN = 7;\r\nconst int PHOTOPIN = A0;\r\n\r\n\r\n\/\/ GLOBAL VARS\r\nint distanceThreshold = 4;\r\nint prevPhotoVal = 0;\r\n\r\nint get_distance(){\r\n  unsigned long duration;\r\n  int distance;\r\n  digitalWrite(TRIGPIN, HIGH);\r\n  delay(1);\r\n  digitalWrite(TRIGPIN, LOW);\r\n  duration = pulseIn(ECHOPIN, HIGH, 20000);\r\n  distance = duration \/ 57;  \/\/ Divide by round-trip microseconds per cm to get cm\r\n  return distance;\r\n}\r\n\r\nvoid setup() {\r\n  Serial.begin(9600);\r\n  pinMode(SPEAKERPIN, OUTPUT); \r\n  pinMode(ECHOPIN, INPUT);\r\n  pinMode(TRIGPIN, OUTPUT);\r\n  pinMode(PHOTOPIN, INPUT);\r\n  pinMode(BUTTONPIN, INPUT_PULLUP);\r\n}\r\n\r\nvoid loop() {\r\n  int buttonUp = digitalRead(BUTTONPIN);\r\n  int currPhotoVal = analogRead(PHOTOPIN);\r\n  int distance = get_distance();\r\n  if (distance &lt; distanceThreshold &amp;&amp; buttonUp) {\r\n    if(currPhotoVal &gt; prevPhotoVal) {\r\n      tone(SPEAKERPIN , 185, 200);\r\n      delay(200);\r\n      tone(SPEAKERPIN , 146.83, 200);\r\n      delay(200);\r\n      tone(SPEAKERPIN , 185, 200);\r\n      delay(200);\r\n      tone(SPEAKERPIN , 146.83, 400);\r\n      delay(400);\r\n    }\r\n  }\r\n  prevPhotoVal = currPhotoVal;\r\n}<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Years ago(when I was a kid) in China, when you walk into most convenience stores and small shops, an accessory by the door will welcome you by saying &#8220;welcome&#8221;, and it also serves to notify the store owners that they have customers. I remember when I was a kid, I found it really annoying, because &hellip; <a href=\"https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/?p=1833\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;\u201d\u6b22\u8fce\u5149\u4e34\u201c A motion sensor that welcomes customers&#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":[20],"tags":[],"_links":{"self":[{"href":"https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/index.php?rest_route=\/wp\/v2\/posts\/1833"}],"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=1833"}],"version-history":[{"count":3,"href":"https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/index.php?rest_route=\/wp\/v2\/posts\/1833\/revisions"}],"predecessor-version":[{"id":1858,"href":"https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/index.php?rest_route=\/wp\/v2\/posts\/1833\/revisions\/1858"}],"wp:attachment":[{"href":"https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1833"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1833"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1833"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}