i just made a motor driver circuit on a veroboard to use with my arduino but the problem is l298 spinning motor only one way. here is the code it was supposed to spin motor forth and backwards every 2 seconds right?
int mot1ana=5;
int mot1a=6;
int mot1b=7;
void setup() {
pinMode(mot1ana,OUTPUT);
pinMode(mot1a,OUTPUT);
pinMode(mot1b,OUTPUT);
}
void loop() {
analogWrite(mot1ana,200);
digitalWrite(mot1a,HIGH);
digitalWrite(mot1b,LOW);
delay(2000);
analogWrite(mot1ana,200);
digitalWrite(mot1a,LOW);
digitalWrite(mot1b,HIGH);
delay(2000);
}
Answer
It looks like you have chosen to use arduino pin numbers that are very similar to the necessary pin numbers on the L298. Nothing wrong with that, you can use whichever arduino pins are convenient. But it seems like it would be an easy mistake (with the given code) just to wire pin N from the arduino to pin N of the L298 under such circumstances.
With the L298, you want the analog PWM going into pin 6, and your arduino is producing that at pin 5. So you'd want 5 from the arduino going to 6 on the L298, and 6 on the arduino going to 5 on the L298. Arduino pin 7 would still go to L298 pin 7.
OR
if want to go with the 5-5, 6-6, 7-7 wiring, you could fix it in software, just by changing
int mot1ana=5;
int mot1a=6;
int mot1b=7;
to
int mot1ana=6;
int mot1a=5;
int mot1b=7;
No comments:
Post a Comment