Arduino板控制不了马达,马达不动
代码:const int negR=4;
const int posR=5;
const int negL=6;
const int posL=7;
const int pwmR=9;
const int pwmL=10;
void setup()
{
pinMode(posR,OUTPUT);
pinMode(negR,OUTPUT);
pinMode(posL,OUTPUT);
pinMode(negL,OUTPUT);
pinMode(pwmR,OUTPUT);
pinMode(pwmL,OUTPUT);
}
void loop()
{
forward(190,200);
delay(2000);
pause(0,0);
delay(2000);
back(190,200);
delay(2000);
pause(0,0);
delay(2000);
}
void forward(byte RmotorSpeed, byte LmotorSpeed)
{
analogWrite(pwmR,RmotorSpeed);
analogWrite(pwmL,LmotorSpeed);
digitalWrite(posR,HIGH);
digitalWrite(negR,LOW);
digitalWrite(posL,LOW);
digitalWrite(negL,HIGH);
}
void back(byte RmotorSpeed, byte LmotorSpeed)
{
analogWrite(pwmR,RmotorSpeed);
analogWrite(pwmL,LmotorSpeed);
digitalWrite(posR,LOW);
digitalWrite(negR,HIGH);
digitalWrite(posL,HIGH);
digitalWrite(negL,LOW);
}
void pause(byte RmotorSpeed, byte LmotorSpeed)
{
analogWrite(pwmR,RmotorSpeed);
analogWrite(pwmL,LmotorSpeed);
digitalWrite(posR,LOW);
digitalWrite(negR,LOW);
digitalWrite(posL,LOW);
digitalWrite(negL,LOW);
}
老哥你这是怎么供电的,用Arduino 同轴DC接口反向给L298N供电?
* 同轴DC我见是给Arduino供电的,没见过用来输出的,你可能理解错了,可以看下电路图
* 一般L298N供电电压9v以上电机比较有劲
* L298N模块和控制器(这里是Arduino)要共地(GND)
电源有问题,你用arduino上的5v连一个升压模块然后连一个L298N l298电源有三个接线柱,有一个是5v,专门给逻辑板供电用的,接到arduino板的vin口,再把gnd接到arduino的gnd口。如果逻辑板有另外供电,那只接gnd到板上就行了
页:
[1]