{"id":968,"date":"2020-03-15T12:56:28","date_gmt":"2020-03-15T03:56:28","guid":{"rendered":"https:\/\/dalomo.net\/blog\/?p=968"},"modified":"2020-03-15T12:56:28","modified_gmt":"2020-03-15T03:56:28","slug":"arduino%e3%81%a7%e3%82%b5%e3%83%bc%e3%83%9c%e3%83%a2%e3%83%bc%e3%82%bf%e3%83%bc%e4%bd%bf%e3%81%a3%e3%81%a6%e3%81%bf%e3%81%9f%e3%81%84","status":"publish","type":"post","link":"https:\/\/dalomo.net\/blog\/2020\/03\/15\/968\/","title":{"rendered":"Arduino\u3067\u30b5\u30fc\u30dc\u30e2\u30fc\u30bf\u30fc\u4f7f\u3063\u3066\u307f\u305f\u3044"},"content":{"rendered":"<h1>\u30b5\u30fc\u30dc\u30e2\u30fc\u30bf\u30fcSG90<\/h1>\n<p>\u56de\u8ee2\u3092\u89d2\u5ea6\u306b\u3067\u304d\u308b\u3084\u3064\u3002\u4f7f\u3063\u3066\u307f\u305f\u3044\u306e\u3067\u4f7f\u3044\u65b9\u8abf\u3079\u308b\u3002<\/p>\n<h2>\u304a\u8cb7\u3044\u7269<\/h2>\n<p><a href=\"http:\/\/akizukidenshi.com\/catalog\/g\/gM-08761\/\">http:\/\/akizukidenshi.com\/catalog\/g\/gM-08761\/<\/a><\/p>\n<p>\u79cb\u6708\u3067\u58f2\u3063\u3066\u308b\u3002\u30b9\u30bf\u30f3\u30c0\u30fc\u30c9\u306a\u3084\u3064\u307f\u305f\u3044\u3002<\/p>\n<p><a href=\"https:\/\/dalomo.net\/blog\/wp-content\/uploads\/2020\/03\/servo01.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-969\" src=\"https:\/\/dalomo.net\/blog\/wp-content\/uploads\/2020\/03\/servo01-225x300.png\" alt=\"\" width=\"225\" height=\"300\" srcset=\"https:\/\/dalomo.net\/blog\/wp-content\/uploads\/2020\/03\/servo01-225x300.png 225w, https:\/\/dalomo.net\/blog\/wp-content\/uploads\/2020\/03\/servo01.png 750w\" sizes=\"auto, (max-width: 225px) 100vw, 225px\" \/><\/a><\/p>\n<p>\u3061\u3063\u3061\u3083\u3044!<\/p>\n<p><a href=\"https:\/\/dalomo.net\/blog\/wp-content\/uploads\/2020\/03\/servo02.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-970\" src=\"https:\/\/dalomo.net\/blog\/wp-content\/uploads\/2020\/03\/servo02-300x225.png\" alt=\"\" width=\"300\" height=\"225\" srcset=\"https:\/\/dalomo.net\/blog\/wp-content\/uploads\/2020\/03\/servo02-300x225.png 300w, https:\/\/dalomo.net\/blog\/wp-content\/uploads\/2020\/03\/servo02-768x576.png 768w, https:\/\/dalomo.net\/blog\/wp-content\/uploads\/2020\/03\/servo02.png 1000w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>\u30d7\u30ec\u30fc\u30c8?\u30ac\u30a4\u30c9?\u306a\u3093\u3066\u3044\u3046\u306e\u304b\u5206\u304b\u3093\u306a\u3044\u3051\u3069\u4ed8\u3044\u3066\u305f\u3002<\/p>\n<h2>\u63a5\u7d9a<\/h2>\n<p><a href=\"https:\/\/dalomo.net\/blog\/wp-content\/uploads\/2020\/03\/servo03.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-971\" src=\"https:\/\/dalomo.net\/blog\/wp-content\/uploads\/2020\/03\/servo03-225x300.png\" alt=\"\" width=\"225\" height=\"300\" srcset=\"https:\/\/dalomo.net\/blog\/wp-content\/uploads\/2020\/03\/servo03-225x300.png 225w, https:\/\/dalomo.net\/blog\/wp-content\/uploads\/2020\/03\/servo03.png 750w\" sizes=\"auto, (max-width: 225px) 100vw, 225px\" \/><\/a><\/p>\n<p>\u76f4\u3067\u7e4b\u3044\u3060\u3002\u5927\u4e08\u592b\u304b\u306a\u3002<\/p>\n<blockquote><p>\u8336=GND\u3001\u8d64=\u96fb\u6e90[+]\u3001\u6a59=\u5236\u5fa1\u4fe1\u53f7 [JR\u30bf\u30a4\u30d7]<\/p><\/blockquote>\n<h2>\u30b9\u30b1\u30c3\u30c1<\/h2>\n<h3>0-90-180\u5ea6\u306e\u7e70\u308a\u8fd4\u3057<\/h3>\n<pre><code class=\"cpp\">#include &lt;Servo.h&gt;\r\n\r\nint pwmpin = 9;\r\nServo myservo;\r\n\r\nvoid setup() {\r\n  myservo.attach(pwmpin);\r\n}\r\n\r\nvoid loop() {\r\n\r\n  myservo.write(0);\r\n  delay(1000);\r\n  myservo.write(90);\r\n  delay(1000);\r\n  myservo.write(180);\r\n  delay(1000);\r\n\r\n}<\/code><\/pre>\n<p>Servo.h\u3092include\u3059\u308b\u3060\u3051\u3067\u4f7f\u3048\u308b\u3002<\/p>\n<p><iframe loading=\"lazy\" src=\"https:\/\/www.youtube.com\/embed\/qpoAeqjJBqY\" width=\"560\" height=\"315\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/p>\n<h3>0.1\u79d2\u6bce\u306b0-180\u5ea6\u306b\u52d5\u304b\u3059<\/h3>\n<pre><code class=\"cpp\">#include &lt;Servo.h&gt;\r\n\r\nint pwmpin = 9;\r\nServo myservo;\r\n\r\nvoid setup() {\r\n  myservo.attach(pwmpin);\r\n}\r\n\r\nvoid loop() {\r\n\r\n  for (int i = 0 ; i &lt; 180 ; i++) {\r\n    myservo.write(i);\r\n    delay(100);\r\n  }\r\n\r\n}<\/code><\/pre>\n<p>\u3053\u3093\u306a\u3068\u304b\u3002<\/p>\n<p><iframe loading=\"lazy\" src=\"https:\/\/www.youtube.com\/embed\/qpoAeqjJBqY?start=10\" width=\"560\" height=\"315\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/p>\n<h3>0.5\u79d2\u3054\u3068\u306b\u30e9\u30f3\u30c0\u30e0<\/h3>\n<pre><code class=\"cpp\">#include &lt;Servo.h&gt;\r\n\r\nint pwmpin = 9;\r\nint deg = 0;\r\nServo myservo;\r\n\r\nvoid setup() {\r\n  myservo.attach(pwmpin);\r\n  randomSeed(analogRead(0));\r\n}\r\n\r\nvoid loop() {\r\n\r\n  deg = random(0, 180);\r\n  myservo.write(deg);\r\n  delay(500);\r\n}<\/code><\/pre>\n<p>\u3053\u3093\u306a\u3093\u3082\u3002<\/p>\n<p><iframe loading=\"lazy\" src=\"https:\/\/www.youtube.com\/embed\/qpoAeqjJBqY?start=30\" width=\"560\" height=\"315\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/p>\n<p>&nbsp;<\/p>\n<p>\u6c17\u306b\u306a\u308b\u3053\u3068\u304c\u3042\u3063\u3066\u3001\u30d4\u30cb\u30aa\u30f3\u30ae\u30a2\u3068\u30d7\u30ec\u30fc\u30c8\u306e\u6b6f\u3092\u5408\u308f\u305b\u308b\u3068\u30010\u5ea6\u306a\u3044\u3057180\u5ea6\u306e\u6642\u306b\u7b50\u4f53\u3068\u76f4\u4ea4\u3057\u306a\u3044\u304b\u3089\u898b\u305f\u76ee\u7684\u306b\u82e5\u5e72\u89d2\u5ea6\u304c\u3064\u3044\u3066\u3044\u308b\u3088\u3046\u306b\u898b\u3048\u308b\u3002\u306a\u3093\u304b\u30e4\u30c0\u306a\u3002\u307e\u3041\u5b89\u3044\u3057\u3061\u3063\u3061\u3083\u3044\u304b\u3089\u305d\u3053\u306f\u6211\u6162\u304b\u3002<\/p>\n<h2>\u306a\u305canalogWrite()\u3060\u3068\u3061\u3083\u3093\u3068\u52d5\u304b\u306a\u3044\u306e\u304b<\/h2>\n<p>\u6700\u521d\u3001analogWrite\u306e\u8aac\u660e\u306bPWM\u3063\u3066\u66f8\u3044\u3066\u3042\u3063\u305f\u306e\u3067<\/p>\n<pre><code class=\"cpp\">int pwmpin = 9;\r\nint deg = 0;\r\nServo myservo;\r\n\r\nvoid setup() {\r\n\r\n  pinMode(pwmpin, OUTPUT);\r\n}\r\n\r\nvoid loop() {\r\n\r\n  analogWrite(pwmpin, 0);\r\n  delay(1000);\r\n  analogWrite(pwmpin, 127);\r\n  delay(1000);\r\n  analogWrite(pwmpin, 255);\r\n  delay(1000);\r\n}<\/code><\/pre>\n<p>\u3066\u3044\u3046\u30b3\u30fc\u30c9\u3092\u66f8\u3044\u305f\u3002analogWrite\u306f0-255\u306e\u7bc4\u56f2\u3067\u5024\u3092\u66f8\u304d\u8fbc\u3081\u308b\u3063\u3066\u3044\u3046\u304b\u3089\u30010-127-255\u30670-90-180\u5ea6\u306b\u306a\u308b\u3068\u8003\u3048\u305f\u308f\u3051\u3060\u3002\u3067\u3082\u3053\u306e\u8003\u3048\u306f\u9593\u9055\u3063\u3066\u305f\u3002\u30b5\u30fc\u30dc\u5168\u7136\u52d5\u304b\u3093\u3057\u3002<\/p>\n<h3>\u30b5\u30fc\u30dc\u30e2\u30fc\u30bf\u30fc\u306f\u96fb\u5727\u306e\u5909\u5316\u3067\u89d2\u5ea6\u3092\u5909\u3048\u3066\u3044\u308b\u308f\u3051\u3067\u306f\u306a\u3044<\/h3>\n<p>\u79cb\u6708\u306b\u3042\u308bSG90\u306e\u8cc7\u6599\u3092\u898b\u3066\u307f\u308b\u3068<\/p>\n<p><a href=\"https:\/\/dalomo.net\/blog\/wp-content\/uploads\/2020\/03\/servo04.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-973\" src=\"https:\/\/dalomo.net\/blog\/wp-content\/uploads\/2020\/03\/servo04-300x185.png\" alt=\"\" width=\"300\" height=\"185\" srcset=\"https:\/\/dalomo.net\/blog\/wp-content\/uploads\/2020\/03\/servo04-300x185.png 300w, https:\/\/dalomo.net\/blog\/wp-content\/uploads\/2020\/03\/servo04-768x475.png 768w, https:\/\/dalomo.net\/blog\/wp-content\/uploads\/2020\/03\/servo04.png 937w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>\u96fb\u5727\u306f4.8V(5V)\u3067\u300120ms\u306e\u5468\u671f\u3067\u306e\u30010.5-2.4ms\u306e\u30c7\u30e5\u30fc\u30c6\u30a3\u30b5\u30a4\u30af\u30eb\u306b\u3088\u3063\u3066\u89d2\u5ea6\u304c\u6c7a\u307e\u308b\u3002PWM\u3092\u96fb\u5727\u3092\u4f4e\u304f\u898b\u305b\u308b\u305f\u3081\u3067\u306f\u306a\u304f\u3066(\u7d50\u679c\u7684\u306b\u4f4e\u304f\u306a\u3063\u3066\u3044\u308b\u3088\u3046\u306b\u898b\u3048\u308b\u3051\u3069)\u3001\u30d1\u30eb\u30b9\u5e45\u3092\u4f7f\u3063\u3066\u308b\u3060\u3051\u3063\u3066\u3053\u3068\u307f\u305f\u3044\u3002PWM=\u96fb\u5727\u3092\u5909\u5316\u3055\u305b\u308b\u3053\u3068\u3001\u307f\u305f\u3044\u306a\u96d1\u306a\u7406\u89e3\u3060\u3063\u305f\u304b\u3089\u99c4\u76ee\u306a\u3093\u3060\u306a\u3002<\/p>\n<h3>analogWrite\u306e\u5468\u671f\u3068SG90\u306e\u5468\u671f\u306f\u9055\u3046<\/h3>\n<p>analogWrite\u306e\u5468\u6ce2\u6570\u306f\u3001<a href=\"http:\/\/www.musashinodenpa.com\/arduino\/ref\/index.php?f=0&amp;pos=2153\">\u3053\u3061\u3089<\/a>\u3092\u898b\u308b\u3068\u7d04490Hz(\u22522.04ms\u306b1\u56de)\u3067\u3001SG90\u306f\u4e0a\u8a18\u304b\u308950Hz(=20ms\u306b1\u56de)\u306a\u306e\u3067\u3001\u90fd\u540810\u500d\u3050\u3089\u3044\u9055\u3046\u3002analogWrite\u306e\u65b9\u304c\u77ed\u3044\u3002\u3066\u3044\u3046\u304banalogWrite\u3067\u3053\u306e\u5236\u5fa1\u4fe1\u53f7\u3092\u4f5c\u308d\u3046\u3068\u3057\u3066\u306f\u3044\u3051\u306a\u3044\u3002\u306a\u306e\u3067digitalWrite\u3068delayMicroseconds\u3092\u7d44\u307f\u5408\u308f\u305b\u3066\u5236\u5fa1\u4fe1\u53f7\u3092\u4f5c\u3089\u306a\u3044\u3068\u3044\u3051\u306a\u3044\u307f\u305f\u3044\u3002<\/p>\n<h3>\u8e0f\u307e\u3048\u305f\u30b9\u30b1\u30c3\u30c1<\/h3>\n<pre><code class=\"cpp\">int pwmpin = 9;\r\n\r\nvoid setup() {\r\n\r\n  pinMode(pwmpin, OUTPUT);\r\n\r\n}\r\n\r\nvoid loop() {\r\n\r\n  pulse(0, 1000);\r\n  pulse(90, 1000);\r\n  pulse(180, 1000);\r\n\r\n}\r\n\r\nvoid pulse(int deg, int ms) {\r\n  int d = 0;\r\n  int startms = millis();\r\n  int endms = startms + ms;\r\n\r\n  d = map(deg, 0, 180, 500, 2400);\r\n\r\n  do {\r\n    digitalWrite(pwmpin, HIGH);\r\n    delayMicroseconds(d);\r\n    digitalWrite(pwmpin, LOW);\r\n    delayMicroseconds(20000 - d);\r\n  } while (endms &lt; millis());\r\n\r\n  delay(ms);\r\n\r\n}<\/code><\/pre>\n<p>\u4e00\u5fdc\u52d5\u304f\u3002<\/p>\n<p><iframe loading=\"lazy\" src=\"https:\/\/www.youtube.com\/embed\/fFtVVevFn_I\" width=\"560\" height=\"315\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/p>\n<p>\u305f\u30601\u5206\u3050\u3089\u3044\u3059\u308b\u3068\u52dd\u624b\u306b\u6b62\u307e\u3063\u3061\u3083\u3046\u3002\u305f\u3076\u3093\u3053\u308c\u306fint\u306e\u305b\u3044\u306a\u306e\u304b\u306a?<\/p>\n<h2>\u53c2\u8003<\/h2>\n<p><a href=\"https:\/\/www.arduino.cc\/en\/Reference\/Servo\">https:\/\/www.arduino.cc\/en\/Reference\/Servo<\/a><\/p>\n<p><a href=\"http:\/\/www.musashinodenpa.com\/arduino\/ref\/index.php?f=0&amp;pos=2153\">http:\/\/www.musashinodenpa.com\/arduino\/ref\/index.php?f=0&amp;pos=2153<\/a><\/p>\n<p><a href=\"http:\/\/marupeke296.com\/EL_Ard_No9_ServoMotor.html\">http:\/\/marupeke296.com\/EL_Ard_No9_ServoMotor.html<\/a><\/p>\n<p><a href=\"http:\/\/e-words.jp\/w\/Hz.html\">http:\/\/e-words.jp\/w\/Hz.html<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u30b5\u30fc\u30dc\u30e2\u30fc\u30bf\u30fcSG90 \u56de\u8ee2\u3092\u89d2\u5ea6\u306b\u3067\u304d\u308b\u3084\u3064\u3002\u4f7f\u3063\u3066\u307f\u305f\u3044\u306e\u3067\u4f7f\u3044\u65b9\u8abf\u3079\u308b\u3002 \u304a\u8cb7\u3044\u7269 http:\/\/akizukidenshi.com\/catalog\/g\/gM-08761\/ \u79cb\u6708\u3067\u58f2\u3063\u3066\u308b\u3002\u30b9\u30bf\u30f3\u30c0\u30fc\u30c9\u306a\u3084\u3064\u307f\u305f\u3044 &hellip; <a href=\"https:\/\/dalomo.net\/blog\/2020\/03\/15\/968\/\">\u7d9a\u304d\u3092\u8aad\u3080 <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":969,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[8],"tags":[69,97,54],"class_list":["post-968","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-8","tag-arduino","tag-97","tag-54"],"_links":{"self":[{"href":"https:\/\/dalomo.net\/blog\/wp-json\/wp\/v2\/posts\/968","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dalomo.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dalomo.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dalomo.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dalomo.net\/blog\/wp-json\/wp\/v2\/comments?post=968"}],"version-history":[{"count":2,"href":"https:\/\/dalomo.net\/blog\/wp-json\/wp\/v2\/posts\/968\/revisions"}],"predecessor-version":[{"id":974,"href":"https:\/\/dalomo.net\/blog\/wp-json\/wp\/v2\/posts\/968\/revisions\/974"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/dalomo.net\/blog\/wp-json\/wp\/v2\/media\/969"}],"wp:attachment":[{"href":"https:\/\/dalomo.net\/blog\/wp-json\/wp\/v2\/media?parent=968"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dalomo.net\/blog\/wp-json\/wp\/v2\/categories?post=968"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dalomo.net\/blog\/wp-json\/wp\/v2\/tags?post=968"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}