Arduino A4950 drives DC motor

Arduino A4950 drives DC motor

For most of the students who make cars by themselves, I, like everyone, use the L298N driver the most. This time I want to try to study a motor drive with better driving ability and more convenient motor drive, and use Arduino L298N online. There are many examples of driving the car, and there is no one in A4950. Well, I hope this article can provide a better and newer option for students who are tired of L298N.

1. Experiment preparation

1. Arduino series microcontroller
2. DC motor
3. A4950 driver

2. Introduction to A4950 chip

Insert picture description here
One A4950 driver can drive two DC motors. The
operating voltage range of the drive board: 7.6V~30V

A4950 pin Corresponding pin
VCC MCU 5V
GND MCU GND
VM Drive power 7.6~30V
AIN1 Control the 1st PWM pin of A motor
AIN2 Control the No. 2 PWM pin of A motor
AOUT1 Motor A positive
ATOU2 Motor A negative
BN1 PWM pin 1 for controlling B motor
BIN2 Control the No. 2 PWM pin of B motor
BOUT1 Motor B positive
BTOU2 Motor B negative

There are two sets of VCC GND VM on one module, connect at least one set

Single-chip A4950 drive power remember to share the ground

The A4950 driver determines the motor direction by comparing the relationship between the two control pins output PWM
The difference between the output PWM of the two control pins determines the speed of the motor

3. Programming

Our next code has already driven a motor as an example, and the remaining one can be done in the same way.

3.1 Simple driver board

unsigned int Motor_AIN1=2;       //控制A电机的PWM引脚  一定改成自己用的
unsigned int Motor_AIN2=3;       
char Motor_Order;                //定义一个字符型变量存储串口输入命令
void setup() 
{
    
    
  Serial.begin(9600);            //打开串口
  Serial.println("/*****开始驱动*****/");
  pinMode(Motor_AIN1,OUTPUT);   //设置两个驱动引脚为输出模式
  pinMode(Motor_AIN2,OUTPUT); 
}

void loop() 
{
    
    
 while(Serial.available()>0)    //检测串口是否有命令
  {
    
    
    Motor_Order=Serial.read();  //将命令存储在变量中
    switch(Motor_Order)
    {
    
    
      //发送字符1电机正转
      case '1' : analogWrite(Motor_AIN1,250); analogWrite(Motor_AIN2,0);Serial.println("/*****电机正传*****/");break;
      //发送字符2电机反转
      case '2' : analogWrite(Motor_AIN1,0); analogWrite(Motor_AIN2,250);Serial.println("/*****电机反转*****/");break;
      //发送其他字符电机停转
      default  : analogWrite(Motor_AIN1,0); analogWrite(Motor_AIN2,0);Serial.println("/*****停转****/");break;
    }
  }
}

After burning, open the serial port and input the instructions separately.
Insert picture description here

to sum up

If the motor does not rotate because of insufficient drive voltage, I use a 12V model airplane battery

Guess you like

Origin blog.csdn.net/chrnhao/article/details/112129949