Control motors using TB6612FNG

日本語のページ

You can control two motors using the Toshiba TB6612FNG motor driver.

Wiring

Connect the AIN1, AIN2, PWMA, BIN1, BIN2, PWMB, and STBY pins of the TB6612FNG to the microcontroller's GPIO pins.
Connect the VCC and GND pins of the TB6612FNG to the microcontroller's power supply pins.
Connect the A01, A02, B01, and B02 pins of the TB6612FNG to the two motors.
Connect the VM and GND pins of the TB6612FNG to a power source for the motors, such as dry-cell batteries.

For example, suppose you are using a standard ESP32 microcontroller and connecting it to the TB6612FNG as follows:

TB6612FNGESP32
AIN113
AIN214
PWMA12
BIN133
BIN232
PWMB27
STBY26
VCC3V3
GNDGND

The wiring for this setup looks like the diagram below.

Wiring example

Initializing the TB6612FNG

Use the initialization block to initialize the TB6612FNG.

Initialize TB6612FNG

First, assign the specific pins (such as AIN1) to variables.
Then, specify these variables in the corresponding parameters (like AIN1) within the initialization block.

Running the Motor

Use the "run single motor" block to operate either motor A or motor B.
Specify the motor to run (A or B), the direction (forward/reverse), and the speed (0–100).

Rotate one of the motors

Use the "run both motors" block to operate both motors (A and B) simultaneously. Specify the rotation direction (forward/reverse) and speed (0–100) for each motor.

Rotate both motors

Stopping the Motors

You can stop the motors by selecting "Stop" or "Brake" as the rotation mode in the motor control block.
With "Stop," there is almost no resistance if you try to turn the stopped motor by hand.
With "Brake," on the other hand, you will feel resistance if you try to turn the stopped motor by hand.

Example

The program below demonstrates how to alternate between forward and reverse rotation using two motors connected to a TB6612FNG driver.
This example assumes the wiring is set up using an ESP32, as shown in the diagram in the "Wiring" section of this page.

Example of controlling a motor with the TB6612FNG

You can download the sample program here.