Saturday, 25 January 2014

arduino - L298 Motor Driver spinning motor only one way :/


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);
}


http://farm5.static.flickr.com/4124/5065468848_a210d091aa.jpg



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

arduino - Can I use TI's cc2541 BLE as micro controller to perform operations/ processing instead of ATmega328P AU to save cost?

I am using arduino pro mini (which contains Atmega328p AU ) along with cc2541(HM-10) to process and transfer data over BLE to smartphone. I...