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() {
  pinMode(trig, OUTPUT);
  pinMode(echo, INPUT);

void loop() {
  digitalWrite(trig, LOW);
  digitalWrite(trig, HIGH);
  digitalWrite(trig, LOW);
  int duration = pulseIn(echo, HIGH);
  int distanceCM = (duration/2) / 29.1;
  int distanceINCH = (duration/2) / 74;
  Serial.println(" cm");
  Serial.println(" inches");
  if(distanceINCH <=1){;

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.