Arduino and DC motor control

Operation of the two-channel H-bridge TB6612

TB6612 Motor Controller - module

A two-channel driver lets you control two DC motors. Continuous current of one motor must not exceed 1A, instantaneous 3A. The maximum supply voltage is 12V. These parameters allow to control e.g. micro motors Polol or HL149.


The module has the necessary capacitors to filter the power supply and protection against reverse power connection.

In order to facilitate assembly the module has been equipped with standard goldpin leads (raster 2,54mm). The circuit can be mounted in a prototype contact board or connected to Arduino with wires.

2. connection of the module

Power supply

VCC - power supply for the logical part

VMOT - motor power supply

GND - mass - remember that all "masses" must be connected to each other

STBY - the low state causes the transition to a stand-by state, i.e. low power consumption (stand-by), for the bridge to be activated the high state must be given

Outputs - outputs to which motors should be connected

AO1, AO2 - channel A outputs - outputs to which the first motor must be connected

BO1, BO2 - outputs of channel B - outputs to which a second motor should be connected

Engine control

PWMA - PWM signal of channel A - used to control the speed of the motor connected to channel A

AIN1 AIN2 - outputs for determining the direction of rotation of the motor connected to the outputs of channel A

PWMB - signal PWM of channel B - is used to control the speed of the motor connected to channel B

BIN1, BIN2 - outputs for determining the direction of rotation of the motor connected to the outputs of channel B

Table - operation of bridge TB6612 (x - means the corresponding channel A or B)

x IN1

x IN2

PMD x

STBY

Channel output x

low high pwm high The motor turns at the maximum setpoint speed via pwm (other than 0) clockwise.
high low pwm high The motor turns at the maximum set speed via pwm (different from 0) counterclockwise.
any any low high Hard stop.
low low any high Gentle braking.
high high any high Gentle braking.
any any any low The bridge is on hold - low power consumption.

The figure shows a sample connection of the controller with Arduino Uno module.

3. sample program

Example program for TB6612. Connect the system according to the drawing:

The program will result in a rotating motor shaft. The direction of rotation will change after two seconds. After another two seconds, the motor will stop.

Program:

int pwmMotorA=5;
int InMotorA1=4;
int InMotorA2=3;

void setup() {                 
  
  //Channel A PWM output 
  pinMode(pwmMotorA, OUTPUT); 
  
  //AIN1 digital output
  pinMode(InMotorA1, OUTPUT); 
  //AIN2 digital output
  pinMode(InMotorA2, OUTPUT);   

}

// Infinite loop
void loop() {
  
  //A channel
  
  //Set direction of rotation
  digitalWrite(InMotorA1, LOW); 
  digitalWrite(InMotorA2, HIGH);
  
  //Set speed to 50% (PWM range: 8bit or 0-255)
  analogWrite(pwmMotorA,128);
   
  //Delay 2s
  delay(2000);
  
  //Changing the direction of rotation 
  digitalWrite(InMotorA1, HIGH); 
  digitalWrite(InMotorA2, LOW);
  
  //Delay 2s
  delay(2000);
  
  //Stopping the motor - by setting the PWM fill factor to 0
  analogWrite(pwmMotorA,0);
  
  //Delay 2s
  delay(2000);

} 

Botland.store - shop for makers!