微信登录
注册忘记密码
查看: 1213|回复: 0

Arduino 实例(四十四)TB6612FNG与直流电机控制

[复制链接]

该用户从未签到

发表于 2022-8-5 10:56:04 | 显示全部楼层 |阅读模式
1 为什么用TB6612FNG?
一张图很能说明问题,L298N电机驱动模块体积太大了,TB6612FNG模块体积小,可以实现同样的功能
2 TB6612FNG引脚连接
Arduino uno
TB6612FNG
电机
电源
PIN3
PWMA




8
AN1




9
AN2




10
STBY






A01
正极




A02
负极


5V
VCC




GND
GND


GND


VM


6V输入

3 接线示意图
4 实物接线图
5 程序
//motor A connected between A01 and A02//motor B connected between B01 and B02 int STBY = 10; //standby //Motor Aint PWMA = 3; //Speed control int AIN1 = 9; //Directionint AIN2 = 8; //Direction //Motor Bint PWMB = 5; //Speed controlint BIN1 = 11; //Directionint BIN2 = 12; //Direction void setup(){  pinMode(STBY, OUTPUT);   pinMode(PWMA, OUTPUT);  pinMode(AIN1, OUTPUT);  pinMode(AIN2, OUTPUT);   pinMode(PWMB, OUTPUT);  pinMode(BIN1, OUTPUT);  pinMode(BIN2, OUTPUT);} void loop(){  move(1, 255, 1); //motor 1, full speed, left  move(2, 255, 1); //motor 2, full speed, left   delay(1000); //go for 1 second  stop(); //stop  delay(250); //hold for 250ms until move again   move(1, 128, 0); //motor 1, half speed, right  move(2, 128, 0); //motor 2, half speed, right   delay(1000);  stop();  delay(250);}  void move(int motor, int speed, int direction){//Move specific motor at speed and direction//motor: 0 for B 1 for A//speed: 0 is off, and 255 is full speed//direction: 0 clockwise, 1 counter-clockwise   digitalWrite(STBY, HIGH); //disable standby   boolean inPin1 = LOW;  boolean inPin2 = HIGH;   if(direction == 1){    inPin1 = HIGH;    inPin2 = LOW;  }   if(motor == 1){    digitalWrite(AIN1, inPin1);    digitalWrite(AIN2, inPin2);    analogWrite(PWMA, speed);  }else{    digitalWrite(BIN1, inPin1);    digitalWrite(BIN2, inPin2);    analogWrite(PWMB, speed);  }} void stop(){//enable standby    digitalWrite(STBY, LOW); }6 视频效果
TB6612驱动直流电机 - 西瓜视频 (ixigua.com)

声明:以上内容来源于网络,如有侵权请联系我们(123@shiyan.com)删除!

发表回复

您需要登录后才可以回帖 登录 | 立即注册 微信登录

本版积分规则