Skip to content
Sean Ye edited this page May 28, 2017 · 6 revisions

Next, place the chip on the middle of the breadboard and connect it to the nano according to the following figure. Ensure that mode is pulled to 5 volts for the program below to work.

Here is a picture of the completed breadboard.

The code for one motor on the h-bridge is located below.

int en1 = 17;
int dir1 = 10;

void setup() {
  pinMode(en1, OUTPUT);
  pinMode(dir1, OUTPUT);
}

void loop() {
  move_motor1(125);
}

void move_motor1(int spd) {
  if (spd >= 0) {
    analogWrite(en1, spd);
    digitalWrite(dir1, HIGH);
  } else if (spd < 0) {
    analogWrite(en1, -spd);
    digitalWrite(dir1, LOW);
  }
}

Clone this wiki locally