only one dc motor spins

Hello. I'm trying to build a garbage collecting robot. I'm using two DC motors (300rpm) and two servo motors (4.8-6V).
The first problem is, only one DC motor works, the other doesn't, and the second problem is that the servos do not work either. My first goal is to get the dc motors running.

//L293D
//Motor A
const int motorPin1  = 5;  // Pin 14 of L293
const int motorPin2  = 6;  // Pin 10 of L293
//Motor B
const int motorPin3  = 10; // Pin  7 of L293
const int motorPin4  = 9;  // Pin  2 of L293

//This will run only one time.
void setup(){
 
    //Set pins as outputs
    pinMode(motorPin1, OUTPUT);
    pinMode(motorPin2, OUTPUT);
    pinMode(motorPin3, OUTPUT);
    pinMode(motorPin4, OUTPUT);
    
    //Motor Control - Motor A: motorPin1,motorpin2 & Motor B: motorpin3,motorpin4

    //This code  will turn Motor A clockwise for 2 sec.
    digitalWrite(motorPin1, HIGH);
    digitalWrite(motorPin2, LOW);
    digitalWrite(motorPin3, LOW);
    digitalWrite(motorPin4, LOW);
    delay(10000); 
    //This code will turn Motor A counter-clockwise for 2 sec.
    digitalWrite(motorPin1, LOW);
    digitalWrite(motorPin2, HIGH);
    digitalWrite(motorPin3, LOW);
    digitalWrite(motorPin4, LOW);
    delay(10000);
    
    //This code will turn Motor B clockwise for 2 sec.
    digitalWrite(motorPin1, LOW);
    digitalWrite(motorPin2, LOW);
    digitalWrite(motorPin3, HIGH);
    digitalWrite(motorPin4, LOW);
    delay(10000); 
    //This code will turn Motor B counter-clockwise for 2 sec.
    digitalWrite(motorPin1, LOW);
    digitalWrite(motorPin2, LOW);
    digitalWrite(motorPin3, LOW);
    digitalWrite(motorPin4, HIGH);
    delay(10000);    
    
    //And this code will stop motors
    digitalWrite(motorPin1, LOW);
    digitalWrite(motorPin2, LOW);
    digitalWrite(motorPin3, LOW);
    digitalWrite(motorPin4, LOW);
  
}


void loop(){
  

}

and this is the code for the two servos:

/*
#include <Servo.h>

Servo servoLeft;  //Define left servo
Servo servoRight;  //Define right servo

*/

void setup() {
  servoLeft.attach(2);  //Set left servo to pin 10
  servoRight.attach(3);  //Set right servo to pin 9
}

void loop (){
 for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
    // in steps of 1 degree
    servoLeft(pos);              // tell servo to go to position in variable 'pos'
    delay(5000);                       // waits 5ms for the servo to reach the position
    servoRight(pos);
    delay(5000)
    
  }
  for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
    servoLeft(pos);              // tell servo to go to position in variable 'pos'
    delay(1);                       // waits 5ms for the servo to reach the position
    servoRight(pos);
    delay(1)
    
  }
}

Any help would be appreciated. Thank you.

What happens when you swap the motors over?

Edit: read the Servo library reference page, second paragraph, carefully

Well the servo one doesn't even compile because you've commented out some vital parts and you never defined pos at all. And even if it did compile you do realise you have a 5 second delay between each 1 degree move of the servos don't you? So it's going to take about 15 minutes to get from 0 to 180?

Steve

When I switched the dc motors, the other dc motor worked, but the other one did not.

would defining the position mean putting

int pos = 0;

before void setup?

TolpuddleSartre:
read the Servo library reference page, second paragraph, carefully

jessabu:
When I switched the dc motors, the other dc motor worked, but the other one did not.

Proper and consistent use of agreed labels would help a lot here, like "left" and "right".

"Other" is too ambiguous.

The OP is not using PWM/analogWrite() and the motor driving sketch doesn't include the servo library anyway.

So could you perhaps be a little clearer about what we are expected to discover in the Servo ref, 2nd para, cus I can't see it either?

Steve

TolpuddleSartre:
Proper and consistent use of agreed labels would help a lot here, like "left" and "right".

Good point and since in the code they are called Motor A and Motor B I suggest those as useful descriptions for now.

So which one always works, Motor A (on pins 5 and 6) or Motor B (on pins 9 and 10)?

Steve

And this should be:
servoLeft.write(pos); // tell servo to go to position in variable 'pos'
servoRight.write(pos);

slipstick:
The OP is not using PWM/analogWrite() and the motor driving sketch doesn't include the servo library anyway.

So could you perhaps be a little clearer about what we are expected to discover in the Servo ref, 2nd para, cus I can't see it either?

Steve

I assumed that at some point, the OP is going to want to control the speed of the motors, and is going to hit a big wall of disappointment.

@TolpuddleSartre:
Good thinking, I would switch Motor B's pins with the servos' anyway.

"On boards other than the Mega, use of the library disables analogWrite() (PWM) functionality on pins 9 and 10, whether or not there is a Servo on those pins."

I didn't connect the servos to pins 9 and 10, is that the part of the paragraph you were talking about?

And motor A is the motor that works.

I didn't connect the servos to pins 9 and 10, is that the part of the paragraph you were talking about?

Yes, that's the right bit, however, there's this

//Motor B
const int motorPin3  = 10; // Pin  7 of L293
const int motorPin4  = 9;  // Pin  2 of L293

Please post the code you are using, not something that doesn't compile.

TolpuddleSartre:
I assumed that at some point, the OP is going to want to control the speed of the motors, and is going to hit a big wall of disappointment.

Ah right, so nothing to do with the current problems just anticipating possible future problems. Fair enough but for a minute there I thought I was missing something about the existing problem.

But that does raise another question because the PWM for motor speed control should normally be applied to the Enable pins of the L293D (pins 1 and 9) which aren't currently being used.

So jessabu, please confirm that you are actually using a bare L293D (not a motor driver board). And can you provide a circuit diagram showing all the L293D and motor connections, particularly where pins 1 and 9 on the L293D are connected?

BTW if Motor A works then the comments for the Motor pins are wrong. motorPin1 must be connected to pin 15 on the L293D. Pin 14 is one of the outputs to the motor. Which is also why an up to date circuit diagram is important.

Steve

//L293D
//Motor A
const int motorPin1  = 5;  // Pin 14 of L293
const int motorPin2  = 6;  // Pin 10 of L293
//Motor B
const int motorPin3  = 10; // Pin  7 of L293
const int motorPin4  = 9;  // Pin  2 of L293

//This will run only one time.
void setup(){
 
    //Set pins as outputs
    pinMode(motorPin1, OUTPUT);
    pinMode(motorPin2, OUTPUT);
    pinMode(motorPin3, OUTPUT);
    pinMode(motorPin4, OUTPUT);
    
    //Motor Control - Motor A: motorPin1,motorpin2 & Motor B: motorpin3,motorpin4

    //This code  will turn Motor A clockwise for 2 sec.
    digitalWrite(motorPin1, HIGH);
    digitalWrite(motorPin2, LOW);
    digitalWrite(motorPin3, LOW);
    digitalWrite(motorPin4, LOW);
    delay(10000); 
    //This code will turn Motor A counter-clockwise for 2 sec.
    digitalWrite(motorPin1, LOW);
    digitalWrite(motorPin2, HIGH);
    digitalWrite(motorPin3, LOW);
    digitalWrite(motorPin4, LOW);
    delay(10000);
    
    //This code will turn Motor B clockwise for 2 sec.
    digitalWrite(motorPin1, LOW);
    digitalWrite(motorPin2, LOW);
    digitalWrite(motorPin3, HIGH);
    digitalWrite(motorPin4, LOW);
    delay(10000); 
    //This code will turn Motor B counter-clockwise for 2 sec.
    digitalWrite(motorPin1, LOW);
    digitalWrite(motorPin2, LOW);
    digitalWrite(motorPin3, LOW);
    digitalWrite(motorPin4, HIGH);
    delay(10000);    
    
    //And this code will stop motors
    digitalWrite(motorPin1, LOW);
    digitalWrite(motorPin2, LOW);
    digitalWrite(motorPin3, LOW);
    digitalWrite(motorPin4, LOW);
  
}


void loop(){
  

}

that is the code that I am using for the DC motors, and yes, I am using a bare L293D chip, not a motor driver board.

I got the code and schematic from this tutorial: http://www.instructables.com/id/How-to-use-the-L293D-Motor-Driver-Arduino-Tutorial/

Check that the Enable pins on the L293 (1 and 9) are properly connected to 5V.

Since no battery is shown I assume it's powered by USB? It's a really bad idea running motors from the Arduino 5V pin, it can't deliver enough current. Take out the link to L293 pin8 and try it with a separate battery maybe 4 x AA cells +ve connected to pin 8 and -ve to Arduino ground.

And just to be certain...you're saying that either motor will run provided that it's connected to pins 5 and 6? The motor connected to 9 and 10 never works?

Steve

And just to be certain...you're saying that either motor will run provided that it's connected to pins 5 and 6? The motor connected to 9 and 10 never works?

yes, I am.

The wheels aren't powered by just USB, I connected a 9V battery to the power rails.

Use either one or another power source, not both!