以下為Arduino Uno板的L298實驗

需要材料:

Wire: n個
Button: 兩個
10kΩ Resistor: 兩個
12Vbattery: 1個
9V_BatteryAdapter: 1個(提供電力給Arduino Uno)
DC Motor: 兩個
L298N: 一個
Arduino Uno: 一個
Breadboard: 一個

電路圖(Circuit diagram)

程式碼(Code)

const int buttonGo = 2; //前進
const int buttonBack = 3; //後退
int Go = 0; //定義Go,為了要讀取buttonGo
int Back = 0; //定義Back,為了要讀取buttonBack

int AmotorA = 4; //控制正反轉
int AmotorB = 5; //控制正反轉

int BmotorA = 6; //控制正反轉
int BmotorB = 7; //控制正反轉

void setup() {
  pinMode(buttonGo, INPUT);
  pinMode(buttonBack, INPUT);
}

void loop() {
  Go = digitalRead(buttonGo);
  Back = digitalRead(buttonBack);

  if (Go == HIGH) {
    digitalWrite(AmotorA, HIGH);
    digitalWrite(AmotorB, LOW);
    digitalWrite(BmotorA, HIGH);
    digitalWrite(BmotorB, LOW);
  }
  else {
    digitalWrite(AmotorA, LOW);
    digitalWrite(AmotorB, LOW);
    digitalWrite(BmotorA, LOW);
    digitalWrite(BmotorB, LOW);
  }

  if (Back == HIGH) {
    digitalWrite(AmotorA, LOW);
    digitalWrite(AmotorB, HIGH);
    digitalWrite(BmotorA, LOW);
    digitalWrite(BmotorB, HIGH);
  }
  else {
    digitalWrite(AmotorA, LOW);
    digitalWrite(AmotorB, LOW);
    digitalWrite(BmotorA, LOW);
    digitalWrite(BmotorB, LOW); 
  }
}

顯示結果:

說明: 當按住其中一個按鈕(2=H or 3=H)

參考網站:

http://goods.ruten.com.tw/item/show?21401288480536
http://designer.mech.yzu.edu.tw/articlesystem/article/compressedfile/(2013-02-18)%20%E4%BD%BF%E7%94%A8%E9%A6%AC%E9%81%94%E9%A9%85%E5%8B%95IC%E6%90%AD%E9%85%8DArduino%20Uno%E6%8E%A7%E5%88%B6%E9%A6%AC%E9%81%94%E8%BC%B8%E5%87%BA.aspx?ArchID=2006