Pololu Robotics & Electronics
My account Comments or questions? About Pololu Contact Ordering information Distributors

Help w/ controlling TB6612FNG without PWM pins


Hello everyone,
I recently ordered the TB6612FNG dual motor driver carrier from pololu, however, for my project I need to be able to control two dc motors without having to use PWM pins with the Arduino UNO. This is because for what I am doing, I will be controlling multiple dc motors and speed control is not necessary in my case and requires additional PWM pins-- which I do not have the resources for.

Anyways, I soldered on the header pins that came with the board and tried connecting the board to two micro metal gear motors (not from pololu). Using the sparkfun TB6612FNG library, I just used the demo code and made the appropriate connections and everything was working fine as both motors were turning in both directions and at multiple speeds, however this setup used pwm pins 5 and 6, which I do not want. I then tried to use some very simple code using the digitalWrite command to set the STBY pin as HIGH to enable the driver, pin AIN1 as HIGH, and AIN2 as LOW to see if this time just one motor would turn at full speed in one direction however I got no response. This is the code I used to tell the motor to turn forward, backward, and stop:

int STBY = 9; //standby

int AIN1 = 2;
int AIN2 = 4;

void setup(){
pinMode(STBY, OUTPUT);

pinMode(AIN1, OUTPUT);
pinMode(AIN2, OUTPUT);


void loop(){
digitalWrite(STBY, HIGH);

digitalWrite(AIN1, HIGH);
digitalWrite(AIN2, LOW);


digitalWrite(AIN1, LOW);
digitalWrite(AIN2, HIGH);


digitalWrite(STBY, LOW);
digitalWrite(STBY, LOW);


I am also using a 6V AA battery pack as my power source. Additionally, it would be convenient if non-PWM but bidirectional control could be achieved using the tb6612fng library because I find the functions convenient to use, however it is fine if this is not possible. Also, this is the sparkfun tb6612fng library demo code:

TB6612FNG H-Bridge Motor Driver Example code
Michelle @ SparkFun Electronics

Uses 2 motors to show examples of the functions in the library.  This causes
a robot to do a little 'jig'.  Each movement has an equal and opposite movement
so assuming your motors are balanced the bot should end up at the same place it

TB6612 SparkFun Library

Development environment specifics:
Developed on Arduino 1.6.4
Developed with ROB-9457

// This is the library for the TB6612 that contains the class Motor and all the
// functions
#include <SparkFun_TB6612.h>

// Pins for all inputs, keep in mind the PWM defines must be on PWM pins
// the default pins listed are the ones used on the Redbot (ROB-12097) with
// the exception of STBY which the Redbot controls with a physical switch
#define AIN1 2
#define BIN1 7
#define AIN2 4
#define BIN2 8
#define PWMA 5
#define PWMB 6
#define STBY 9

// these constants are used to allow you to make your motor configuration 
// line up with function names like forward.  Value can be 1 or -1
const int offsetA = 1;
const int offsetB = 1;

// Initializing motors.  The library will allow you to initialize as many
// motors as you have memory for.  If you are using functions like forward
// that take 2 motors as arguements you can either write new functions or
// call the function more than once.
Motor motor1 = Motor(AIN1, AIN2, PWMA, offsetA, STBY);
Motor motor2 = Motor(BIN1, BIN2, PWMB, offsetB, STBY);

void setup()
 //Nothing here

void loop()
   //Use of the drive function which takes as arguements the speed
   //and optional duration.  A negative speed will cause it to go
   //backwards.  Speed can be from -255 to 255.  Also use of the 
   //brake function which takes no arguements.
   //Use of the drive function which takes as arguements the speed
   //and optional duration.  A negative speed will cause it to go
   //backwards.  Speed can be from -255 to 255.  Also use of the 
   //brake function which takes no arguements.
   //Use of the forward function, which takes as arguements two motors
   //and optionally a speed.  If a negative number is used for speed
   //it will go backwards
   forward(motor1, motor2, 150);
   //Use of the back function, which takes as arguments two motors 
   //and optionally a speed.  Either a positive number or a negative
   //number for speed will cause it to go backwards
   back(motor1, motor2, -150);
   //Use of the brake function which takes as arguments two motors.
   //Note that functions do not stop motors on their own.
   brake(motor1, motor2);
   //Use of the left and right functions which take as arguements two
   //motors and a speed.  This function turns both motors to move in 
   //the appropriate direction.  For turning a single motor use drive.
   left(motor1, motor2, 100);
   right(motor1, motor2, 100);
   //Use of brake again.
   brake(motor1, motor2);

I would appreciate any help with my issue, and if it isn’t evident already, I am an absolute beginner with Arduino. Thank you.



I am sorry you are having trouble getting your motor driver working. Even if you do not plan to adjust the speed of your motor, you should still do something with the PWM pin in your setup. By default, that pin is pulled low, which effectively disables the motor outputs by commanding a 0% duty cycle. Pulling the PWM pin to logic high will allow current to flow through the outputs. Can you connect PWMA to logic high and try controlling your motor again? If that does not work, can you post pictures that clearly show your connections and soldered joints?



Thank you Jonathan, I did not know that the PWM pins disabled the motor outputs if left by default however I tried what you said with connecting PWMA to logic high and it worked great. Thanks again.