海外のモータードライバと言えば L293D が乗っていることが多いのですが、ぼちぼちと SN754410NE に切り替えるのか?と話題があって。こっちのほうは秋月電子で150円で買えます。
それとは別に、TB6612FNG を買ってみたのでお試しとして。手元にあるのはスイッチサイエンスのものではなくて互換品で 3$ 程度で買っています。
ブレッドボードで配線
それぞれのモーターに対して IN/OUTが2本ずつとPWM線があるので、結構本数が多いのが難点ですね。まあ、Arduino Tank を動かだけの2個のモーターならばいいけど、多脚ロボットにしてそれぞれの足にモーターが付いている、ということになると、ちょっと考えないといけないかも。I2C 経由にすればよいのですが。いずれ ロジコマ作ってみる【ぼーだー1】 ‐ ニコニコ動画:GINZA を参考にして作ってみたいところ。
回路図
無線化もあわせると、こんな感じ。
ブレッドボードに配線すると、こんな感じで動きます。
実験用のコード
まだ Bluetooth のコードは入れていないので後で。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | #include <Wire.h> const int motorA1 = 8; // IN1 const int motorA2 = 9; // IN2 const int motorAp = 10; // const int motorB1 = 7; // IN1 const int motorB2 = 6; // IN2 const int motorBp = 5; // const int STBY = 11; void setup() { // put your setup code here, to run once: pinMode( motorA1, OUTPUT ); pinMode( motorA2, OUTPUT ); pinMode( motorAp, OUTPUT ); pinMode( motorB1, OUTPUT ); pinMode( motorB2, OUTPUT ); pinMode( motorBp, OUTPUT ); pinMode( STBY, OUTPUT ); digitalWrite( motorA1, LOW ); digitalWrite( motorA2, LOW ); digitalWrite( motorAp, LOW ); digitalWrite( motorB1, LOW ); digitalWrite( motorB2, LOW ); digitalWrite( motorBp, LOW ); digitalWrite( STBY, HIGH ); Serial.begin(9600); Serial.println( "Motor Standby" ); delay( 1000 ); } void loop() { // put your main code here, to run repeatedly: Serial.println( "motorA forward" ); digitalWrite( motorAp, HIGH ); digitalWrite( motorA1, HIGH ); digitalWrite( motorA2, LOW ); delay( 3000 ); Serial.println( "motorA stop" ); digitalWrite( motorAp, LOW ); delay( 1000 ); Serial.println( "motorA back" ); digitalWrite( motorAp, HIGH ); digitalWrite( motorA1, LOW ); digitalWrite( motorA2, HIGH ); delay( 3000 ); Serial.println( "motorA stop" ); digitalWrite( motorAp, LOW ); delay( 1000 ); Serial.println( "motorB forward" ); digitalWrite( motorBp, HIGH ); digitalWrite( motorB1, HIGH ); digitalWrite( motorB2, LOW ); delay( 3000 ); Serial.println( "motorB stop" ); digitalWrite( motorBp, LOW ); delay( 1000 ); Serial.println( "motorB back" ); digitalWrite( motorBp, HIGH ); digitalWrite( motorB1, LOW ); digitalWrite( motorB2, HIGH ); delay( 3000 ); Serial.println( "motorB stop" ); digitalWrite( motorBp, LOW ); delay( 1000 ); } |