Motor won't work with Ultrasonic sensor

I’m making an obstacle avoiding robot and I’m having an issue with the motor and sensor. I’ve wired the sensor from the Arduino and then attached a L293D on top of the Arduino. I’ve attached a picture to show this.

If I have this line included, my motors don’t work at all (echo is pin #8):

pinMode(echo, INPUT);

If I comment out that line, my motors work fine.

Any idea why this is happening?

Most likely, pin usage conflict. See "How to use this forum" for instructions and advice on posting.

OP's pic:

You'll need to post your code, OP.

Sorry, didn’t think I needed to post the code. Anyways, here it is. Its just a short test for the sensor+motor:

#include <AFMotor.h>
AF_DCMotor motor1(1);

int echo = 8;
int trig = 7;
void setup() {
  Serial.begin(9600);
  motor1.setSpeed(200);
  motor1.run(RELEASE);
  pinMode(trig, OUTPUT);
  pinMode(echo, INPUT);
}

void loop() {
  digitalWrite(trig, LOW);
  delayMicroseconds(5);
  digitalWrite(trig, HIGH);
  delayMicroseconds(10);
  digitalWrite(trig, LOW);
  int duration = pulseIn(echo, HIGH);
  int distanceCM = (duration/2) / 29.1;
  int distanceINCH = (duration/2) / 74;
  Serial.print(distanceCM);
  Serial.println(" cm");
  Serial.print(distanceINCH);
  Serial.println(" inches");
  if(distanceINCH <=1){
    motor1.run(FORWARD);
    motor1.setSpeed(255);
    delay(1000);
    motor1.run(RELEASE);
  }
}

Have a look in the source or documentstion for the library, it’s possible or even likely that pin 8 is hardcoded for that shield.

So you will need to consult the shield / library docs to see which pins are vacant.

Yes, you were right. I changed both pins to 12 and 13 and it worked, thanks for the help.