1
\$\begingroup\$

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

\$\endgroup\$
1
\$\begingroup\$

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;
\$\endgroup\$
  • \$\begingroup\$ yes wiring is correct. im sure about pwm pins. \$\endgroup\$ – Ahmet Yildirim Oct 9 '10 at 17:26
  • \$\begingroup\$ my arduino produces pwm output from: 5,6,3 pins i choosed to use pwm5 for first motor and \$\endgroup\$ – Ahmet Yildirim Oct 9 '10 at 17:27
  • \$\begingroup\$ pwm3 for the second one \$\endgroup\$ – Ahmet Yildirim Oct 9 '10 at 17:28
  • \$\begingroup\$ 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. \$\endgroup\$ – JustJeff Oct 9 '10 at 17:33
  • \$\begingroup\$ i'll check if the second motor also have save problem \$\endgroup\$ – Ahmet Yildirim Oct 9 '10 at 17:55
0
\$\begingroup\$

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.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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