Trouble getting the L293D to run with a 9V battery

I am trying to make a DC motor turn forward and reverse runnning on a 9V battery. While connected through USB to my computer everything works fine. However when I disconnect the USB and connect the 9V battery (ground to ground, 9V to Vin) the motor turns only in one direction, and stands still while it is supposed to move in the other direction.

My setup: - An uno board - H-bridge motor driver [L293D] - Small 6V DC motor - 9V battery

The L293D is connected the following way

pin 1: +5v pin 2: digital pin 9 pin 3: + motor pin 4: ground pin 5: ground pin 6: - motor pin 7: digital pin 10 pin 8: +5v

pin 9: +5v pin 10: not used yet pin 11: not used yet pin 12: ground pin 13: ground pin 14: not used yet pin 15: not used yet pin 16: +5v

I use a simple code just to test functionality

const int motorPin1 = 10; // pin 7 L293
const int motorPin2 = 9; // pin 2 L293

void setup() {
pinMode(motorPin1, OUTPUT);
pinMode(motorPin2, OUTPUT);

}

void loop() {

//stand still
 digitalWrite(motorPin1, LOW);
 digitalWrite(motorPin2, LOW);
 delay(3000);

// turn +
 digitalWrite(motorPin1, LOW);
 digitalWrite(motorPin2, HIGH);
 delay(3000);

//turn -
 digitalWrite(motorPin1, HIGH);
 digitalWrite(motorPin2, LOW);
 delay(3000);


}

Sounds like the Arduino just resets. A 9V is the most terrible battery for loads... Try a 9V adapter or a couple of AA's.

EranT: I am trying to make a DC motor turn forward and reverse runnning on a 9V battery.

You have the wrong sort of 9V battery. You need something like this http://www.connevans.co.uk/product/4091/103085/Rechargable-NiMH-PP9-battery- for high current which is what motors use.

Alternatively forget the 9V and go for a 6V or 12V SLA, or a 2S or 3S LiPo or LiFePO4 battery, something that can put out a few amps without flatlining itself.