TB6612FNG Motor driver failure

Hello, I am new to this forum. I have purchased the TB6612FNG dual motor controller for use with the Dagu Rover 5 and an Arduino Uno Rev 3. I using this combo for my senior design project at my university. I had everything working fine, running basic tests, worked great. I could get motor A to go forwards and backwards without trouble, as well as motor B. I could get them to rotate forward together or backward together, as well as opposite directions without trouble. I moved on to adding some photoresistors to my project to make the robot follow light. I was getting good values on the analog pins without problem. So I coded up a simple if else statement which used the photoresistor values to determine whether to go forward, left or right. This was working perfectly, and I thought it was almost too easy.

This is the problem I am having. I decided to slow the motor speeds, because I didn’t want to let the robot loose, and crash into stuff. So i put the PWM frequency value to 128 (instead of 255 where it was before), and ran my tests again. The motors seemed to operate at the same speed. So I tried 64 instead of 128, same thing. Then I put it down to 10 expecting it to not even turn the motors, but it did. However when it came to motor A going in the reverse direction it would not go, however the motor had resistance as if there was some current going through it.

After trying meticulously going over my code, and rewiring the TB6612FNG again to make sure all my connections were good, I had same results. Motor A will not go in reverse, even when I put PWM frequency back to 255. So tried disconnecting motor A, and just supply direct power in forward and reverse polarities to see if the motor would operate in the reverse direction if the correct current was applied. It did! So a little more detective work ( thanks for the patience to read this long problem). I wired motor A back in and hooked AO1 and AO2 to a couple of analog pins to read the output values and send them to the serial monitor of the Arduino. This was my results:

Reading Left motor motorcontroller outputs values.
Begin forward
AO1 = 19 A02 = 1023
Begin reverse
AO1 = 14 A02 = 15
Begin forward
AO1 = 18 A02 = 1023
Begin reverse
AO1 = 15 A02 = 15
Begin forward
AO1 = 14 A02 = 1023
Begin reverse
AO1 = 14 A02 = 15
Begin forward
AO1 = 17 A02 = 1023
Begin reverse
AO1 = 14 A02 = 15
Begin forward
AO1 = 19 A02 = 1023
Begin reverse
AO1 = 14 A02 = 15
Begin forward
AO1 = 16 A02 = 1023
Begin reverse
AO1 = 14 A02 = 15
Begin forward
AO1 = 14 A02 = 1023
Begin reverse
AO1 = 14 A02 = 15
Begin forward
AO1 = 20 A02 = 1023
Begin reverse
AO1 = 14 A02 = 14
Begin forward
AO1 = 20 A02 = 1023

Any time motor A is told to go in reverse the AO1 and AO2 outputs are nearly the same, resulting in a LOW/LOW which wouldn’t drive the motor any direction.

Here is the code I used to get this output:

//motorcontrolTestv1
// Author: Brad Hackett
// date: 1/16/2013

  //  TB6612FNG motor control variables
  int AIN1 = 4;
  int AIN2 = 2;
  int BIN1 = 7;
  int BIN2 = 8;
  int PWMA = 3;
  int PWMB = 12;
  int STBY = 9;

   // variable to store speed value
  int vel = 255;
  
  //left motor A outputs
  int aPin1 = 1;
  int aPin2 = 2;
  
  int aout1;
  int aout2;

void setup() {
  
  // declaring mode of pins to be outputs
  pinMode(AIN1, OUTPUT);
  pinMode(AIN2, OUTPUT);
  pinMode(BIN1, OUTPUT);
  pinMode(BIN2, OUTPUT);
  pinMode(PWMA, OUTPUT);
  pinMode(PWMB, OUTPUT);
  pinMode(STBY, OUTPUT);
  
  //Setup left motor pins
  pinMode(aPin1, INPUT);
  pinMode(aPin2, INPUT);
  digitalWrite(A1, HIGH);
  digitalWrite(A2, HIGH);
  
  Serial.begin(9600);
  Serial.println("\nReading Left motor motorcontroller outputs values.");
  
  // turn off both motor to begin with
  A_stop();
  B_stop();
  
  //delay(500);
  
  digitalWrite(STBY, HIGH);

}

void loop() {
  
  A_forward(vel);
  delay(2000);

  aout1 = analogRead(aPin1);
  aout2 = analogRead(aPin2);
  Serial.print("Begin forward\n");
  Serial.print("AO1 = ");
  Serial.print(aout1);
  Serial.print("\t");
  Serial.print("A02 = ");
  Serial.print(aout2);
  Serial.print("\n");

A_reverse(vel);
delay(1000);

  aout1 = analogRead(aPin1);
  delay(1);
  aout2 = analogRead(aPin2);
  delay(1);
  Serial.print("Begin reverse\n");
  Serial.print("AO1 = ");
  Serial.print(aout1);
  Serial.print("\t");
  Serial.print("A02 = ");
  Serial.print(aout2);
  Serial.print("\n");

A_stop();
delay(1000);

}

// Motor Functions //

/// Left Motor ///
void A_reverse(int freq)
{
  digitalWrite(AIN1, HIGH);
  digitalWrite(AIN2, LOW);
  digitalWrite(PWMA, freq);

}

void A_forward(int freq)
{
  digitalWrite(AIN1, LOW);
  digitalWrite(AIN2, HIGH);
  digitalWrite(PWMA, freq);
}

void A_stop()
{
  digitalWrite(AIN1, LOW);
  digitalWrite(AIN2, LOW);
  digitalWrite(PWMA, LOW);
}

/// Right Motor ///
void B_reverse(int freq)
{
  digitalWrite(BIN1, LOW);
  digitalWrite(BIN2, HIGH);
  digitalWrite(PWMB, freq);
}

void B_forward(int freq)
{
  digitalWrite(BIN1, HIGH);
  digitalWrite(BIN2, LOW);
  digitalWrite(PWMB, freq);
}

void B_stop()
{
  digitalWrite(BIN1, LOW);
  digitalWrite(BIN2, LOW);
  digitalWrite(PWMB, LOW);
}

// Both Motors
void AB_reverse(int freq)
{
  A_reverse(freq);
  B_reverse(freq);
}

void AB_forward(int freq)
{
  A_forward(freq);
  B_forward(freq);
}

void AB_stop()
{
  A_stop();
  B_stop();
}

void AB_turn_left(int freq)
{
  A_reverse(freq);
  B_forward(freq);
}

void AB_turn_right(int freq)
{
  A_forward(freq);
  B_reverse(freq);
}

If anyone has seen this problem before or knows what I am doing wrong please let me know, as I can not make much progress on my Senior Design project without a fully function motor controller.

Hi.

Changing the frequency of the PWM signal you are supplying your driver will not change the motor’s speed. To adjust the speed you should adjust the duty cycle of the PWM signal.

In addition, the code you posted tries to use the Arduino’s digitalWrite function to set the duty cycle of your PWM output. That function is only meant to output digital values (i.e. high or low); you should use the analogWrite function instead.

Connecting the motor driver’s outputs directly to an Arduino is a really bad idea (especially if your motor voltage is higher than 5V), and is likely to damage your Arduino. If you want to check the voltages on the motor outputs you should use a multimeter or oscilloscope instead.

-Claire