{"id":6641,"date":"2016-02-19T09:00:35","date_gmt":"2016-02-19T14:00:35","guid":{"rendered":"https:\/\/blogs.mathworks.com\/pick\/?p=6641"},"modified":"2016-02-18T14:36:57","modified_gmt":"2016-02-18T19:36:57","slug":"arduino-blinking-heart-motion-sensor","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/pick\/2016\/02\/19\/arduino-blinking-heart-motion-sensor\/","title":{"rendered":"Arduino Blinking Heart Motion Sensor"},"content":{"rendered":"<div xmlns:mwsh=\"https:\/\/www.mathworks.com\/namespace\/mcode\/v1\/syntaxhighlight.dtd\" class=\"content\">\r\n   <introduction>\r\n      <p><a href=\"https:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/3208495\">Sean<\/a>'s pick this week is <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/45530-arduino-blinking-heart-motion-sensor\">Arduino Blinking Heart Motion Sensor<\/a> by <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/2987669\">Ye Cheng<\/a>.\r\n      <\/p>\r\n   <\/introduction>\r\n   <p>My pick this week is one of the many submissions on the File Exchange that mentions Valentine's Day somewhere in the description.\r\n      However, unlike any of the others, this one runs standalone on an Arduino so I can set it up somewhere in my house an surprise\r\n      my wife with it.\r\n   <\/p>\r\n   <p>So what does it do?  The Arduino is connected to a motion sensor and a breadboard with red LEDs on it shaped like a heart.\r\n       When the motion sensor trips, it blinks the LEDs.\r\n   <\/p>\r\n   <p>The controller is built in Simulink.  It uses <a href=\"https:\/\/www.mathworks.com\/products\/stateflow\/\">Stateflow<\/a> for the supervisory control logic and the <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/40312-simulink-support-package-for-arduino-hardware\">Arduino Simulink Support Package<\/a> so that the model can be embedded on the Arduino.\r\n   <\/p>\r\n   <p>Here's a snapshot of the Stateflow logic:<\/p>\r\n   <p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/Sean\/mainArduinoHeart\/statechart.png\"> <\/p>\r\n   <p>So if you're curious what happened when I set this up in my house, here's a video.  The motion sensor is <i>very<\/i> sensitive.\r\n   <\/p>\r\n   <p>\r\n      <object id=\"csSWF\" classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" width=\"768\" height=\"432\" codebase=\"http:\/\/download.macromedia.com\/pub\/shockwave\/cabs\/flash\/swflash.cab#version=9,0,115,0\">\r\n      <param name=\"src\" value=\"https:\/\/blogs.mathworks.com\/images\/pick\/Sean\/mainArduinoHeart\/ArduinoHeart.mp4\">\r\n      <param name=\"bgcolor\" value=\"#1a1a1a\">\r\n      <param name=\"quality\" value=\"best\">\r\n      <param name=\"allowScriptAccess\" value=\"always\">\r\n      <param name=\"allowFullScreen\" value=\"true\">\r\n      <param name=\"scale\" value=\"showall\">\r\n      <param name=\"flashVars\" value=\"autostart=false#&amp;thumb=FirstFrame.png&amp;thumbscale=45&amp;color=0x1A1A1A,0x1A1A1A\">\r\n      <embed name=\"csSWF\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/Sean\/mainArduinoHeart\/ArduinoHeart.mp4\" width=\"768\" height=\"432\" bgcolor=\"#1a1a1a\" quality=\"best\" allowscriptaccess=\"always\"\r\n      allowfullscreen=\"true\" scale=\"showall\" flashvars=\"autostart=false&amp;thumb=FirstFrame.png&amp;thumbscale=45&amp;color=0x1A1A1A,0x1A1A1A\"\r\n      pluginspage=\"http:\/\/www.macromedia.com\/shockwave\/download\/index.cgi?P1_Prod_Version=ShockwaveFlash\">\r\n      <\/object>\r\n      \r\n   <\/p>\r\n   <p>Many thanks to Ye for providing me with the hardware.<\/p>\r\n   <h3>Comments<a name=\"3\"><\/a><\/h3>\r\n   <p>Give it a try and let us know what you think <a href=\"https:\/\/blogs.mathworks.com\/pick\/?p=6641#respond\">here<\/a> or leave a <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/45530-arduino-blinking-heart-motion-sensor#comments\">comment<\/a> for Ye.\r\n   <\/p><script language=\"JavaScript\">\r\n<!--\r\n\r\n    function grabCode_625d2aaa63974c07b0be29e6dd027df2() {\r\n        \/\/ Remember the title so we can use it in the new page\r\n        title = document.title;\r\n\r\n        \/\/ Break up these strings so that their presence\r\n        \/\/ in the Javascript doesn't mess up the search for\r\n        \/\/ the MATLAB code.\r\n        t1='625d2aaa63974c07b0be29e6dd027df2 ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' 625d2aaa63974c07b0be29e6dd027df2';\r\n    \r\n        b=document.getElementsByTagName('body')[0];\r\n        i1=b.innerHTML.indexOf(t1)+t1.length;\r\n        i2=b.innerHTML.indexOf(t2);\r\n \r\n        code_string = b.innerHTML.substring(i1, i2);\r\n        code_string = code_string.replace(\/REPLACE_WITH_DASH_DASH\/g,'--');\r\n\r\n        \/\/ Use \/x3C\/g instead of the less-than character to avoid errors \r\n        \/\/ in the XML parser.\r\n        \/\/ Use '\\x26#60;' instead of '<' so that the XML parser\r\n        \/\/ doesn't go ahead and substitute the less-than character. \r\n        code_string = code_string.replace(\/\\x3C\/g, '\\x26#60;');\r\n\r\n        author = 'Sean de Wolski';\r\n        copyright = 'Copyright 2016 The MathWorks, Inc.';\r\n\r\n        w = window.open();\r\n        d = w.document;\r\n        d.write('<pre>\\n');\r\n        d.write(code_string);\r\n\r\n        \/\/ Add author and copyright lines at the bottom if specified.\r\n        if ((author.length > 0) || (copyright.length > 0)) {\r\n            d.writeln('');\r\n            d.writeln('%%');\r\n            if (author.length > 0) {\r\n                d.writeln('% _' + author + '_');\r\n            }\r\n            if (copyright.length > 0) {\r\n                d.writeln('% _' + copyright + '_');\r\n            }\r\n        }\r\n\r\n        d.write('<\/pre>\\n');\r\n      \r\n      d.title = title + ' (MATLAB code)';\r\n      d.close();\r\n      }   \r\n      \r\n-->\r\n<\/script><p style=\"text-align: right; font-size: xx-small; font-weight:lighter;   font-style: italic; color: gray\"><br><a href=\"javascript:grabCode_625d2aaa63974c07b0be29e6dd027df2()\"><span style=\"font-size: x-small;        font-style: italic;\">Get \r\n            the MATLAB code \r\n            <noscript>(requires JavaScript)<\/noscript><\/span><\/a><br><br>\r\n      Published with MATLAB&reg; R2015b<br><\/p>\r\n<\/div>\r\n<!--\r\n625d2aaa63974c07b0be29e6dd027df2 ##### SOURCE BEGIN #####\r\n%% Arduino Blinking Heart Motion Sensor\r\n%\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/3208495 Sean>'s pick this week is\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/45530-arduino-blinking-heart-motion-sensor Arduino Blinking Heart Motion Sensor> by\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/2987669 Ye Cheng>.\r\n% \r\n\r\n%% \r\n% My pick this week is one of the many submissions on\r\n% the File Exchange that mentions Valentine's Day\r\n% somewhere in the description.  However, unlike any of\r\n% the others, this one runs standalone on an Arduino so\r\n% I can set it up somewhere in my house an surprise my\r\n% wife with it.  \r\n%\r\n% So what does it do?  The Arduino is connected to a\r\n% motion sensor and a breadboard with red LEDs on it\r\n% shaped like a heart.  When the motion sensor trips,\r\n% it blinks the LEDs.\r\n%\r\n% The controller is built in Simulink.  It uses\r\n% <https:\/\/www.mathworks.com\/products\/stateflow\/\r\n% Stateflow> for the supervisory control logic and the\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/40312-simulink-support-package-for-arduino-hardware\r\n% Arduino Simulink Support Package> so that the model\r\n% can be embedded on the Arduino.\r\n%\r\n% Here's a snapshot of the Stateflow logic:\r\n%\r\n% <<statechart.png>>\r\n%\r\n% So if you're curious what happened when I set this up\r\n% in my house, here's a video.  The motion sensor is\r\n% _very_ sensitive.\r\n%\r\n% <html>\r\n%     <object id=\"csSWF\" classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" width=\"1000\" height=\"520\" codebase=\"http:\/\/download.macromedia.com\/pub\/shockwave\/cabs\/flash\/swflash.cab#version=9,0,115,0\">\r\n%          <param name=\"src\" value=\"ArduinoHeart.mp4\">\r\n%          <param name=\"bgcolor\" value=\"#1a1a1a\">\r\n%          <param name=\"quality\" value=\"best\">\r\n%          <param name=\"allowScriptAccess\" value=\"always\">\r\n%          <param name=\"allowFullScreen\" value=\"true\">\r\n%          <param name=\"scale\" value=\"showall\">\r\n%          <param name=\"flashVars\" value=\"autostart=false#&amp;thumb=FirstFrame.png&amp;thumbscale=45&amp;color=0x1A1A1A,0x1A1A1A\">\r\n%          <embed name=\"csSWF\" src=\"ArduinoHeart.mp4\" width=\"1280\" height=\"720\" bgcolor=\"#1a1a1a\" quality=\"best\" allowscriptaccess=\"always\" allowfullscreen=\"true\" scale=\"showall\" flashvars=\"autostart=false&amp;thumb=FirstFrame.png&amp;thumbscale=45&amp;color=0x1A1A1A,0x1A1A1A\" pluginspage=\"http:\/\/www.macromedia.com\/shockwave\/download\/index.cgi?P1_Prod_Version=ShockwaveFlash\">\r\n%      <\/object>\r\n% <\/html>\r\n\r\n%%\r\n% Many thanks to Ye for providing me with the hardware.\r\n\r\n%% Comments\r\n% \r\n% Give it a try and let us know what you think\r\n% <https:\/\/blogs.mathworks.com\/pick\/?p=6641#respond here> or leave a\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/45530-arduino-blinking-heart-motion-sensor#comments\r\n% comment> for Ye.\r\n%\r\n \r\n\r\n##### SOURCE END ##### 625d2aaa63974c07b0be29e6dd027df2\r\n-->","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img decoding=\"async\"  class=\"img-responsive\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/Sean\/mainArduinoHeart\/statechart.png\" onError=\"this.style.display ='none';\" \/><\/div><p>\r\n   \r\n      Sean's pick this week is Arduino Blinking Heart Motion Sensor by Ye Cheng.\r\n      \r\n   \r\n   My pick this week is one of the many submissions on the File Exchange that mentions... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/pick\/2016\/02\/19\/arduino-blinking-heart-motion-sensor\/\">read more >><\/a><\/p>","protected":false},"author":87,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[16],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/6641"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/users\/87"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/comments?post=6641"}],"version-history":[{"count":4,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/6641\/revisions"}],"predecessor-version":[{"id":6645,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/6641\/revisions\/6645"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media?parent=6641"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/categories?post=6641"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/tags?post=6641"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}