{"id":7881,"date":"2020-10-22T00:00:13","date_gmt":"2020-10-21T15:00:13","guid":{"rendered":"https:\/\/techclass.wfjydl.com\/?p=7881"},"modified":"2022-09-09T17:14:51","modified_gmt":"2022-09-09T09:14:51","slug":"%e4%bc%ba%e6%9c%8d%e7%94%b5%e6%9c%ba%e6%8e%a7%e5%88%b6%e7%9a%84%e6%97%a0%e7%ba%bf%e7%94%b5%e7%81%af%e5%bc%80%e5%85%b3-%e7%ac%ac%e4%ba%8c%e9%83%a8%e5%88%86","status":"publish","type":"post","link":"https:\/\/techclass.wfjydl.com\/knowledge\/tech-info\/how-tos\/arduino\/servo-motor-controlled-wireless-light-switch-2","title":{"rendered":"\u4f3a\u670d\u7535\u673a\u63a7\u5236\u7684\u65e0\u7ebf\u7535\u706f\u5f00\u5173-\u7b2c\u4e8c\u90e8\u5206"},"content":{"rendered":"<p><script type=\"text\/javascript\" src=\"https:\/\/ssl-cache.stream.ne.jp\/www50\/eqa194obdo\/jmc_pub\/jmc_swf\/player\/t3\/if.js\" charset=\"UTF-8\"><\/script><\/p>\n<div class=\u201cthe_content_wrapper\u201d>\n\u8fd9\u7bc7\u6587\u7ae0\u6765\u6e90\u4e8e<a href=\"https:\/\/www.deviceplus.com\/\">DevicePlus.com<\/a>\u82f1\u8bed\u7f51\u7ad9\u7684\u7ffb\u8bd1\u7a3f\u3002<\/p>\n<h2>\u76ee\u5f55<\/h2>\n<p>&nbsp;<\/p>\n<ul>\n<li><strong><a href=\"https:\/\/techclass.wfjydl.com\/knowledge\/tech-info\/how-tos\/arduino\/servo-motor-controlled-wireless-light-switch-1\">\u2022\t\u7b2c\u4e00\u90e8\u5206<\/a><br \/>\n<\/strong>\u4ec0\u4e48\u662f\u4f3a\u670d\u7535\u673a\uff1f<br \/>\n\u4f3a\u670d\u7535\u673a\u7684\u7c7b\u578b<br \/>\n\u6240\u9700\u7535\u538b\u548c\u7535\u6e90<\/li>\n<p>&nbsp;<\/p>\n<li><strong>\u2022\t\u7b2c\u4e8c\u90e8\u5206<br \/>\n<\/strong>\u57fa\u4e8eArduino\u7a0b\u5e8f\u7684\u4f3a\u670d\u63a7\u5236<br \/>\n\u4f3a\u670d\u7535\u673a\u53ef\u4ee5\u505a\u4ec0\u4e48\uff1f<\/li>\n<p>&nbsp;<\/p>\n<li><strong><a href=\"https:\/\/techclass.wfjydl.com\/knowledge\/tech-info\/how-tos\/arduino\/servo-motor-controlled-wireless-light-switch-3\">\u2022\t\u7b2c\u4e09\u90e8\u5206<\/a><br \/>\n<\/strong>\u4f3a\u670d\u63a7\u5236\u7535\u706f\u5f00\u5173<br \/>\n\u7535\u706f\u5f00\u5173\u7684\u8fdc\u7a0b\u63a7\u5236<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<h2><b>4. \u57fa\u4e8eArduino\u7a0b\u5e8f\u7684\u4f3a\u670d\u63a7\u5236<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">Arduino\u5bf9\u4f3a\u670d\u7535\u673a\u63a7\u5236\u7684\u65b9\u5f0f\u5927\u81f4\u6709\u4e24\u79cd\u3002<\/span><\/p>\n<p><span style=\"font-weight: 400;\">PWM\uff08\u8109\u51b2\u5bbd\u5ea6\u8c03\u5236\uff09\u662f\u4e00\u79cd\u901a\u8fc7\u6253\u5f00\u548c\u5173\u95ed\u8109\u51b2\u4fe1\u53f7\u6765\u63a7\u5236\u7535\u673a\u7684\u65b9\u6cd5\u3002\u901a\u8fc7\u76f4\u63a5\u4f7f\u7528PWM\u6765\u63a7\u5236\u4f3a\u670d\u7535\u673a\u53ef\u4ee5\u5b9e\u73b0\u6b65\u8fdb\u5f0f\u8f6c\u52a8\u3002\u4f46\u662f\u5bf9\u4e8e\u66f4\u590d\u6742\u7684\u9879\u76ee\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528Arduino IDE\u4e2d\u5305\u542b\u7684\u4f3a\u670d\u7535\u673a\u5e93\u3002<\/span><\/p>\n<p><b>Arduino IDE \u2192 [File] \u2192 [Examples] \u2192 [10.StarterKit BasicKit] \u2192 [p05_ServoMoodindicator]<\/b><\/p>\n<p><span style=\"font-weight: 400;\">\u8be5\u7a0b\u5e8f\u53ef\u4ee5\u6839\u636e\u6a21\u62df\u5f15\u811a0\uff08A0\uff09\u7684\u8f93\u5165\u503c\u6765\u66f4\u6539\u4f3a\u670d\u7535\u673a\u7684\u89d2\u5ea6\u3002\u5728\u6a21\u62df\u5f15\u811a\u4e0a\u4f7f\u7528\u7535\u4f4d\u8ba1\u6216\u5149\u5b66\u4f20\u611f\u5668\u7b49\u53ef\u53d8\u7535\u963b\uff0c\u901a\u8fc7\u7535\u963b\u503c\u7684\u53d8\u5316\u6765\u5b9e\u73b0\u7535\u673a\u7684\u8f6c\u52a8\u3002<\/span><\/p>\n<p><b>\u4f3a\u670d\u7535\u673a\u5e93\u51fd\u6570<\/b><\/p>\n<p><span style=\"font-weight: 400;\">\u4f3a\u670d\u7535\u673a\u5e93\u57fa\u4e8e\u4e24\u79cd\u7c7b\u578b\u7684\u6307\u4ee4\uff1a1\uff09\u6307\u5b9a\u8981\u53d1\u9001\u5230\u4f3a\u670d\u7535\u673a\u7684\u63a7\u5236\u4fe1\u53f7\u7684\u5f15\u811a\u7f16\u53f7\u30022\uff09\u6307\u5b9a\u4f3a\u670d\u7535\u673a\u8f6c\u52a8\u65f6\u7684\u89d2\u5ea6\u3002<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><strong>\u4ee3\u7801\u2014\u793a\u4f8b<\/strong><\/p>\n<p><!-- Crayon Syntax Highlighter v_2.7.2_beta --><\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism undefined-numbers lang-c\" data-lang=\"C\"><code>myServo.attach(9); \/\/Specify the servo motor's signal pin\r\n<\/code><\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<p><strong>\u4ee3\u7801\u2014\u793a\u4f8b<\/strong><\/p>\n<p><!-- Crayon Syntax Highlighter v_2.7.2_beta --><\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism undefined-numbers lang-c\" data-lang=\"C\"><code>myServo.write(angle); \/\/Move the servomotor to a specific angle\r\n<\/code><\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">\u4ee5\u4e0b\u7535\u8def\u662f\u4f7f\u7528FEETECH FS90\u5fae\u4f3a\u670d\u7535\u673a\u7684\u793a\u4f8b\u3002\u8be5\u4f3a\u670d\u7535\u673a\u7684\u5de5\u4f5c\u7535\u538b\u662f6V\u3002\u7531\u4e8e\u5de5\u4f5c\u65f6\u7684\u7535\u6d41\u662f200 mA\uff0c\u56e0\u6b64\u4f3a\u670d\u7535\u673a\u7531\u56db\u8282AA\u7535\u6c60\u4e32\u8054\u4f9b\u7535\uff086V\uff09\u3002<\/span><\/p>\n<div id=\"attachment_6545\" style=\"width: 710px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-6545\" class=\"size-full wp-image-6545\" src=\"https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2017\/09\/image013-3.jpg\" alt=\"diy wireless light switch\" width=\"700\" height=\"387\" srcset=\"https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2017\/09\/image013-3.jpg 700w, https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2017\/09\/image013-3-300x166.jpg 300w, https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2017\/09\/image013-3-260x144.jpg 260w, https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2017\/09\/image013-3-50x28.jpg 50w, https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2017\/09\/image013-3-136x75.jpg 136w\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" \/><\/p>\n<p id=\"caption-attachment-6545\" class=\"wp-caption-text\">\u56fe6\uff1a\u793a\u4f8b\u7535\u8def\u56fe<\/p>\n<\/div>\n<p>&nbsp;<\/p>\n<div id=\"attachment_6546\" style=\"width: 710px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-6546\" class=\"size-full wp-image-6546\" src=\"https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2017\/09\/image015-3.jpg\" alt=\"diy wireless light switch\" width=\"700\" height=\"394\" srcset=\"https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2017\/09\/image015-3.jpg 700w, https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2017\/09\/image015-3-300x169.jpg 300w, https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2017\/09\/image015-3-260x146.jpg 260w, https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2017\/09\/image015-3-50x28.jpg 50w, https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2017\/09\/image015-3-133x75.jpg 133w\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" \/><\/p>\n<p id=\"caption-attachment-6546\" class=\"wp-caption-text\">\u56fe7\uff1a\u4f3a\u670d\u7535\u673a\u63a7\u5236\u7535\u8def<\/p>\n<\/div>\n<p>&nbsp;<\/p>\n<div id=\"attachment_6547\" style=\"width: 710px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-6547\" class=\"size-full wp-image-6547\" src=\"https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2017\/09\/image017-3.jpg\" alt=\"diy wireless light switch\" width=\"700\" height=\"319\" srcset=\"https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2017\/09\/image017-3.jpg 700w, https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2017\/09\/image017-3-300x137.jpg 300w, https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2017\/09\/image017-3-260x118.jpg 260w, https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2017\/09\/image017-3-50x23.jpg 50w, https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2017\/09\/image017-3-150x68.jpg 150w\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" \/><\/p>\n<p id=\"caption-attachment-6547\" class=\"wp-caption-text\">\u56fe8\uff1a p05_ServoMoodIndicator<\/p>\n<\/div>\n<p><strong>\u4ee3\u7801\u2014\u793a\u4f8b<\/strong><\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism undefined-numbers lang-c\" data-lang=\"C\"><code>\/*\r\nArduino Starter Kit example\r\nProject 5 - Servo Mood Indicator\r\n \r\nThis sketch is written to accompany Project 5 in the\r\nArduino Starter Kit\r\n \r\nParts required:\r\nservo motor\r\n10 kilohm potentiometer\r\n2 100 uF electrolytic capacitors\r\n \r\nCreated 13 September 2012\r\nby Scott Fitzgerald\r\n \r\nhttps:\/\/www.arduino.cc\/starterKit\r\n \r\nThis example code is part of the public domain\r\n*\/\r\n \r\n\/\/ include the servo library\r\n#include &amp;lt;Servo.h&amp;gt;\r\n \r\nServo myServo; \/\/ create a servo object\r\n \r\nint const potPin = A0; \/\/ analog pin used to connect the potentiometer\r\nint potVal; \/\/ variable to read the value from the analog pin\r\nint angle; \/\/ variable to hold the angle for the servo motor\r\n \r\nvoid setup() {\r\nmyServo.attach(9); \/\/ attaches the servo on pin 9 to the servo object\r\nSerial.begin(9600); \/\/ open a serial connection to your computer\r\n}\r\n \r\nvoid loop() {\r\npotVal = analogRead(potPin); \/\/ read the value of the potentiometer\r\n\/\/ print out the value to the serial monitor\r\nSerial.print(\"potVal: \");\r\nSerial.print(potVal);\r\n \r\n\/\/ scale the numbers from the pot\r\nangle = map(potVal, 0, 1023, 0, 179);\r\n \r\n\/\/ print out the angle for the servo motor\r\nSerial.print(\", angle: \");\r\nSerial.println(angle);\r\n \r\n\/\/ set the servo position\r\nmyServo.write(angle);\r\n \r\n\/\/ wait for the servo to get there\r\ndelay(15);\r\n}\r\n<\/code><\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<div style=\"position: relative; height: 0; padding-bottom: 56.25%;\"><script type=\"text\/javascript\">\n\tjstream_t3.PlayerFactoryIF.create({\n\tb:\"eqa194obdo.eq.webcdn.stream.ne.jp\/www50\/eqa194obdo\/jmc_pub\/jmc_swf\/player\/\",\n\tc:\"NDc3\",\n\tm:\"NTQ3\",\n\ts:{\n\t\thp:360,\n\t\til:\"off\",\n\t\trb:\"off\",\n\t\tsn:\"f,t,g\",\n\t\twp:640\n\t}});\n<\/script><\/div>\n<p>&nbsp;<\/p>\n<h2><b>5. \u4f3a\u670d\u7535\u673a\u53ef\u4ee5\u505a\u4ec0\u4e48\uff1f<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">\u8ba9\u6211\u4eec\u7b80\u8981\u56de\u987e\u4e00\u4e0b\u4f7f\u7528\u4f3a\u670d\u7535\u673a\u53ef\u4ee5\u5b8c\u6210\u7684\u5de5\u4f5c\u3002\u4ee5\u4e0b\u662f\u4e24\u79cd\u5178\u578b\u5de5\u4f5c\u65b9\u5f0f\uff1a<\/span><\/p>\n<h2><b>I. \u6309\u4e0b\u6309\u94ae<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">\u4f3a\u670d\u7535\u673a\u53ef\u4ee5\u63a7\u5236\u8f6c\u52a8\u7684\u89d2\u5ea6\u3002\u8fd9\u5c31\u662f\u4e3a\u4ec0\u4e48\u4f3a\u670d\u7535\u673a\u6700\u9002\u4e8e\u5f00\u53d1\u6309\u94ae\u63a7\u5236\u7684\u673a\u68b0\u7cfb\u7edf\u3002\u60a8\u53ef\u4ee5\u50cf\u4e0b\u9762\u7684\u89c6\u9891\u4e2d\u90a3\u6837\u5236\u4f5c\u4e00\u4e9b\u6709\u8da3\u7684\u8bbe\u5907\uff0c\u5e76\u4e14\u4e5f\u53ef\u4ee5\u5f00\u53d1\u51fa\u4ec5\u901a\u8fc7\u4e00\u4e2a\u6309\u94ae\u6765\u5b9e\u73b0\u63a7\u5236\u7684\u591a\u79cd\u8bbe\u5907\uff0c\u5982\u623f\u95f4\u91cc\u7684\u5f00\u5173\u7b49\u7b49\u3002<\/span><\/p>\n<p>&nbsp;<\/p>\n<div style=\"position: relative; height: 0; padding-bottom: 56.25%;\"><script type=\"text\/javascript\">\n\tjstream_t3.PlayerFactoryIF.create({\n\tb:\"eqa194obdo.eq.webcdn.stream.ne.jp\/www50\/eqa194obdo\/jmc_pub\/jmc_swf\/player\/\",\n\tc:\"NDc3\",\n\tm:\"NTQ4\",\n\ts:{\n\t\thp:360,\n\t\til:\"off\",\n\t\trb:\"off\",\n\t\tsn:\"f,t,g\",\n\t\twp:640\n\t}});\n<\/script><\/div>\n<p>&nbsp;<\/p>\n<h2><b>II. \u79fb\u52a8\u7269\u4f53<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">\u5728<\/span><a href=\"https:\/\/www.deviceplus.com\/arduino\/entry013\/\"><b>\u4f7f\u7528Arduino\u63a7\u5236\u7535\u673a\u7684\u7b2c\u4e09\u90e8\u5206\u2014\u2014\u5236\u9020\u4e00\u8f86\u901a\u8fc7\u4f3a\u670d\u7535\u673a\u63a7\u5236\u8f6c\u5411\u7684RC\u8f66<\/b><\/a><span style=\"font-weight: 400;\">\u4e2d,\u6211\u4eec\u4f7f\u7528LEGO\u5236\u9020\u4e86\u4e00\u53f0RC\u8f66\u3002\u6211\u4eec\u5b89\u88c5\u4e86\u901a\u8fc7\u4f3a\u670d\u7535\u673a\u8fdb\u884c\u63a7\u5236\u7684\u8f6c\u5411\u90e8\u4ef6\u3002\u4f3a\u670d\u7535\u673a\u53ef\u4ee5\u7528\u4e8e\u591a\u79cd\u5668\u4ef6\uff0c\u4f46\u662f\u5b83\u901a\u5e38\u7528\u4e8e\u201c\u79fb\u52a8\u201d\u90e8\u4ef6\/\u7269\u4f53\uff0c\u4f8b\u5982\u79fb\u52a8\u673a\u5668\u4eba\u6c7d\u8f66\u6216<\/span><a href=\"https:\/\/www.deviceplus.com\/arduino\/smart-robotic-arm-part-1-mechanics-and-wiring\/\"><b>\u673a\u5668\u4eba\u624b\u81c2<\/b><\/a><span style=\"font-weight: 400;\">\u7b49\u3002<\/span><\/p>\n<p>&nbsp;<\/p>\n<div style=\"position: relative; height: 0; padding-bottom: 56.25%;\"><script type=\"text\/javascript\">\n\tjstream_t3.PlayerFactoryIF.create({\n\tb:\"eqa194obdo.eq.webcdn.stream.ne.jp\/www50\/eqa194obdo\/jmc_pub\/jmc_swf\/player\/\",\n\tc:\"NDc3\",\n\tm:\"NTQ2\",\n\ts:{\n\t\thp:360,\n\t\til:\"off\",\n\t\trb:\"off\",\n\t\tsn:\"f,t,g\",\n\t\twp:640\n\t}});\n<\/script><\/div>\n<div class=\"author-box-wrapper\">\n<div class=\"avatar-wrapper\">\n\t\t<img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/micro.wfjydl.com\/deviceplus\/wp-content\/uploads\/2018\/08\/Device-Plus-logo-for-author-info-75x75.png\" width=\"64\" height=\"64\" alt=\"DevicePlus \u7f16\u8f91\u56e2\u961f\">\n\t<\/div>\n<div class=\"desc-wrapper\">\n<h5>DevicePlus \u7f16\u8f91\u56e2\u961f<\/h5>\n<div class=\"desc\">\n<p>\u8bbe\u5907\u5347\u7ea7\u7248\u9002\u7528\u4e8e\u6240\u6709\u70ed\u7231\u7535\u5b50\u548c\u673a\u7535\u4e00\u4f53\u5316\u7684\u4eba\u3002<\/p>\n<\/div><\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"\u8fd9\u7bc7\u6587\u7ae0\u6765\u6e90\u4e8eDevicePlus.com\u82f1\u8bed\u7f51\u7ad9\u7684\u7ffb\u8bd1\u7a3f\u3002 \u76ee\u5f55 &nbsp; \u2022 \u7b2c\u4e00\u90e8\u5206 \u4ec0\u4e48\u662f\u4f3a\u670d\u7535\u673a\uff1f \u4f3a\u670d\u7535\u673a\u7684\u7c7b\u578b \u6240\u9700\u7535\u538b\u548c\u7535\u6e90 &nbsp; \u2022 \u7b2c\u4e8c\u90e8\u5206 \u57fa\u4e8eArduino\u7a0b\u5e8f\u7684\u4f3a\u670d\u63a7\u5236 \u4f3a\u670d\u7535\u673a\u53ef\u4ee5 [&hellip;]","protected":false},"author":3,"featured_media":20699,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1130],"tags":[],"class_list":["post-7881","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-arduino"],"acf":[],"wps_subtitle":"","_links":{"self":[{"href":"https:\/\/techclass.wfjydl.com\/wp-json\/wp\/v2\/posts\/7881","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/techclass.wfjydl.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techclass.wfjydl.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techclass.wfjydl.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/techclass.wfjydl.com\/wp-json\/wp\/v2\/comments?post=7881"}],"version-history":[{"count":8,"href":"https:\/\/techclass.wfjydl.com\/wp-json\/wp\/v2\/posts\/7881\/revisions"}],"predecessor-version":[{"id":11471,"href":"https:\/\/techclass.wfjydl.com\/wp-json\/wp\/v2\/posts\/7881\/revisions\/11471"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/techclass.wfjydl.com\/wp-json\/wp\/v2\/media\/20699"}],"wp:attachment":[{"href":"https:\/\/techclass.wfjydl.com\/wp-json\/wp\/v2\/media?parent=7881"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techclass.wfjydl.com\/wp-json\/wp\/v2\/categories?post=7881"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techclass.wfjydl.com\/wp-json\/wp\/v2\/tags?post=7881"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}