LoginSignup
1
0

More than 5 years have passed since last update.

Arduino nanoでサーボモータを使ってみる

Posted at

サーボモーターとは

ホビー用途で市販されているラジコン用のサーボモーターと言った場合には電気駆動式で制御基板、モーター、ギヤボックスが一体化され防塵ケースに封入された物であることが多い。
インドアプレーン用など重量が数グラムしかない超小型製品の場合は基板やギヤが剥き出しの物もある。
制御信号はPWM信号によって行われることが一般的で、標準規格化はされていないが、事実上は大半のラジコン用サーボモーターで信号が統一されており、メーカーが異なるサーボ同士でも混在使用可能な場合が多い。
近年ではホビーロボット用のアクチュエーターとして使用されるようになり、専用の製品も多数開発されている。

出展:wikipedia

使ったもの

TOWER PRO SG90

サンプルコード

sweep_test.ino
/* Sweep
 by BARRAGAN <http://barraganstudio.com> 
 This example code is in the public domain.

 modified 8 Nov 2013
 by Scott Fitzgerald
 http://arduino.cc/en/Tutorial/Sweep
*/ 

#include <Servo.h> 

Servo myservo;  // create servo object to control a servo 
                // twelve servo objects can be created on most boards

int pos = 0;    // variable to store the servo position 

void setup() 
{ 
  myservo.attach(2);  // attaches the servo on pin 9 to the servo object 
} 

void loop() 
{ 
  for(pos = 0; pos <= 180; pos += 1) // goes from 0 degrees to 180 degrees 
  {                                  // in steps of 1 degree 
    myservo.write(pos);              // tell servo to go to position in variable 'pos' 
    delay(15);                       // waits 15ms for the servo to reach the position 
  } 
  for(pos = 180; pos>=0; pos-=1)     // goes from 180 degrees to 0 degrees 
  {                                
    myservo.write(pos);              // tell servo to go to position in variable 'pos' 
    delay(15);                       // waits 15ms for the servo to reach the position 
  } 
} 

参考:http://makers-with-myson.blog.so-net.ne.jp/2014-04-24
参考:Servo library

Bluetoothとの連携サンプル

以下はただのメモです。

bluetooth_test.ino
#include <SoftwareSerial.h>

SoftwareSerial btport(10, 11);

void setup() {
    Serial.begin(9600);
    btport.begin(38400);
    Serial.println("Enter AT commands:");
}

void loop()

{
    if (btport.available())
        Serial.write(btport.read());
    if (Serial.available()){
       btport.write(Serial.read());
    }
}

参考:Arduinoを簡単にBluetooth無線化するHC-05/HC-06

1
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0