TB6612 Motor Driver Module
This module is much more efficient than the traditional L298N and has a significantly smaller size. Within the rated range, the chip hardly generates heat, making it more delicate. Therefore, we recommend it for those with some hands-on experience. When wiring, be sure to be very careful, paying close attention to the correct polarity.
Module Source
Specifications
VM Motor Voltage: <12V
VCC Chip Voltage: 2.7~5.5V
Output Current: 1A
Control Method: PWM
Instructions for Use
The STBY pin is connected to the microcontroller's IO pin. When STBY is set to 0, the motor will stop completely. It must be set to 1 for the motor to work. Once STBY is set to 1, the motor's forward and reverse direction can be controlled using AIN1, AIN2, BIN1, and BIN2.
The A side (AIN1 and AIN2) can only control the AO1 and AO2 terminals. Similarly, the B side (BIN1 and BIN2) can only control the BO1 and BO2 terminals. Therefore, it is a dual-channel motor driver.
Hardware Connection
The TB6612FNG motor driver module typically has the following main pins: VCC, GND, VM, AIN1, AIN2, BIN1, BIN2, PWMA, PWMB, and the motor connection terminals A01, A02, B01, B02. Here's how to connect them to the Arduino and motors:
VM connects to the positive terminal of the external power supply to drive the motor. (Make sure the voltage matches your motor's specifications)
VCC connects to the 5V of the development board to power the logic part of the driver.
GND connects to the GND of the development board and the GND of the power supply.
AIN1 and AIN2 control the direction of motor A, connected to the digital output pins of the development board.
BIN1 and BIN2 control the direction of motor B, also connected to the digital output pins of the development board.
PWMA controls the speed of motor A, connected to the PWM output pin of the development board.
PWMB controls the speed of motor B, also connected to the PWM output pin of the development board.
A01, A02 connect to the two terminals of motor A.
B01, B02 connect to the two terminals of motor B.
Below is the wiring for this example:
Usage Method
This code first sets two direction pins (AIN1, AIN2) and a speed control pin (PWMA) as output mode. In the main loop (loop
function), the code implements the motor's forward, stop, and reverse operations (by changing the high and low levels of AIN1 and AIN2) and controls the speed usinganalogWrite
to generate a PWM signal.
Make sure to adjust the PWM signal value (through the second parameter of the analogWrite
function) to control the motor's speed. The PWM range is from 0 (completely stopped) to 255 (maximum speed).
To ensure the system's stability, it's recommended to use a separate power supply for the driver, especially when the motor you're driving requires a high current. Also, make sure the ground of the TB6612 module is connected to the ground of the development board.
#define AIN1 2
#define AIN2 3
#define PWMA 5 // PWM控制引脚,支持PWM的Arduino数字引脚
void setup() {
// 设置AIN1, AIN2和PWMA为输出模式
pinMode(AIN1, OUTPUT);
pinMode(AIN2, OUTPUT);
pinMode(PWMA, OUTPUT);
}
void loop() {
// 电机正转
digitalWrite(AIN1, HIGH);
digitalWrite(AIN2, LOW);
analogWrite(PWMA, 255); // 使用PWM控制速度,0 (停止) 到 255 (最大速度)
delay(1000); // 电机运行1秒
// 电机停止
digitalWrite(AIN1, LOW);
digitalWrite(AIN2, LOW);
delay(1000); // 停止1秒
// 电机反转
digitalWrite(AIN1, LOW);
digitalWrite(AIN2, HIGH);
analogWrite(PWMA, 255); // 改变PWM值控制速度
delay(1000); // 电机运行1秒
// 可以在这里添加更多的控制逻辑
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33