Problem using L293D with a 3 - 6 V DC motor

I´m trying to fix a trash bin with an arduino sketch (ultrassonic sensor, L293D, arduino pro mini, 7805, 9v battery, DC motor of trash bin).
When not connected to a PC, not work.
When connected to a PC works a few times. After some times works only for open a trash bin and never closes it.
I really appreciate some advice.

#include <Narcoleptic.h>
#include <Ultrasonic.h>

// definicao das portas usadas para o sensor ultrassonico
#define echoPin 6
#define triggerPin 7

//definicao das portas usadas para o L293D - po nte para acionar motor
#define motorPin1 3
#define motorPin2 4
#define motorEnable 9
#define ledopen 12
#define ledclose 13

Ultrasonic ultrasonic(echoPin,triggerPin);

void setup()
{

pinMode(triggerPin, OUTPUT);
pinMode(echoPin, INPUT);

// “programa portas do L293D”
pinMode(motorPin1, OUTPUT);
pinMode(motorPin2, OUTPUT);
pinMode(motorEnable, OUTPUT);

// pinos dos leds
pinMode(ledopen, OUTPUT);
pinMode(ledclose, OUTPUT);

Serial.begin(9600);

}

void loop()
{

digitalWrite(triggerPin, LOW);
delayMicroseconds(2);
digitalWrite(triggerPin, HIGH);
delayMicroseconds(10);
digitalWrite(triggerPin, LOW);
long duration = pulseIn(echoPin, HIGH);
int cm = microsecondsToCentimeters(duration);

if(cm <= 50 && cm >=5)
{

abreTampa();

}
}

void abreTampa()
{

Serial.println(“abrindo tampa”);

digitalWrite(motorEnable, HIGH);

digitalWrite(motorPin1, 1); //
digitalWrite(motorPin2, 0); //

Serial.println("espera 5 segundos ");
Narcoleptic.delay(5000);

digitalWrite(motorPin1, 0); // para o motor
digitalWrite(motorPin2, 0); //

Serial.println(“fechando tampa”);
digitalWrite(motorPin1, 0);
digitalWrite(motorPin2, 1);

Serial.println("espera 5 segundos ");
Narcoleptic.delay(5000);

digitalWrite(motorPin1, 0); // para o motor
digitalWrite(motorPin2, 0); //

Serial.println("…end … ");

}

void fechaTampa()
{

digitalWrite(motorEnable, HIGH);

digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, HIGH);

Narcoleptic.delay(3000);

digitalWrite(motorEnable, LOW);

}

float microsecondsToCentimeters(long microseconds)
{
float seconds = (float) microseconds / 1000000.0;
float distance = seconds * 340;
distance = distance / 2;
distance = distance * 100;
return distance;
}

9V battery - no use at all for motors.