hi there. first post here
i am having trouble with the L298n shield v2.1.
http://www.elechouse.com/store/bbs/viewtopic.php?f=8&t=12
i am running on a arduino mega and a 7.2v 2map battery for the motors
the wiring looks good, the motors run but it doesnot do what the code intends to:
int pwm_a = 10; //speed right motor
int pwm_b = 9; //speed left motor
int dir_fa = 12; //forward motor right
int dir_ba = 13; //backwards motor right
int dir_fb = 11; //forward motor left
int dir_bb = 8; //backwards motor left
void setup()
{
pinMode(pwm_a, OUTPUT); //Set control pins to be outputs
pinMode(pwm_b, OUTPUT);
pinMode(dir_fa, OUTPUT);
pinMode(dir_ba, OUTPUT);
pinMode(dir_fb, OUTPUT);
pinMode(dir_bb, OUTPUT);
analogWrite(pwm_a, 100); //set both motors to run at (100/255 = 39)% duty cycle (slow)
analogWrite(pwm_b, 100);
}
void loop()
{
digitalWrite(dir_fa, HIGH); //GO FORWARD
digitalWrite(dir_ba, LOW);
digitalWrite(dir_fb, HIGH);
digitalWrite(dir_bb, LOW);
delay(5000);
digitalWrite(dir_fa, LOW); // GO BACKWARDS
digitalWrite(dir_ba, HIGH);
digitalWrite(dir_fb, LOW);
digitalWrite(dir_bb, HIGH);
delay(5000);
}
i got this code from a website and changed the values, it should make the motors run forwards for 5 seconds then backwards for 5 secondes and loops, however the motors run back and forth on their own.
is the a problem with the code? please help,
Thanks Paulo