Using the pololu tb6612fng dual motor driver with an Arduino to control two low powered DC motors

Pololu_TB6612FNG.jpg

Hello LMRians,

Ever tried using the pololu tb6612fng dual motor driver? Quite handy if you are thinking of controlling two low powered DC motors. It can handle a peak current of 3Amps, and can deliver 1Amp continuous current to two motors. There are 16 pins on this motor driver, and here is how you connect it to an Arduino.

1) GND - Connect it to the GND pin on the Arduino

2) VCC - The Logic Voltage of the motor driver IC. Connect it to the 5V pin on the Arduino.

3) A01 - The output pin that is connected to the positive terminal of Motor A.

4) A02 - The output pin that is connected to the negative terminal of Motor A

5) B02- The output pin that is connected to the negative terminal of Motor B.

6) B01- The output pin that is connected to the positive terminal of Motor B

7) VMOT- The motor voltage pin. Connect it to the positive terminal of your battery. ( For powering motors)

8) GND- Connect it to the negative terminal of your battery.

9) GND- Connect it to the GND pin on the Arduino.

10) PWMB- The PWM pin of the motor driver for adjusting the speed of Motor B . Connect it to any of the PWM pins on the Arduino and specify a speed value for the motor from 0-255.

11 & 12 ) BIN2 and BIN1 - The input pins of the motor driver for Motor B that specify the direction of Motor B. Connect it to any two digital pins on the Arduino.

13) STBY- Just like a power pin which on setting to HIGH enables the motor control mechanism . Connect it to any digital pin.

14 & 15) AIN1 and AIN2- The input pins of the motor driver for Motor A that specifies the direction of Motor A. Connect it to any two digital pins on the Arduino.

16) PWMA- The PWM pin of the motor driver for adjusting the speed of Motor B. Connect it to any of the PWM pins on the Arduino and specify a speed value for the motor from 0-255.

So, now that you have connected the pins, how do you program your Arduino to control the speed and direction of your motors? It's as simple as shown below:

For motor A to go forward you need to set AIN1 to HIGH and AIN2 to LOW

likewise, for motor B to go forward, you need to set BIN1 to HIGH and BIN2 to LOW.

Swap the HIGH and LOW values to make the motors go in reverse.

Similary, for PWM, specify values from 0 - 255 to pins PWMA and PWMB,

Most importantly, set STBY to HIGH, or else, nothing will start up.

So, for driving you robot forward with a PWM value of 125, the code should look something like :

digitalWrite(STBY, HIGH);

digitalWrite(AIN1, HIGH);

digitalWrite(AIN2, LOW);

analogWrite(PWMA, 125);

digitalWrite(STBY, HIGH);

digitalWrite(BIN1, HIGH);

digitalWrite(BIN2, LOW);

analogWrite(PWMB, 125);

Similarly, for going back, swap the HIGH-LOW values for pins AIN1, AIN2 and BIN1, BIN2

In the same way, you can try out left turn, right turn, and many other functions. Good luck.

Please let me know if i have left out something, or something is not correct :-)

Ashim

More Juice

 

Any suggestions for teh 12V 10A range?

 

Useful Sketch Function

I offer this tried and tested method to control it. You simply supply the two parameters “motor” (1 or 2) and “per255” which can be a number from -255 to +255, where the negative values run the motor one way while the positive values run it the other.

 

void setMotor(int motor, int per255) {

  int pin1, pin2; // each “side” of the selected motor

  boolean outputs = true; // protection against inappropriate motor index

  switch (motor) {

    case 1:

      pin1 = motorPin1;

      pin2 = motorPin2;

      break;

    case 2:

      pin1 = motorPin3;

      pin2 = motorPin4;

      break;

    default:

      outputs = false; // if we’re here, the motor index was bad

      break;

  } // switch motor

  if (outputs) {

    if (per255 < 0) { // negative = run “backwards”

      digitalWrite(pin2, LOW);

      analogWrite(pin1, abs(per255));

    } else { // positive = run “forwards”

      digitalWrite(pin1, LOW);

      analogWrite(pin2, per255);

    } // if per else

  } // if outputs

} // setMotor

Thankyou BOA, much easier to

Thankyou BOA, much easier to integrate it into your code, i’ll try it :slight_smile:

Indeed, i am bulding a sumo

Indeed, i am bulding a sumo bot using two high powered motors, each rated at a stall current of 7.5A and a voltage of 12V. I am using this powerful dual motor driver shield for an arduino. It runs from 5.5 to 24 volts and can deliver 12Amps continnous or 30Amps peak per motor. I have tested it, the build is going on. Handling 7.5 Amps is a breezer for this guy. :slight_smile:

 

One more thing

Just spotted a teency flaw. motorPin1 through motorPin 4 need to be declared (prefereably as constants) globally. They take on teh values of the pins to which you have your dual H-bridge wired.

Hi I saw on the Pololu website that this TB6612FNG Dual Motor Driver doesn’t have reverse protection for the Vcc connection.

I wondered if you had any trouble with this and if so how you got round it?

Thanks
Matty