Driver doesn't response always

Hi forum (firtst post here)

I have some problems with my project. I'm making a robot on 4 weels with a motor each. I bought the following driver shield :

http://www.dfrobot.com/wiki/index.php?title=Arduino_Motor_Shield_(L298N)_(SKU:DRI0009)

I made a simpel move and turn code for it :

//Arduino PWM Speed Control:
int E1 = 5;  
int M1 = 4; 
int E2 = 6;                      
int M2 = 7;                        

void setup() 
{ 
    pinMode(M1, OUTPUT);   
    pinMode(M2, OUTPUT); 
} 

void loop() 
{ 
  delay(10000);
    digitalWrite(M1,LOW);   
    digitalWrite(M2, LOW);       
    analogWrite(E1, 255);   //PWM Speed Control
    analogWrite(E2, 255);   //PWM Speed Control
delay(3000);
analogWrite(E1, 0);   //PWM Speed Control
    analogWrite(E2, 0);
   delay(3000); 
       digitalWrite(M1,HIGH);   
    digitalWrite(M2, LOW);       
    analogWrite(E1, 255);   //PWM Speed Control
    analogWrite(E2, 255);   //PWM Speed Control
    delay(3000);
analogWrite(E1, 0);   //PWM Speed Control
    analogWrite(E2, 0);
    delay(10000);
}

When i use a usb scource this codes works perfectly but when I use a battery the thing most of the time get stuck at the first move command. Sometimes it does work but most of it doesn't.

What did I do wrong?

Cheers,

What battery are you using?

How are the motors powered?

...R

Robin2: What battery are you using?

How are the motors powered?

...R

I'm using a pack of 8 1,5 AA batterys. They got powerd by the shield that stand in external mode. The first command works fine but it looks like the arduino gets stuck and never get out of the delay of 3000ms ?

mistertimmy952: I'm using a pack of 8 1,5 AA batterys. They got powerd by the shield that stand in external mode.

Are you using rechargeable NiMh batteries?

Are the batteries powering the motors as well as the Arduino?

Can you confirm that the motors do not draw their power THROUGH the Arduino board?

When the Arduino is connected to USB what is powering the motors?

My guess is that the motors draw so much current from the battery that the voltage to the Arduino falls below an acceptable level. If so you need batteries with a greater instantaneous current capability or a separate battery to power the Arduino. Temporary use of a separate battery would be a good diagnostic test.

...R

Ok, I use alkaline batteries.

Yes they power the arduino and the motorshield.

I did some testing, when I use the usb for the arduino and I power the shield with the arduino (so no battery in use) he runs perfectly trough the program all day long.

When I do the arduino and drivershield on the same battery, the arduino keeps sending 5V on the E1 and E2 (pwn pins) so the motor only performs the first movment (and he keeps doing this he never gets below the 5V) so it seems the drivers works fine the arduino just get stuck in the program and keeps on sending 5V over E1 and E2. Sometimes it jumps to the other movement commands but this happens on lower pwn. (150) But he gets stuck again after a while.

When I power the arduino on usb and the motor on battery it works a couple of runs (mostly) but then again same thing happens the E1 and E2 stay on 5V motor stays spinning.

Also maybe it will be use full, I disconnected the motor shield from the arduino and I connected the E1,E2,M1,M2 GND and 5V pin again couple of runs works then get stuck. I noticed the following the 5V pin on the arduino is 5V but the 5V on the shield (on battery) is only 2,5? How is this possible?

Simple - don't run the Arduino from the motor battery pack, give it a separate supply that won't drop-out when the motors power up, and it will work.