Go Down

Topic: only one dc motor spins (Read 855 times) previous topic - next topic

jessabu

#15
Apr 10, 2018, 04:18 am Last Edit: Apr 10, 2018, 04:31 am by jessabu
Code: [Select]

//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.

jessabu

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

slipstick

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

jessabu

Quote
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.

Johan_Ha

Use either one or another power source, not both!
____________________

If you ask for help and write 'u' instead of 'you' because you think it's convenient, I will write 'no' instead of 'yes'. For same reasons.

slipstick

The wheels aren't powered by just USB, I connected a 9V battery to the power rails.
O.k. so what you mean is that the schematic you said you had followed isn't what you have at all. So it was a waste of time looking at that. You're not exactly making it easy to help you. Are you actually even using a UNO?

Let's have an accurate diagram of how everything is connected with emphasis on all power/battery connections.

BTW if the 9V battery is one of those small PP3 types then it really won't help. They can't deliver enough current to run motors.

Steve

jessabu

I'm sorry for the miscommunication. I meant that I power the motors ONLY by using a 9V battery. I just used an alkaline battery to see how they would work while not being connected to the computer via USB. I posted another forum message about how to power all four motors, and they said that I should use four rechargeable batteries.

But anyway, I did find another code for the wheels that is working fine, so the servos are remaining.

And I apologize again for the misunderstanding with the schematic. That schematic from the link was what I was using before (without the power connections) before I found another code to use.

And yes, I am using an Arduino UNO.

jessabu

How can I fix the servo code?

Johan_Ha

Right now you could post again what you have. Your code and your circuit. What it does and what it should do.
____________________

If you ask for help and write 'u' instead of 'you' because you think it's convenient, I will write 'no' instead of 'yes'. For same reasons.

Evans_Picolo

Well, it says in the first code comments that each motor should run for 2 seconds. However, you use a 10000 delay, wich makes each motor run for 10 seconds.

Since the delay freezes the program, nothing should happen during this 10 seconds in excepton of the first motor run.

Did you take this into consideration in your tests?
Think simple, talk simple, act simple... Make it simple!

TomGeorge

Hi,
OPs servo code;


Code: [Select]
/*
#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)
    
  }
}



Code: [Select]
delay(5000);                       // waits 5ms for the servo to reach the position
Does not wait for 5ms,it waits for 5000ms, or 5s, while it waits, NOTHING is done, the program STOPs.

try

Code: [Select]
delay(100);

How are you powering the servos.
Can you please post a copy of your servo circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
Thanks.. Tom... :)
Everything runs on smoke, let the smoke out, it stops running....

slipstick

In message #2 a couple of weeks ago I pointed that out including the fact that it won't compile if pos is never defined and won't do anything useful with the Servo.h include and servo definitions commented out. Which is why several of us have asked for the latest code and a circuit diagram.

But the OP rarely bothers answering any questions so I've lost interest.

Steve


Johan_Ha

This thread barely has anything of value. It might as well be deleted. If the OP ever needs to continue it, he could start a new thread.
____________________

If you ask for help and write 'u' instead of 'you' because you think it's convenient, I will write 'no' instead of 'yes'. For same reasons.

Go Up