L298Nモータードライバーを使用して4線ステッピングモーターを制御する
このチュートリアルでは、L298NモータードライバとArduinoを組み合わせて4線式ステッピングモーターを制御する方法を解説します。L298Nは多用途なデュアルHブリッジドライバで、ステッピングモーターの回転方向と速度を効果的に制御できます。ガイドの終わりまでには、ステッピングモーターを両方向に回転させ、ポテンショメータを使って速度を制御できる実用的なセットアップが完成しているでしょう。


プロセスをよりよく理解するために、配線とコーディングを視覚的に示した関連動画(動画の01:30)を見ることをお勧めします。
ハードウェア解説
L298Nモータードライバーは、モーターを前進および後退の両方向に駆動できるように設計されています。Hブリッジ構成を採用しており、モーターに印加される電圧の極性を切り替えて回転方向を反転させることができます。このドライバーは最大46Vの供給電圧とチャネルあたり連続2Aの電流に対応しており、多くの用途に適しています。
このセットアップでは、ステッピングモーターを制御するために4本の制御ピンを使用します。主要なピンはENAとENB、ドライバを有効にするにはHIGH(5V)に設定する必要があります。ピンはIN1,IN2,IN3、そしてIN4モーターの巻線状態を制御し、所望の方向へステップさせる。
データシートの詳細
| 製造元 | STマイクロエレクトロニクス |
|---|---|
| 部品番号 | L298N |
| ロジック/IO電圧 | 5ボルト |
| 電源電圧 | 5~46 V(VS) |
| 出力電流(チャンネルごと) | チャンネルあたり最大2 A(連続) |
| ピーク電流(チャンネルあたり) | 最大3A |
| PWM周波数に関するガイダンス | 1 kHz から 20 kHz |
| 入力ロジックの閾値 | 0.8 V(低)、2.0 V(高) |
| 電圧降下 / RDS(オン)/ 彩度 | 最大1.5V |
| 熱制限 | 最大150 °C |
| パッケージ | DIP-15 |
| 備考 / バリエーション | フラットタイプ(L298P)もあります。 |
- 確実にする
ENAとENB正常に動作するために5Vに接続されています。 - 高電流の用途では過熱を防ぐために十分な放熱対策を講じてください。
- Arduinoとモータードライバの間でグラウンドを共通にしてください。
- モーターやドライバーを損傷しないよう、配線の極性に注意してください。
- ノイズを除去するために、電源ピンの近くにデカップリングコンデンサを実装してください。
- 最適な性能を得るために、モーターの仕様に基づいてPWM周波数を調整してください。
配線手順

L298NモータードライバーをArduinoとステッパーモーターに配線するには、まず電源を接続します。次に、VINL298Nのピンをお使いの12V電源に接続します。次に、GNDL298Nのピンを電源のグラウンドとArduinoのグラウンドの両方に接続してください。
では、制御ピンを接続してください。ENAArduinoのピン2に接続し、ENBピン3に接続します。次に接続しますIN1ピン8に、IN2ピン9へ、IN3ピン10に、そしてIN4Arduinoのピン11に接続します。最後に、ステッパーモーターの配線をL298Nの出力端子に接続します。モーターから出ている2対の配線が出力に正しく接続されていることを確認してください。
コード例と解説
コードでは、まずインクルードしますStepper.hステッピングモーターの制御を簡素化するライブラリです。正確な動作のために重要な、1回転あたりの総ステップ数を定義します。コード中の主要な識別子には次のものが含まれますstepsPerRevolution, これにより1回転に必要なステップ数が設定され、そしてmyStepper、指定したピンでステッパーオブジェクトを初期化します。
const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11); // initialize the stepper libraryこの抜粋は、ステッピングモーターを適切なピンで初期化します。以下ではsetup()関数内で、モーターの速度を設定し、ピン2と3をHIGHにしてドライバーを有効にします。
void setup() {
myStepper.setSpeed(300); // set the speed at 60 rpm
pinMode(2,OUTPUT); // for EN1
digitalWrite(2,HIGH); // enable EN1
pinMode(3,OUTPUT); // for EN2
digitalWrite(3,HIGH); // enable EN2
}その中でloop()この関数では、モーターは時計回りと反時計回りの両方向に1回転ずつステップし、その間に遅延を入れます。これにより、モーターの動作を観察できます。
void loop() {
myStepper.step(stepsPerRevolution); // step one revolution in one direction
delay(500); // wait half a second
myStepper.step(-stepsPerRevolution); // step one revolution in the other direction
delay(500); // wait half a second
}この抜粋は、モーターを両方向に回転させる方法を示しています。参考のため、記事の下に完全なコードを掲載しています。
デモンストレーション/期待される内容
すべての配線が正しく接続され、コードがアップロードされると、ステッピングモーターが一方向に1回転し、その後反対方向に1回転するのが確認できるはずです。さらに、速度制御用のポテンショメーターを組み込んでいる場合は、それを調整することでモーターの回転速度が変わります。モーターの電流には注意してください。速度を上げると消費電流が増え、適切に管理しないと過熱する可能性があります(動画の09:45)。
モーターが期待どおりに回転しない場合は、配線を確認してすべての接続が確実に固定され、正しい向きで接続されていることを確認してください。また、電源の電圧が使用しているステッピングモーターに適しているかどうかも確認してください。
動画のタイムスタンプ
- 00:00- はじめに
- 01:30- 配線の説明
- 05:00- コードの概要
- 09:45- モーター制御のデモンストレーション
/*
Stepper Motor Control - one revolution
This program drives a unipolar or bipolar stepper motor.
The motor is attached to digital pins 8 - 11 of the Arduino.
The motor should revolve one revolution in one direction, then
one revolution in the other direction.
Created 11 Mar. 2007
Modified 30 Nov. 2009
by Tom Igoe
Modified by Ahmad S. for Robojax.com
on May 19, 2018 at 19:31, in Ajax, Ontario, Canada
*/
#include <Stepper.h>
const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution
// for your motor
// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);
void setup() {
// set the speed at 60 rpm:
myStepper.setSpeed(300);
// initialize the serial port:
Serial.begin(9600);
// L298N for Robojax.com
pinMode(2,OUTPUT);// for EN1
digitalWrite(2,HIGH);// enable EN1
pinMode(3,OUTPUT);// for EN1
digitalWrite(3,HIGH); // enable EN2
}
void loop() {
// step one revolution in one direction:
Serial.println("clockwise");
myStepper.step(stepsPerRevolution);
delay(500);
// L298N for Robojax.com
// step one revolution in the other direction:
Serial.println("counterclockwise");
myStepper.step(-stepsPerRevolution);
delay(500);
}
/*
Stepper Motor Control - one step at a time
This program drives a unipolar or bipolar stepper motor.
The motor is attached to digital pins 8 - 11 of the Arduino.
The motor will step one step at a time, very slowly. You can use this to
test that you've got the four wires of your stepper wired to the correct
pins. If wired correctly, all steps should be in the same direction.
Use this also to count the number of steps per revolution of your motor,
if you don't know it. Then plug that number into the oneRevolution
example to see if you got it right.
Created 30 Nov. 2009
by Tom Igoe
Modified by Ahmad S. for Robojax.com
on May 19, 2018 at 19:31, in Ajax, Ontario, Canada
*/
#include <Stepper.h>
const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution
// for your motor
// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);
int stepCount = 0; // number of steps the motor has taken
void setup() {
// initialize the serial port:
Serial.begin(9600);
// L298N for Robojax.com
pinMode(2,OUTPUT);// for EN1
digitalWrite(2,HIGH);// enable EN1
pinMode(3,OUTPUT);// for EN1
digitalWrite(3,HIGH); // enable EN2
}
void loop() {
// step one step:
// L298N for Robojax.com
myStepper.step(-1);
Serial.print("steps:");
Serial.println(stepCount);
stepCount++;
delay(200);
}
必要かもしれないもの
-
アマゾンAmazonからL298Nモータードライバーを購入するamzn.to
-
アマゾンAmazonでNema 17ステッパーモーターを購入するamzn.to
リソースと参考文献
まだリソースはありません。
ファイル📁
ファイルは利用できません。