Tell me more ×
Electrical Engineering Stack Exchange is a question and answer site for electronics and electrical engineering professionals, students, and enthusiasts. It's 100% free, no registration required.

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

share|improve this question

2 Answers

up vote 1 down vote accepted

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;
share|improve this answer
yes wiring is correct. im sure about pwm pins. – Ahmet Yıldırım Oct 9 '10 at 17:26
my arduino produces pwm output from: 5,6,3 pins i choosed to use pwm5 for first motor and – Ahmet Yıldırım Oct 9 '10 at 17:27
pwm3 for the second one – Ahmet Yıldırım Oct 9 '10 at 17:28
if you have an o-scope, you can tell if you have the software lined up with the wiring pretty quickly by looking at the L298's Enable input. If you happen to have swapped the Enable with an 'In', you'd get exactly the symptom you mentioned. – JustJeff Oct 9 '10 at 17:33
well you are right buddy. :D thank you so much – Ahmet Yıldırım Oct 9 '10 at 17:54
show 1 more comment

The first thing would be to check your motor driver actually works. It could be damaged, or perhaps is not designed to run motors in reverse. I'd check it by connecting the appropriate control pins to its V+ input.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.