Arduinoのコードとビデオ:L293D DCモーターコントローラ(速度制御なし)
このチュートリアルでは、L293DモータードライバをArduinoと組み合わせてDCモーターを制御する方法を説明します。L293Dを使うと、モーターを時計回りおよび反時計回りの両方向に回転させることができます。このガイドに従えば、部品の配線方法とArduinoのプログラミングを学び、目的のモーター制御を実現できるようになります。
このプロジェクトでは、L293Dモータードライバを使って単一のDCモーターを制御します。モーターはArduinoのコードで与えられるコマンドに応じて回転方向を切り替えることができます。セットアップとコードをより明確に理解するために、関連する動画(動画の00:00)を見ることをおすすめします。
ハードウェアの解説
L293Dはモータ駆動用に設計された集積回路です。2つの直流モータを同時に制御することも、1つのステッピングモータを制御することもできます。このチップはHブリッジ構成を用いており、モータに印加される電圧の極性を切り替えることで回転方向を制御できます。この柔軟性により、ロボット工学や自動化プロジェクトに最適な選択肢となります。
L293D に加えて、モータードライバに制御信号を送るために Arduino ボードを使用します。Arduino はモーターを有効にし、その回転方向を決定するために必要な論理レベルを生成します。セットアップには、DC モーターとモーターの電圧要件に適合した電源も必要です。
データシートの詳細
| 製造業者 | テキサス・インスツルメンツ |
|---|---|
| 部品番号 | L293D |
| ロジック/入出力電圧 | 5ボルト |
| 供給電圧 | 4.5〜36V |
| 出力電流(チャンネルあたり) | 600 mA |
| ピーク電流(チャンネルあたり) | 1.2 A |
| PWM周波数に関するガイダンス | 20 kHz |
| 入力ロジック閾値 | 2.5 V(典型値) |
| 電圧降下 / RDS(オン) / 彩度 | 1.5 V(最大) |
| 温度制限 | 150 °C(最大) |
| パッケージ | 16ピンDIP |
| メモ / バリエーション | 2台のモーターを制御できます |
- 供給電圧が36 Vを超えないことを確認してください。
- 最大電流付近で動作させる場合は、適切な放熱対策を行ってください。
- Arduinoとモータードライバーのグラウンドを必ず接続してください。
- 逆極性の接続を避けるために配線を確認してください。
- 将来のプロジェクトで必要なら、速度制御にPWM信号を使用してください。
配線手順


L293DモータコントローラをArduinoに配線するには、まず電源とグランドを接続します。L293Dのピン4とピン5をグランドに接続します。次に、ピン1(Vcc1)をArduinoの5 V出力に接続します。Vcc2(ピン8)は外部電源に接続し、モーターの電圧仕様に合っていることを確認してください。
次に、イネーブルピン(ピン1)をArduinoのピン8に接続してモーターの電源を制御します。モーター制御入力については、L293Dのピン2(1A)をArduinoのピン2に、ピン7(2A)をArduinoのピン7に接続します。最後に、モーター端子をL293Dのピン3(1Y)とピン6(2Y)に接続します。
コード例と解説
次のコードはピンを初期化し、モーター制御を設定します。使用されている識別子には次のものが含まれますP1A最初のモーター制御ピン用およびEN12イネーブルピン用です。setup関数はピンを出力として設定します。
void setup() {
Serial.begin(9600); // setup Serial Monitor to display information
pinMode(P1A, OUTPUT); // define pin as OUTPUT for P1A
pinMode(P2A, OUTPUT); // define pin as OUTPUT for P2A
pinMode(EN12, OUTPUT); // define pin as OUTPUT for 1,2EN enable
}ループ内では、モーターが両方向に回転するように指示され、その間に遅延が設けられます。モーターの状態はシリアルモニタに表示するために使用してSerial.println。
void loop() {
Serial.println("Rotating CW");
digitalWrite(EN12, HIGH); // Enable 1A and 2A
digitalWrite(P1A, HIGH); // send HIGH signal to P1A
digitalWrite(P2A, LOW); // send LOW signal to P2A
delay(3000); // motor runs for 3 seconds
digitalWrite(EN12, LOW); // Disable 1A and 2A
}この抜粋は、送る論理レベルを変更することでモーターの回転方向を制御する方法を示していますP1AそしてP2Aモーターは停止して回転方向を切り替える前に3秒間作動します。
L293Dハーフブリッジドライバの使い方は以下の通りです:
デモ/ご期待いただけること
セットアップが完了してコードをアップロードすると、モーターが一方向に3秒間回転し、2秒間停止してから反対方向にさらに3秒間回転するのが観察できるはずです。モーターの状態はシリアルモニターに表示され、動作が確認できます(ビデオの12:00)。
よくある落とし穴としては、モーターに正しい電圧が供給されていることや、モーターの接続が正しいことを確認することが含まれます。モーターが反応しない場合は、配線と電源の接続を再度確認してください。
動画のタイムスタンプ
- 00:00- はじめに
- 02:30- 配線の説明
- 05:00- コードのウォークスルー
- 10:00モーター制御の実演
++
/*
* This is the Arduino code L293 DC motor driver (Advanced).
Using this code you can control a motor to rotate in both directions: clockwise (CW)
and counter-clockwise (CCW).
* *
// Written by Ahmad S. for Robojax.com on
// February 25, 2018 at 18:30 in Ajax, Ontario, Canada
* Permission granted to share this code given that this
* note is kept with the code.
* Disclaimer: this code is "AS IS" and for educational purposes only.
*
* watch L293 video for details https://youtu.be/jAmDliHcTJ0
* Code is available at http://robojax.com/learn/arduino
*
*/
// DC motor 1 control
#define P1A 2 // define pin 2 as for P1A
#define P2A 7 // define pin 7 as for P2A
#define EN12 8 // define pin 8 as for 1,2EN enable
// DC motor 2 control
#define P3A 10 // define pin 10 as for P3A
#define P4A 13 // define pin 13 as for P4A
#define EN34 9 // define pin 9 as for EN3 and EN4 enable
/*
* Permission granted to share this code given that this
* note is kept with the code.
* Disclaimer: this code is "AS IS" and for educational purposes only.
*
*/
void setup() {
// L293 Motor Control Code by Robojax.com 2018025
Serial.begin(9600);// setup Serial Monitor to display information
pinMode(P1A, OUTPUT);// define pin as OUTPUT for P1A
pinMode(P2A, OUTPUT);// define pin as OUTPUT for P2A
pinMode(EN12, OUTPUT);// define pin as OUTPUT for 1,2EN
pinMode(P3A, OUTPUT);// define pin as OUTPUT for P3A
pinMode(P4A, OUTPUT);// define pin as OUTPUT for P4A
pinMode(EN34, OUTPUT);// define pin as OUTPUT for 3,4EN
// L293 Motor Control Code by Robojax.com 2018025
}
void loop() {
// L293 Motor Control Code by Robojax.com 2018025
Serial.println("Rotating CW");
digitalWrite(EN12 ,HIGH);// Enable 1A and 2A
digitalWrite(P1A,HIGH);// send + or HIGH signal to P1A
digitalWrite(P2A,LOW);// send - or LOW signal to P2A
delay(3000);// motor runs for 3 seconds
digitalWrite(EN12 ,LOW);// Disable 1A and 2A
delay(2000);// motor stop for 3 seconds
Serial.println("Motor Stopped");
// L293 Motor Control Code by Robojax.com 2018025
// now changing the direction of rotation of motor
Serial.println("Rotating CCW");
digitalWrite(EN12 ,HIGH);// Enable 1A and 2A
digitalWrite(P1A,LOW);// send + or HIGH signal to P1A
digitalWrite(P2A,HIGH);// send - or LOW signal to P2A
delay(3000);// motor runs for 3 seconds
digitalWrite(EN12 ,LOW);// Disable 1A and 2A
delay(2000);// motor stop for 3 seconds
Serial.println("Motor Stopped");
Serial.println("=========== Loop done");
delay(500);
// L293 Motor Control Code by Robojax.com 2018025
}
/*
* This is the Arduino code L293 DC motor driver (Advanced).
Using this code you can control a motor to rotate in both directions: clockwise (CW)
and counter-clockwise (CCW).
* *
// Written by Ahmad S. for Robojax.com on
// February 25, 2018 at 18:30 in Ajax, Ontario, Canada
* Permission granted to share this code given that this
* note is kept with the code.
* Disclaimer: this code is "AS IS" and for educational purposes only.
*
* Watch L293 video for details: https://youtu.be/jAmDliHcTJ0
* Code is available at: http://robojax.com/learn/arduino
*
*/
// DC motor 1 control
#define P1A 2 // define pin 2 as for P1A
#define P2A 7 // define pin 7 as for P2A
#define EN12 8 // define pin 8 as for 1,2EN enable
// DC motor 2 control
#define P3A 10 // define pin 10 as for P3A
#define P4A 13 // define pin 13 as for P4A
#define EN34 9 // define pin 9 as for EN3 and EN4 enable
/*
* Permission granted to share this code given that this
* note is kept with the code.
* Disclaimer: this code is "AS IS" and for educational purposes only.
*
*/
void setup() {
// L293 Motor Contro Code by Robojax.com 2018025
Serial.begin(9600);// setup Serial Monitor to display information
pinMode(P1A, OUTPUT);// define pin as OUTPUT for P1A
pinMode(P2A, OUTPUT);// define pin as OUTPUT for P2A
pinMode(EN12, OUTPUT);// define pin as OUTPUT for 1,2EN
pinMode(P3A, OUTPUT);// define pin as OUTPUT for P3A
pinMode(P4A, OUTPUT);// define pin as OUTPUT for P4A
pinMode(EN34, OUTPUT);// define pin as OUTPUT for 3,4EN
// L293 Motor Contro Code by Robojax.com 2018025
}
void loop() {
if(value == 45){
rotateMA("CW",HIGH); // start motor in CW
}
delay(3000);
rotateMA("CW",LOW); // stop motor
delay(2000);
rotateMA("CCW",HIGH); // start motor in CCW
delay(3000);
rotateMA("CW",LOW); /// stop motor
delay(2000);
// L293 Motor Contro Code by Robojax.com 2018025
}// loop ends
/**
* function: rotateMA(String di,int action)
* Sends power to motor A
* di is a string and can be "CW" or "CCW"
* to use:
* rotateMA("CW",HIGH);// to rotate motor CW
* rotateMA("CCW",HIGH);// to rotate motor CCW
* to stop the motor:
* rotateMA("CW",LOW);// to stop motor
*/
void rotateMA(String di,int endis)
{
// L293 Motor Contro Code by Robojax.com 2018025
if(di =="CW"){
Serial.println(" Rotating CW");
digitalWrite(EN12 ,endis);// Enable 1A and 2A
digitalWrite(P1A,HIGH);// send + or HIGH signal to P1A
digitalWrite(P2A,LOW);// send - or LOW signal to P2A
}else{
// L293 Motor Contro Code by Robojax.com 2018025
// now changing the direction of rotation of motor
Serial.println(" Rotating CCW");
digitalWrite(EN12 ,endis);// Enable 1A and 2A
digitalWrite(P1A,LOW);// send + or HIGH signal to P1A
digitalWrite(P2A,HIGH);// send - or LOW signal to P2A
}
// L293 Motor Contro Code by Robojax.com 2018025
}//rotateMA ends here
必要かもしれないもの
-
アマゾンL293DモータードライバICを購入するamzn.to
-
アリエクスプレスAliExpressからL293DモータードライバーICを購入するs.click.aliexpress.com
リソースと参考文献
まだリソースはありません。
ファイル📁
ファイルは利用できません。