{"id":16551,"date":"2022-07-18T10:07:00","date_gmt":"2022-07-18T02:07:00","guid":{"rendered":"https:\/\/www.circuspi.com\/?p=16551"},"modified":"2022-08-24T09:11:14","modified_gmt":"2022-08-24T01:11:14","slug":"intruder-alarm","status":"publish","type":"post","link":"https:\/\/www.circuspi.com\/index.php\/2022\/07\/18\/intruder-alarm\/","title":{"rendered":"\u6a39\u8393\u6d3e\u611f\u6e2c\u5668\u5be6\u4f5c(\u4e8c)\uff1a\u5165\u4fb5\u8005\u8b66\u5831\u5668"},"content":{"rendered":"\n<p><style>\n\/* ###\u5be6\u9a57\u4e0b\u4e00\u5217### *\/\n\na:link {color:#0695e4\n;}    \/* \u8a2d\u5b9a\u5c1a\u672a\u9ede\u95b1\u904e\u7684\u9023\u7d50\u6a23\u5f0f *\/\na:visited {color:#0695e4\n;} \/* \u8a2d\u5b9a\u904e\u53bb\u66fe\u7d93\u95b1\u904e\u7684\u9023\u7d50 *\/\na:hover {color:#0695e4\n;}   \/* \u8a2d\u5b9a\u6ed1\u9f20\u6e38\u6a19\u6307\u5728\u9023\u7d50\u4f4d\u7f6e\u4e0a\u7684\u6a23\u5f0f *\/\na:active {color:#0000BB;}  \/* \u8a2d\u5b9a\u4e0a\u9ede\u64ca\u904e\u7684\u9023\u7d50\u6a23\u5f0f *\/\n<\/style><\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1000\" height=\"526\" src=\"https:\/\/www.circuspi.com\/wp-content\/uploads\/2022\/08\/\u5165\u4fb5\u8005\u8b66\u5831\u5668_1000x526.jpg\" alt=\"\u6a39\u8393\u6d3e\u611f\u6e2c\u5668\u5be6\u4f5c(\u4e8c)\uff1a\u5165\u4fb5\u8005\u8b66\u5831\u5668\" class=\"wp-image-16931\"\/><\/figure><\/div>\n\n\n\n<p><em>\u672c\u6587\u8b6f\u81ea\u6a39\u8393\u6d3e\u96dc\u8a8c 112 \u671f(MagPi issue 112)\uff0c\u539f\u6587\u6a19\u984c\u70ba Make an intruder alarm\uff08\u5716\u7247\u4f86\u6e90\u53d6\u81ea\u96dc\u8a8c\u5167\u9801\uff09\uff0c\u76f8\u95dc\u539f\u59cb\u7a0b\u5f0f\u78bc\u53ef\u53c3\u8003<\/em><a href=\"https:\/\/github.com\/themagpimag\/magpi-issue112\/tree\/master\/SensoryWorld2\" target=\"_blank\" rel=\"noreferrer noopener\"><em>\u5b98\u65b9\u7a0b\u5f0f\u78bc<\/em><\/a><em>\u3002\u672c\u7bc7\u8207\u539f\u6587\u540c\u6a23\u4f7f\u7528CC 3.0 BY-NC-SA\u6388\u6b0a\uff0c\u6b61\u8fce\u6a19\u8a3b\u539f\u4f5c\u8005\u8f49\u8f09\uff0c\u82e5\u6709\u4efb\u4f55\u4e0d\u59a5\u8207\u6307\u6559\u656c\u8acb\u544a\u77e5\u3002<\/em><\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-style-default\"><p>\ud83d\udc40 <strong>\u6a39\u8393\u6d3e\u521d\u5b78\u8005\u770b\u9019\u908a\uff01<\/strong><\/p><cite>\u60f3\u4e86\u89e3\u5165\u9580\u7684\u6559\u5b78\u6559\u6750\u55ce\uff1f\u63a8\u85a6\u53c3\u8003\u300c<a href=\"https:\/\/user113160.psee.io\/4b7ncp\" target=\"_blank\" rel=\"noreferrer noopener\">\u591c\u5e02\u5c0f\u9738\u738b<\/a>\u300d<strong>\u5c24\u6fec\u54f2\u8001\u5e2b<\/strong>\u7684\u7db2\u7ad9\uff0c\u4e00\u8d77\u9032\u5165 Raspberry Pi \u6a39\u8393\u6d3e\u7684\u4e16\u754c\u5427\uff01<\/cite><\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e00\u3001\u524d\u8a00<\/h2>\n\n\n\n<p>\u300c\u6a39\u8393\u6d3e\u611f\u6e2c\u5668\u5be6\u4f5c\u300d\u7cfb\u5217\u6211\u5011\u5c07\u63a2\u7d22\u4e00\u4e9b\u5e38\u898b\u7684\u611f\u6e2c\u5668\uff0c\u4e26\u88fd\u4f5c\u51fa\u53ef\u57f7\u884c\u7684\u5c08\u6848\u3002\u5728<a href=\"https:\/\/www.circuspi.com\/index.php\/2022\/06\/28\/alarm-system\/(\u5728\u65b0\u5206\u9801\u4e2d\u958b\u555f)\" target=\"_blank\" rel=\"noreferrer noopener\">\u5be6\u4f5c(\u4e00)<\/a>\u6211\u5011\u88fd\u4f5c\u4e86\u706b\u7130\u8207\u74e6\u65af\u6d29\u6f0f\u8b66\u5831\u7cfb\u7d71\uff0c\u9019\u6b21\u8981\u4f7f\u7528\u611f\u6e2c\u5668\u88fd\u4f5c\u4e0d\u540c\u7684\u8b66\u5831\u5668\uff0d\u5165\u4fb5\u8005\u8b66\u5831\u5668\u3002<\/p>\n\n\n\n<p>\u8981\u5075\u6e2c\u9644\u8fd1\u662f\u5426\u6709\u4eba\u6709\u5f88\u591a\u53ef\u884c\u7684\u65b9\u6cd5\uff0c\u4f8b\u5982\u4f7f\u7528<a href=\"https:\/\/www.icshop.com.tw\/product_list.php?header_search=PIR\" target=\"_blank\" rel=\"noreferrer noopener\">\u4eba\u9ad4\u7d05\u5916\u7dda\u611f\u6e2c\u5668<\/a>\u6216\u93e1\u982d\uff0c\u672c\u6b21\u6211\u5011\u5c07\u4f7f\u7528\u96f7\u5c04\u5149\u611f\u6e2c\u5668\u8207<a href=\"https:\/\/www.icshop.com.tw\/product_list.php?header_search=Sound+Sensor\" target=\"_blank\" rel=\"noreferrer noopener\">\u8072\u97f3\u611f\u6e2c\u5668<\/a>\uff0c\u7576\u5176\u4e2d\u4e00\u9805\u88ab\u89f8\u767c\u6642\uff0c\u4fbf\u6703\u767c\u51fa\u8996\u89ba\u8207\u807d\u89ba\u7684\u8b66\u5831\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e8c\u3001\u6240\u9700\u8a2d\u5099<\/h2>\n\n\n\n<p>1. \u96f7\u5c04\u5149\u611f\u6e2c\u5668 x1<\/p>\n\n\n\n<p>2. <a href=\"https:\/\/www.icshop.com.tw\/product_list.php?header_search=Sound+Sensor\" target=\"_blank\" rel=\"noreferrer noopener\">\u8072\u97f3\u611f\u6e2c\u5668<\/a> x1<\/p>\n\n\n\n<p>3. <a href=\"https:\/\/www.icshop.com.tw\/product-page.php?2512\" target=\"_blank\" rel=\"noreferrer noopener\">LED \u71c8<\/a> x1<\/p>\n\n\n\n<p>4. <a href=\"https:\/\/www.icshop.com.tw\/product_list.php?header_search=%E6%9C%89%E6%BA%90%E8%9C%82%E9%B3%B4%E5%99%A8\" target=\"_blank\" rel=\"noreferrer noopener\">\u8702\u9cf4\u5668<\/a> x1<\/p>\n\n\n\n<p>5. <a href=\"https:\/\/www.icshop.com.tw\/product_list.php?categories_id=190&amp;header_search=%E9%BA%B5%E5%8C%85%E6%9D%BF\/p_1\" target=\"_blank\" rel=\"noreferrer noopener\">\u9eb5\u5305\u677f<\/a> x1<\/p>\n\n\n\n<p>6. <a href=\"https:\/\/www.icshop.com.tw\/product_list.php?header_search=330+ohm+%E9%9B%BB%E9%98%BBDIP\" target=\"_blank\" rel=\"noreferrer noopener\">330\u03a9 \u96fb\u963b<\/a> x1<\/p>\n\n\n\n<p>7. <a href=\"https:\/\/www.icshop.com.tw\/product_list.php?header_search=%E6%9D%9C%E9%82%A6%E7%B7%9A\/p_1\" target=\"_blank\" rel=\"noreferrer noopener\">\u675c\u90a6\u7dda\u6750<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e09\u3001\u5be6\u4f5c\u6b65\u9a5f<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1. \u9023\u63a5\u96f7\u5c04\u5149\u611f\u6e2c\u5668<\/h3>\n\n\n\n<p>\u56de\u60f3\u4e00\u4e0b\uff0c\u6211\u5011\u66fe\u7d93\u5728\u96fb\u5f71\u4e2d\u770b\u904e\uff0c\u7576\u79d8\u5bc6\u7279\u5de5\u6216\u662f\u5c0f\u5077\u8981\u6f5b\u5165\u76ee\u7684\u5730\u7372\u53d6\u7269\u54c1\u6642\uff0c\u4e0d\u5c0f\u5fc3\u89f8\u52d5\u4e86\u96f7\u5c04\u5149\u4e26\u4e14\u8b66\u9234\u5927\u4f5c\u7684\u5834\u666f\u3002\u6c92\u932f\uff01\u672c\u6b21\u6211\u5011\u8981\u5be6\u4f5c\u7684\u6b63\u662f\u300c\u5165\u4fb5\u8005\u8b66\u5831\u5668\u300d\u3002<\/p>\n\n\n\n<p>\u96f7\u5c04\u5149\u611f\u6e2c\u5668\u4e0d\u65b7\u5730\u767c\u5c04\u96f7\u5c04\u5149\uff0c\u4e26\u50c5\u63a5\u6536\u76f8\u540c\u6ce2\u9577\u7684\u5149\u675f(650 nm)\uff0c\u56e0\u6b64\u5b83\u4e26\u4e0d\u6703\u56e0\u70ba\u5176\u4ed6\u7684\u53ef\u898b\u5149\u800c\u88ab\u89f8\u767c\u3002\u7576\u5b83\u5075\u6e2c\u5230\u5149\u675f\u6642\uff0c\u6578\u4f4d\u8173\u4f4d\u767c\u51fa\u8a0a\u865f 1\uff1b\u7576\u5149\u675f\u88ab\u4e2d\u65b7\u6642\u767c\u51fa\u8a0a\u865f 0\u3002<\/p>\n\n\n\n<p>\u9996\u5148\u95dc\u9589 Raspberry Pi \u6a39\u8393\u6d3e\u7684\u96fb\u6e90\uff0c\u5c07\u96f7\u5c04\u5149\u611f\u6e2c\u5668\u9023\u63a5\u5230\u958b\u767c\u677f\u5982\u4e0b\u5716\u8868\u6240\u793a\uff1a<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/lh6.googleusercontent.com\/bxU5KBenHYdDAE3VW-_EtC0GjM-_AEJwga60OIrpIcfaPMdQeyLPbJHWfDWoyTMUzap4y8MuS3IKw0A1wIak5j1N6_r_vLoMt0fSylsY29PCspuyJH9l9QXq9J5Cjcz9wx7ZTl3d8zByEprpQQ\" alt=\"\u6a39\u8393\u6d3e\u611f\u6e2c\u5668\u5be6\u4f5c(\u4e8c)\uff1a\u5165\u4fb5\u8005\u8b66\u5831\u5668\" width=\"670\" height=\"413\"\/><figcaption>\u57161. \u5165\u4fb5\u8005\u8b66\u5831\u5668\u63a5\u7dda\u5716<\/figcaption><\/figure><\/div>\n\n\n\n<figure class=\"wp-block-table aligncenter is-style-stripes\"><table><tbody><tr><td class=\"has-text-align-center\" data-align=\"center\"><strong>Raspberry Pi \u6a39\u8393\u6d3e<\/strong><\/td><td class=\"has-text-align-center\" data-align=\"center\"><strong>\u96f7\u5c04\u5149\u611f\u6e2c\u5668<\/strong><\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">3.3 V<\/td><td class=\"has-text-align-center\" data-align=\"center\">VCC<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">GND<\/td><td class=\"has-text-align-center\" data-align=\"center\">GND<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">IO21<\/td><td class=\"has-text-align-center\" data-align=\"center\">DO<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">2. \u5b9a\u4f4d\u96f7\u5c04\u5149\u611f\u6e2c\u5668<\/h3>\n\n\n\n<p>\u7576\u9023\u63a5\u597d\u96f7\u5c04\u5149\u611f\u6e2c\u5668\u5f8c\uff0c\u958b\u555f<a href=\"https:\/\/www.icshop.com.tw\/product_list.php?2180\"> Raspberry Pi \u6a39\u8393\u6d3e<\/a>\u7684\u96fb\u6e90\uff0c\u82e5\u662f\u9023\u63a5\u6b63\u78ba\u5c07\u6703\u770b\u5230\u611f\u6e2c\u5668\u53f3\u5074\u4eae\u8d77<strong>\u7d05\u71c8<\/strong>\u3002\u611f\u6e2c\u5668\u5c07\u6703\u5f9e\u91d1\u5c6c\u7ba1\u4e2d\u767c\u5c04\u96f7\u5c04\u5149\u675f\uff0c\u56e0\u6b64\u5207\u8a18\u52ff\u76f4\u8996\u5b83\uff01<\/p>\n\n\n\n<p>\u5c07\u5149\u675f\u5c0d\u6e96\u9644\u8fd1\u7684\u7246\u58c1\uff08\u5927\u7d04 1.5 m \u7684\u8ddd\u96e2\uff09\uff0c\u4e26\u6aa2\u67e5\u5de6\u5074\u7684 LED \u662f\u5426\u4eae\u8d77\uff08\u6307\u793a\u71c8\uff09\uff0c\u78ba\u8a8d\u5b83\u6b63\u5728\u5075\u6e2c\u96f7\u5c04\u5149\u675f\u3002\u4f60\u53ef\u80fd\u9700\u8981\u900f\u904e\u6c34\u5e73\u548c\u5782\u76f4\u7684\u50be\u659c\u4f86\u8abf\u6574\u611f\u6e2c\u5668\uff0c\u6216\u8005\u662f\u5c07\u5176\u66f4\u9760\u8fd1\u7246\u58c1\u3002\u70ba\u4e86\u5b8c\u6210\u8b66\u5831\u5668\uff0c\u6211\u5011\u5efa\u8b70\u5c07\u8b66\u5831\u5668\u5b89\u88dd\u5728\u96e2\u5730\u677f\u5f88\u8fd1\u7684\u5730\u65b9\uff0c\u5982\u6b64\u4e00\u4f86\uff0c\u6709\u4eba\u7d93\u904e\u4fbf\u6703\u4e2d\u65b7\u5149\u675f\u4e5f\u4e0d\u6703\u592a\u9760\u8fd1\u4eba\u5011\u7684\u773c\u775b\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3. \u96f7\u5c04\u5149\u6e2c\u8a66<\/h3>\n\n\n\n<p>\u9996\u5148\uff0c\u6211\u5011\u8981\u64b0\u5beb\u4e00\u500b Python \u7a0b\u5f0f\u300claser_test.py\u300d\uff0c\u53bb\u8b80\u53d6\u611f\u6e2c\u5668\u7684\u6578\u4f4d\u8f38\u51fa\uff0c\u4e26\u5728\u5149\u675f\u4e2d\u65b7\u6642\u986f\u793a\u8a0a\u606f\u3002\u5f9e\u96fb\u8166\u684c\u9762\u7684\u9078\u55ae\u4e2d\uff0c\u6253\u958b <a href=\"https:\/\/thonny.org\/\">Thonny IDE<\/a> \u8edf\u9ad4\u5e73\u53f0\u958b\u59cb\u64b0\u5beb\u7a0b\u5f0f\u3002<\/p>\n\n\n\n<p>\u73fe\u5728\u5c31\u900f\u904e\u624b\u906e\u853d\u4f86\u4e2d\u65b7\u5149\u675f\uff0c\u8a66\u8a66\u770b\u8a0a\u606f\u662f\u5426\u6709\u6539\u8b8a\u5427\uff01<\/p>\n\n\n\n<p>\u5728\u958b\u59cb\u64b0\u5beb\u7a0b\u5f0f\u4e4b\u524d\uff0c\u6211\u5011\u9078\u64c7\u4f7f\u7528 GPIO Zero \u7a0b\u5f0f\u5eab\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n\n\n\n<div style=\"overflow: auto; height: 335px; background-color: #0000;\"><script src=\"https:\/\/gist.github.com\/icchannel\/2828c59ef67a0b800aad24968a9f5e07.js\"><\/script>\n<\/div>\n\n\n\n<p>\u7b2c 1~3 \u884c\uff1a\u5728\u7a0b\u5f0f\u78bc\u4e2d\uff0c\u6211\u5011\u4f7f\u7528 Button \u65b9\u6cd5\u6aa2\u6e2c\u96f7\u5c04\u5149\u611f\u6e2c\u5668\u7684\u6578\u4f4d\u8a0a\u865f\uff0c\u7576\u8a0a\u865f\u70ba 0 \u6642\u5c31\u7b49\u540c\u65bc\u6309\u4e0b\u6309\u9215\u3002\u5982\u540c\u9023\u63a5\u7684\u8173\u4f4d\u70ba IO 21\uff0c\u56e0\u6b64\u6211\u5011\u5c07 laser&nbsp; \u7269\u4ef6\u4f9d\u7167 Button \u65b9\u6cd5\u8a2d\u5b9a\u70ba laser = Button(21)\u3002<\/p>\n\n\n\n<p>\u7b2c 6~11\u884c\uff1a\u8a2d\u5b9a\u4e00\u500b\u8ff4\u5708 while True: \uff0c\u7576\u4e2d\u4f7f\u7528 if\u2026else \u4f86\u5224\u65b7\u8207\u986f\u793a\u611f\u6e2c\u5668\u6578\u4f4d\u8a0a\u865f\u7684\u9ad8\u4f4e\uff0cif laser.value == 0 \u70ba\u5149\u675f\u88ab\u4e2d\u65b7 \uff0cThonny Shell \u986f\u793a\u7a97\u70ba\u300cIntruder!\u300d\uff1b\u53cd\u4e4b\u5247\u986f\u793a\u300cAll clear\u300d\u3002<\/p>\n\n\n\n<p>\u7b2c 12 \u884c\uff1a\u5728\u986f\u793a\u8a2d\u5b9a\u4e2d\u6211\u5011\u52a0\u5165\u4e86 end = \u201c\\r\u201d \uff0c\u5982\u6b64\u4e00\u4f86\u6bcf\u6b21\u986f\u793a\u6587\u5b57\u5c31\u90fd\u6703\u51fa\u73fe\u5728\u540c\u4e00\u884c\u3002<\/p>\n\n\n\n<p>\u73fe\u5728\u5c31\u57f7\u884c\u300claser_test.py\u300d\u7a0b\u5f0f\u78bc\uff0c\u4e26\u4f7f\u7528\u60a8\u7684\u624b\u906e\u853d\u4e2d\u65b7\u5149\u675f\uff0c\u770b\u770b\u986f\u793a\u7a97\u7684\u8a0a\u606f\u662f\u5426\u6703\u8b8a\u70ba\u300cIntruder!\u300d\u3002\u904e\u7a0b\u4e2d\u6703\u767c\u73fe\uff0c\u7576\u624b\u96e2\u611f\u6e2c\u5668\u6bd4\u8f03\u9060\u6642\uff0c\u6548\u679c\u8f03\u70ba\u986f\u8457\u3002\u5373\u4f7f LED \u6307\u793a\u71c8\u53ea\u6709\u77ac\u9593\u7184\u6ec5\uff0c\u9019\u6a23\u5c31\u8db3\u4ee5\u89f8\u767c\u6211\u5011\u5f8c\u9762\u8981\u88fd\u4f5c\u7684\u8b66\u5831\u3002<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-style-default\"><p>\u6ce8\u610f\uff01<\/p><cite>\u96f7\u5c04\u5149\u611f\u6e2c\u5668\u6703\u6301\u7e8c\u767c\u5c04\u96f7\u5c04\u5149\u675f\uff0c\u4f7f\u7528\u6642\u5207\u52ff\u5c07\u5176\u76f4\u5c04\u4eba\u7684\u982d\u90e8\uff0c\u53ef\u80fd\u6703\u9020\u6210\u773c\u775b\u8996\u529b\u7684\u640d\u50b7\u3002<\/cite><\/blockquote>\n\n\n\n<h3 class=\"wp-block-heading\">4. \u52a0\u5165\u8072\u97f3\u611f\u6e2c\u5668<\/h3>\n\n\n\n<p>\u6211\u5011\u5df2\u7d93\u6210\u529f\u8b93\u96f7\u5c04\u5149\u611f\u6e2c\u5668\u904b\u4f5c\u4e86\uff0c\u70ba\u4e86\u8981\u63d0\u9ad8\u9632\u6b62\u5165\u4fb5\u8005\u7684\u898f\u683c\uff0c\u73fe\u5728\u5c31\u8b93\u6211\u5011\u589e\u52a0<a href=\"https:\/\/www.icshop.com.tw\/product_list.php?header_search=Sound+Sensor\">\u8072\u97f3\u611f\u6e2c\u5668<\/a>\u5427\uff01<\/p>\n\n\n\n<p>\u8072\u97f3\u611f\u6e2c\u5668\u6709\u985e\u6bd4\u8207\u6578\u4f4d\u8f38\u51fa\u8173\u4f4d\uff0c\u6211\u5011\u7684\u8b66\u5831\u7cfb\u7d71\u50c5\u9700\u8981\u4f7f\u7528\u6578\u4f4d\u8f38\u51fa\u7684\u8173\u4f4d\u3002\u5c07\u8072\u97f3\u611f\u6e2c\u5668\u9023\u63a5\u5230<a href=\"https:\/\/www.icshop.com.tw\/product_list.php?2180\"> Raspberry Pi \u6a39\u8393\u6d3e<\/a>\u5982\u57161\uff0c\u63a5\u7dda\u8acb\u53c3\u7167\u4e0b\u8868\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-table aligncenter is-style-stripes\"><table><tbody><tr><td class=\"has-text-align-center\" data-align=\"center\"><strong>Raspberry Pi \u6a39\u8393\u6d3e<\/strong><\/td><td class=\"has-text-align-center\" data-align=\"center\"><strong>\u8072\u97f3\u611f\u6e2c\u5668<\/strong><\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">3.3 V<\/td><td class=\"has-text-align-center\" data-align=\"center\">VCC<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">GND<\/td><td class=\"has-text-align-center\" data-align=\"center\">GND<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">IO14<\/td><td class=\"has-text-align-center\" data-align=\"center\">DO<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\uff0a<a href=\"https:\/\/www.icshop.com.tw\/product_list.php?2180\" target=\"_blank\" rel=\"noreferrer noopener\">Raspberry Pi \u6a39\u8393\u6d3e<\/a>\u4e0a\u76843.3 V \u8207 GND \u8173\u4f4d\u900f\u904e\u9eb5\u5305\u677f\u8207\u96f7\u5c04\u5149\u611f\u6e2c\u5668\u5171\u7528\u3002<\/p>\n\n\n\n<p>\u958b\u555f <a href=\"https:\/\/www.icshop.com.tw\/product_list.php?2180\">Raspberry Pi \u6a39\u8393\u6d3e<\/a>\u7684\u96fb\u6e90\u5f8c\u6703\u770b\u5230\u611f\u6e2c\u5668\u5de6\u5074\u7684\u96fb\u6e90\u6307\u793a\u71c8\u4eae\u8d77\u3002\u5982\u679c\u88fd\u9020\u5927\u7684\u566a\u97f3\u6703\u770b\u5230\u611f\u6e2c\u5668\u53f3\u5074\u7684\u6307\u793a\u71c8\u4eae\u8d77\uff0c\u9019\u5c31\u8868\u793a\u566a\u97f3\u6709\u88ab\u5075\u6e2c\u5230\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">5. \u8072\u97f3\u6e2c\u8a66<\/h3>\n\n\n\n<p>\u73fe\u5728\u6211\u5011\u5c31\u4f86\u5efa\u7acb\u4e00\u500b\u7a0b\u5f0f\u300csound_test.py\u300d\u4f86\u6e2c\u8a66\u8072\u97f3\u611f\u6e2c\u5668\u5427\uff01<\/p>\n\n\n\n<div style=\"overflow: auto; height: 320px; background-color: #0000;\"><script src=\"https:\/\/gist.github.com\/icchannel\/4da4ae1a5aaaf5a54122fffbb9c99cbb.js\"><\/script>\n<\/div>\n\n\n\n<p>\u7b2c 1~3 \u884c\uff1a\u4f7f\u7528\u8207\u524d\u9762\u4e00\u6a23\u7684 Button \u65b9\u6cd5\uff0c\u5c07 Raspberry Pi \u6a39\u8393\u6d3e\u7684 GPIO14 \u6307\u5b9a\u70ba sound&nbsp; \u7269\u4ef6 sound = Button(14)\uff0c\u4f86\u5075\u6e2c\u611f\u6e2c\u5668\u662f\u5426\u6709\u89f8\u767c\u3002<\/p>\n\n\n\n<p>\u7b2c 6~11\u884c\uff1a\u8a2d\u5b9a\u4e00\u500b\u8ff4\u5708 while True: \uff0c\u7576\u4e2d\u4f7f\u7528 if\u2026else \u4f86\u5224\u65b7\u8207\u986f\u793a\u611f\u6e2c\u5668\u6578\u4f4d\u8a0a\u865f\u7684\u9ad8\u4f4e\uff0cif sound.value == 1 \u70ba\u5075\u6e2c\u5230\u566a\u97f3\uff0cThonny Shell \u986f\u793a\u7a97\u70ba\u300cIntruder!\u300d\uff1b\u53cd\u4e4b\u5247\u986f\u793a\u300cAll clear\u300d\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">6. \u5be6\u6e2c\u8072\u97f3\u611f\u6e2c\u5668<\/h3>\n\n\n\n<p>\u73fe\u5728\u5c31\u8b93\u6211\u5011\u4f86\u6e2c\u8a66\u8072\u97f3\u611f\u6e2c\u5668\u662f\u5426\u6709\u6b63\u78ba\u904b\u4f5c\u5427\uff01<\/p>\n\n\n\n<p>\u57f7\u884c\u300csound_test.py\u300dPython \u7a0b\u5f0f\u78bc\uff0c\u4e26\u88fd\u9020\u566a\u97f3\u4f7f\u8072\u97f3\u611f\u6e2c\u5668\u53f3\u5074\u7684\u6307\u793a\u71c8\u4eae\u8d77\uff0c\u6703\u767c\u73fe\u8981\u8b93\u566a\u97f3\u9700\u6301\u7e8c\u7d04\u4e00\u79d2\u9418\uff0c\u8a0a\u606f\u6703\u77ed\u66ab\u5730\u5f9e\u300cAll clear\u300d\u8b8a\u6210\u300cIntruder!\u300d\u3002<\/p>\n\n\n\n<p>\u5982\u679c\u6e2c\u8a66\u6642\u6709\u7121\u6cd5\u89f8\u767c\u7684\u72c0\u6cc1\uff0c\u53ef\u4ee5\u5617\u8a66\u8abf\u6574\u611f\u6e2c\u5668\u4e0a\u5370\u6709 D \u7b26\u865f\u7684\u5341\u5b57\u65cb\u9215\uff0c\u4ee5\u9006\u6642\u91dd\u7684\u65b9\u5411\u65cb\u8f49\uff0c\u8abf\u4f4e\u53ef\u8b8a\u96fb\u963b\u4f86\u589e\u52a0\u611f\u6e2c\u5668\u7684\u9748\u654f\u5ea6\uff0c\u4f46\u8acb\u52ff\u904e\u5ea6\u65cb\u8f49\uff0c\u4e0d\u7136\u6703\u5c0e\u81f4\u6307\u793a\u71c8\u6046\u4eae\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">7. \u589e\u52a0\u8996\u89ba\u8b66\u5831<\/h3>\n\n\n\n<p>\u5982\u679c\u524d\u9762\u7684\u611f\u6e2c\u5668\u8207\u7a0b\u5f0f\u78bc\u90fd\u5df2\u7d93\u80fd\u5920\u6b63\u5e38\u904b\u4f5c\u4e86\uff0c\u90a3\u9ebc\u6211\u5011\u5c31\u53ef\u4ee5\u9032\u5165\u5230\u4e0b\u4e00\u500b\u968e\u6bb5\u56c9\uff01<\/p>\n\n\n\n<p>\u96d6\u7136\u8b66\u5831\u5668\u80fd\u5920\u986f\u793a\u8a0a\u606f\u6548\u679c\u5df2\u7d93\u76f8\u7576\u4e0d\u932f\u4e86\uff0c\u4f46\u662f\u70ba\u4e86\u8981\u8ffd\u6c42\u66f4\u597d\u7684\u8b66\u5831\u5668\uff0c\u56e0\u6b64\u9700\u8981\u589e\u52a0\u8996\u89ba\u8207\u8072\u89ba\u7684\u8b66\u793a\u6548\u679c\u3002<\/p>\n\n\n\n<p>\u5728\u4e0a\u4e00\u7bc7\u5be6\u4f5c(\u4e00)\u4e2d\uff0c\u6211\u5011\u4f7f\u7528\u4e865 mm \u7684\u7d05\u8272 LED \u71c8\u4f86\u4f5c\u70ba\u8996\u89ba\u7684\u8b66\u793a(\u7576\u7136\u4e5f\u53ef\u4ee5\u9078\u64c7\u5176\u4ed6\u5c3a\u5bf8)\u3002\u4e00\u5982\u65e2\u5f80\u7684\uff0c\u70ba\u4e86\u8981\u907f\u514d LED \u71d2\u58de\uff0c\u56e0\u6b64\u6211\u5011\u9084\u8981\u52a0\u5165\u4e00\u500b\u96fb\u963b\u53bb\u9650\u5236\u96fb\u6d41\u3002<\/p>\n\n\n\n<p>\u5c07 LED \u7684\u5169\u96bb\u8173\u63d2\u5728\u9eb5\u5305\u677f\u4e0d\u540c\u884c\u4e0a\uff0c\u4e26\u5728\u9670\u6975\uff08\u77ed\uff09\u8173\u9023\u63a5\u4e00\u500b 330\u03a9 \u7684\u96fb\u963b\u5728\u9eb5\u5305\u677f\u7684\u8ca0\u96fb\u5340\uff0c\u800c\u967d\u6975\uff08\u5f4e\u66f2\uff0c\u9577\uff09\u8173\u9023\u63a5\u5230 Raspberry Pi \u6a39\u8393\u6d3e IO16 \u7684\u8173\u4f4d\uff0c\u5982\u57161 \u6240\u793a\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">8. \u9023\u63a5\u8702\u9cf4\u5668<\/h3>\n\n\n\n<p>\u5728\u807d\u89ba\u8b66\u5831\u7684\u90e8\u5206\uff0c\u6211\u5011\u4f7f\u7528\u4e00\u500b\u6709\u6e90\u8702\u9cf4\u5668\u767c\u51fa\u8072\u97ff\u3002\u6709\u6e90\u8702\u9cf4\u5668\u8f03\u9577\u7684\u8173\u70ba\u967d\u6975\uff0c\u8f03\u77ed\u7684\u8173\u70ba\u9670\u6975\uff08\u8702\u9cf4\u5668\u672c\u8eab\u53ef\u80fd\u6703\u6a19\u793a\u5b83\u5011\u7684\u4f4d\u7f6e\uff09\u3002\u5c07\u9670\u6975\u8173\u9023\u63a5\u5230\u9eb5\u5305\u677f\u7684\u8ca0\u6975\uff0c\u800c\u967d\u6975\u8173\u9023\u63a5\u5230 Raspberry Pi \u6a39\u8393\u6d3e IO25 \u7684\u8173\u4f4d\uff0c\u5982\u5716 1 \u6240\u793a\uff0c\u5b8c\u6210\u5f8c\u7684\u6210\u54c1\u5982\u5716 2 \u6240\u793a\u3002<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.circuspi.com\/wp-content\/uploads\/2022\/06\/8B7F82EA-471B-4ded-91E4-CAC980215FD2-1.png\" alt=\"\u6a39\u8393\u6d3e\u611f\u6e2c\u5668\u5be6\u4f5c(\u4e8c)\uff1a\u5165\u4fb5\u8005\u8b66\u5831\u5668\" class=\"wp-image-16552\" width=\"780\" height=\"440\"\/><figcaption>\u5716 2. \u5165\u4fb5\u8005\u8b66\u5831\u5668\u5b8c\u6210\u5716<\/figcaption><\/figure><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">9. \u64b0\u5beb\u8b66\u5831\u5668\u7a0b\u5f0f\u78bc<\/h3>\n\n\n\n<p>\u7576\u6240\u6709\u786c\u9ad4\u90fd\u5982\u57161\u8a2d\u7f6e\u5b8c\u6210\u5f8c\uff0c\u6211\u5011\u5c31\u53ef\u4ee5\u6e96\u5099\u958b\u59cb\u64b0\u5beb\u5165\u4fb5\u8005\u8b66\u5831\u5668\u7684\u7a0b\u5f0f\u78bc\u4e86\uff01<\/p>\n\n\n\n<div style=\"overflow: auto; height: 540px; background-color: #0000;\">\n<script src=\"https:\/\/gist.github.com\/icchannel\/f5e7204b170bf2fb563e9e8fd831ec32.js\"><\/script>\n<\/div>\n\n\n\n<p>\u7b2c 1~2 \u884c\uff1a\u5728\u6700\u7d42\u7248\u7684\u300cintruder_alarm.py\u300d\u7a0b\u5f0f\u78bc\u4e2d\uff0c\u6211\u5011\u9996\u5148\u8f38\u5165 GPIO Zero \u7a0b\u5f0f\u5eab\u7684 LED \u8207\u8702\u9cf4\u5668\uff0c\u4e26\u4e14\u4f7f\u7528\u6642\u9593\u7a0b\u5f0f\u5eab\u4e2d\u7684\u4f11\u7720\uff0c\u7528\u4f86\u4f5c\u70ba\u5ef6\u9072\u4f7f\u7528\u3002<\/p>\n\n\n\n<p>\u7b2c 9~14 \u884c\uff1a\u53ef\u4ee5\u4f9d\u7167\u4e0d\u540c\u7684\u8b66\u5831\u5efa\u7acb\u7368\u7acb\u7684\u8b66\u793a\u8a0a\u606f\uff08\u5c31\u50cf\u5be6\u4f5c(\u4e00)\u7684\u706b\u7130\u8207\u74e6\u65af\u8b66\u5831\u7cfb\u7d71\uff09\uff0c\u4f46\u662f\u9019\u6b21\u6211\u5011\u70ba\u4e86\u8981\u7c21\u5316\u5728\u6c92\u6709\u5075\u6e2c\u5230\u5165\u4fb5\u8005\u72c0\u614b\u7684\u7a0b\u5f0f\uff0c\u56e0\u6b64\u4e26\u6c92\u6709\u5206\u6210\u5169\u7a2e\u8b66\u793a\u8a0a\u606f\u3002<\/p>\n\n\n\n<p>\u7576\u89f8\u767c\u6642\uff0c\u5c07\u6703\u57f7\u884c for \u8ff4\u5708\u4f86\u63a7\u5236 LED \u8207\u8702\u9cf4\u5668\u958b\u95dc\u5207\u63db\u7684\u6b21\u6578\uff0c\u4e26\u4e14\u52a0\u5165 0.5 \u79d2\u7684\u4f11\u7720\u4f5c\u70ba\u5ef6\u9072\u3002<\/p>\n\n\n\n<p>\u7b2c16~22 \u884c\uff1a\u5728 while True: \u8ff4\u5708\u4e2d\uff0c\u6211\u5011\u7528\u4f86\u6aa2\u6e2c pin \u8173\u5f9e\u611f\u6e2c\u5668\u6240\u63a5\u6536\u5230\u7684\u8a0a\u865f\uff0c\u7576\u96f7\u5c04\u5149\u88ab\u4e2d\u65b7(laser.value == 0)\uff0c\u6216\u662f\u7576\u8072\u97f3\u5df2\u5230\u9054\u95a5\u503c\u6642(sound.value == 1)\uff0c\u4fbf\u6703\u89f8\u767c\u8b66\u5831\u3002\u82e5\u662f\u5728\u672a\u89f8\u767c\u7684\u60c5\u6cc1\u4e0b\uff0c\u9810\u8a2d\u986f\u793a\u8a0a\u606f\u70ba\u300cAll Clear\u300d\uff0c LED \u8207\u8702\u9cf4\u5668\u7686\u70ba\u95dc\u9589\u7684\u72c0\u614b\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">10. \u5be6\u6e2c\u8b66\u5831\u7cfb\u7d71<\/h3>\n\n\n\n<p>\u63a5\u8457\u5c31\u4f86\u6e2c\u8a66\u5165\u4fb5\u8005\u8b66\u5831\u5668\u5427\uff01<\/p>\n\n\n\n<p>\u9996\u5148\uff0c\u5617\u8a66\u5c07\u96f7\u5c04\u5149\u611f\u6e2c\u5668\u7684\u96f7\u5c04\u5149\u675f\u4e2d\u65b7\u5982\u4e0b\u5716 3 \u6240\u793a\uff0c\u6b64\u6642 LED \u9583\u720d\uff0c\u8702\u9cf4\u5668\u6703\u767c\u51fa\u8072\u97ff\uff0cShell \u8996\u7a97\u986f\u793a\u300cIntruder!\u300d\u3002\u63a5\u4e0b\u4f86\uff0c\u6211\u5011\u88fd\u9020\u4e00\u500b\u8f03\u9577\u6642\u9593\u7684\u566a\u97f3\uff0c\u6e2c\u8a66\u8072\u97f3\u611f\u6e2c\u5668\u662f\u5426\u6b63\u5e38\u904b\u4f5c\u3002<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"619\" height=\"360\" src=\"https:\/\/www.circuspi.com\/wp-content\/uploads\/2022\/06\/89BFCD44-9120-4245-9FAF-0EDAF96E3805.png\" alt=\"\u6a39\u8393\u6d3e\u611f\u6e2c\u5668\u5be6\u4f5c(\u4e8c)\uff1a\u5165\u4fb5\u8005\u8b66\u5831\u5668\" class=\"wp-image-16553\"\/><figcaption>\u5716 3. \u4e2d\u65b7\u96f7\u5c04\u5149\u6e2c\u8a66<\/figcaption><\/figure><\/div>\n\n\n\n<blockquote class=\"wp-block-quote is-style-default\"><p><strong>\u5c0f\u79d8\u8a23<\/strong><\/p><cite>\u70ba\u4e86\u7c21\u5316\u786c\u9ad4\u914d\u7f6e\uff0c\u6211\u5011\u4f7f\u7528\u8072\u97f3\u611f\u6e2c\u5668\u7684\u6578\u4f4d\u8f38\u51fa\u53bb\u89f8\u767c\u6211\u5011\u7684\u8b66\u5831\u5668\u3002\u5982\u679c\u662f\u4f7f\u7528\u985e\u6bd4\u8f38\u51fa\uff0c\u5c07\u6703\u9700\u8981\u589e\u52a0\u4e00\u500b\u985e\u6bd4\u6578\u4f4d\u8f49\u63db\u5668\uff08\u5982 MCP3008\uff09\uff0c\u5c07\u8a0a\u865f\u8f49\u63db\u4f5c\u70ba\u6578\u4f4d\u8b80\u53d6\u3002\u4e0b\u4e00\u500b\u5be6\u4f5c\u6211\u5011\u5c07\u6559\u5b78\u5982\u4f55\u4f7f\u7528\u985e\u6bd4\u6578\u4f4d\u8f49\u63db\u5668\u3002<\/cite><\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\">\u56db\u3001\u5c0f\u7d50<\/h2>\n\n\n\n<p>\u73fe\u5728\u6211\u5011\u6709\u4e00\u500b\u7c21\u6613\u7684\u5165\u4fb5\u8005\u8b66\u5831\u5668\u4e86\uff01\u70ba\u4e86\u66f4\u9032\u4e00\u6b65\u7684\u5b8c\u5584\u5b83\uff0c\u9084\u53ef\u4ee5\u589e\u52a0\u984d\u5916\u7684\u611f\u6e2c\u5668\uff0c\u4f8b\u5982\u4eba\u9ad4\u7d05\u5916\u7dda\u611f\u6e2c\u5668\uff0c\u6216\u8005\u662f\u4f7f\u7528\u93e1\u982d\u53bb\u5075\u6e2c\u52d5\u614b\u5165\u4fb5\u8005\uff0c\u4e5f\u53ef\u4ee5\u589e\u52a0\u66f4\u5927\u7684\u71c8\u865f\uff0c\u6216\u8005\u662f\u5587\u53ed\u64a5\u653e\u8b66\u793a\u97f3\uff0c\u7576\u7136\u4e5f\u53ef\u4ee5\u8a2d\u5b9a\u7576\u767c\u751f\u8b66\u5831\u6642\u767c\u9001 email \u6216\u63d0\u793a\u8a0a\u606f\u5230\u624b\u6a5f\u3002\u5c31\u770b\u5404\u4f4d\u7684\u5275\u610f\u767c\u60f3\u56c9\uff01<\/p>\n\n\n\n<p>\u4e0b\u4e00\u6b21\u6211\u5011\u5c07\u5206\u4eab\u5982\u4f55\u5be6\u4f5c\u7c21\u6613\u6c23\u8c61\u7ad9\u7684\u6587\u7ae0\uff0c\u6709\u8208\u8da3\u7684\u5925\u4f34\u5011\u8acb\u5e6b\u6211\u5011\u591a\u591a\u5206\u4eab\u4e26\u6301\u7e8c\u95dc\u6ce8\u6211\u5011\u5594\uff01\u4e0b\u6b21\u898b\uff5e<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u300c\u6a39\u8393\u6d3e\u611f\u6e2c\u5668\u5be6\u4f5c\u300d\u7cfb\u5217\u6211\u5011\u5c07\u63a2\u7d22\u4e00\u4e9b\u5e38\u898b\u7684\u611f\u6e2c\u5668\uff0c\u4e26\u88fd\u4f5c\u51fa\u53ef\u57f7\u884c\u7684\u5c08\u6848\u3002\u672c\u6b21\u5be6\u4f5c\u7684\u5c08\u6848\u76ee\u6a19\uff1a\u88fd\u4f5c\u4e00\u500b\u7c21\u6613\u7684\u5c0f\u578b\u5165\u4fb5\u8005\u8b66\u5831\u5668\uff0c\u900f\u904e\u96f7\u5c04\u5149\u8207\u8072\u97f3\u611f\u6e2c\u5668\u53bb\u5075\u6e2c\uff0c\u7576\u6709\u4eba\u5165\u4fb5\u6642\uff0c\u8b66\u5831\u5668\u4fbf\u6703\u51fa\u8072\u5149\u8b66\u793a\u63d0\u9192\u4eba\u5011\u3002\u73fe\u5728\u5c31\u4e00\u8d77\u4f86\u52d5\u624b\u5be6\u4f5c\u5427\uff01<\/p>\n","protected":false},"author":1,"featured_media":16932,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[112,238],"tags":[23,113],"table_tags":[],"_links":{"self":[{"href":"https:\/\/www.circuspi.com\/index.php\/wp-json\/wp\/v2\/posts\/16551"}],"collection":[{"href":"https:\/\/www.circuspi.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.circuspi.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.circuspi.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.circuspi.com\/index.php\/wp-json\/wp\/v2\/comments?post=16551"}],"version-history":[{"count":10,"href":"https:\/\/www.circuspi.com\/index.php\/wp-json\/wp\/v2\/posts\/16551\/revisions"}],"predecessor-version":[{"id":16980,"href":"https:\/\/www.circuspi.com\/index.php\/wp-json\/wp\/v2\/posts\/16551\/revisions\/16980"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.circuspi.com\/index.php\/wp-json\/wp\/v2\/media\/16932"}],"wp:attachment":[{"href":"https:\/\/www.circuspi.com\/index.php\/wp-json\/wp\/v2\/media?parent=16551"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.circuspi.com\/index.php\/wp-json\/wp\/v2\/categories?post=16551"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.circuspi.com\/index.php\/wp-json\/wp\/v2\/tags?post=16551"},{"taxonomy":"table_tags","embeddable":true,"href":"https:\/\/www.circuspi.com\/index.php\/wp-json\/wp\/v2\/table_tags?post=16551"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}