LoginSignup
7
6

More than 5 years have passed since last update.

ESP-WROOM-02 Arduino互換ボードでサーボモーターを回す

Posted at

スイッチサイエンス製 ESP-WROOM-02 Arduino互換ボード

スイッチサイエンスからESP-WROOM-02 Arduino互換ボードが発売されました。今まではESP-WROOM-02(ESP8266)をArduinoのスケッチを書き込んで使うためには、モジュールをはんだ付けしてブレッドボード上で使用したりと少々使いづらい部分がありました。それをこの互換ボードが解消してくれます :pray:

ESP-WROOM-02 Arduino互換ボード
2620_1.jpg

ESP-WROOM-02 Arduino互換ボードでサーボモーターを回そう

ESP-WROOM-02 Arduino互換ボードでサーボモーターの回転角度を制御する仕組みを作ります(ネットには接続しません)。細かな設定は記事「ESP-WROOM-02開発ボードをArduino IDEで開発する方法」をご覧ください :eyes:

電子部品リスト

ESP-WROOM-02 Arduino互換ボードと電子工作に必要なもろもろの道具以外に必要な電子部品のリスト。

部品名 個数 価格
サーボモーター 1 1,300円

配線図

サーボモーターの信号線はIO12へ接続します。

img03.png

FritzingにESP-WROOM-02 Arduino互換ボードのパーツがないため、Arduino Unoを見た目上使用しています :bow:

スケッチ

// サーボモーター用ライブラリの読み込み
#include <Servo.h>

// モータードライバーのIN1を接続するピン
const int servoPin = 12;

// サーボモーターのインスタンス
Servo servo;

void setup() {
  // デジタル3番ピンをサーボモーター用として設定
  servo.attach(servoPin);
}

void loop() {
  // 回転角度
  int angle = 0;

  // 0度から180度まで1度ずつ回転
  for (angle = 0; angle <= 180; angle++) {
    // サーボモーターを回転
    servo.write(angle);
    // 処理を10ミリ秒停止
    delay(10);
  }

  // 180度から0度まで1度ずつ回転
  for (angle = 180; angle >= 0; angle--) {
    // サーボモーターを回転
    servo.write(angle);
    // 処理を10ミリ秒停止
    delay(10);
  }
}
7
6
0

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
7
6