An h-bridge motor controller is used for two very useful purposes: one is to control two motors at the same time, the other, is to be able to reverse the direction of the motors at will. This sort of component would come in handy if you were working on anything that you wanted to go back and forth or any two separate directions. A car, a printer, any kind of device that uses a dc motor can be manipulated with an h-bridge. below are two pictures, the first is an actual picture of the h-bridge, the second is a diagram of how to wire it to the arduino.

Okay, to make life easier, here is the diagram in a nutshell:

  • gnd = these are the grounds, they go starght to the negative power supply of your board

  • 1-4y = these go to the positive and negative attachments of your dc motors

  • 1-4a = these are the arduino pins you want to control your motor to mke it swith directions, these do not need to be pmw pins, so don't ask

  • vcc1, vcc2 = these are the positive inputs, vcc1 is the positive of you motors and vcc2 will either be the positive from the other motor, or if it is only one motor, it will go to the positive power supply on you board.

  • 1-2 en, 3-4 en = these are the analog declaratives for how much power will be flowing to the two motors, these do need to be pmw pins, so don't ask.

  • Here is a code that uses the h-bridge. This is the code from the self driving car fall project listed on the site. Pins axelpmw as well as analog, are the two analog inputs of the h-bridge (1-2en, 3-4en). axel 1-2, ledPin -2 are the motor inputs that go on the two sides of the negative grounds. the code is already pre-commented (if that's a word). good luck and Godspeed.

int motor1 = 2; //declares the first pin for the motor

int motor2 = 4; //declares the other pin for the motor

int motorpmw = 9; // this is the pmw that will set how much battery power the motor is getting (speed)

void setup()


pinMode(motor1, OUTPUT); //

pinMode(motor2, OUTPUT); // these simply are declaring them as outputs

pinMode(motorpmw, OUTPUT); //


void loop()


analogWrite(motorpmw, 255); // this is the analog speed value for the arduino (0-255)

digitalWrite(motor1, HIGH);

digitalWrite(motor2, LOW); //turns the motors on - forwards

delay(1000); // resets the coding sequence and refiles all the commands under the y-drive of the mainframe.

digitalWrite(motor1, LOW);

digitalWrite(motor2, HIGH); //makes motor go backwards

delay(1000); //summons demons to influence the creation of man into waiting for exactly 1 second.