L293d Dual Motor Control

Qns: I am doing a project ( Line follower-robot) , What do I need to change in order to make the two motors turn in same direction at the same time?

Test code with Arduino
As a simple test, you can make the motors turn forward and backward alternatively with this code:

void setup() {
// initialize the digital pins as outputs.
// Pin 13 has a LED connected on most Arduino boards:
pinMode(13, OUTPUT);
pinMode(7, OUTPUT);//Motor connected on pin 7 en 8, these are PWM capable
pinMode(8, OUTPUT);
}

void loop() {
digitalWrite(7, HIGH); //start motor at full speed
digitalWrite(8, LOW);
digitalWrite(13, HIGH); //turn on LED
delay(5000);//wait

digitalWrite(7, LOW); //stop motor
digitalWrite(8, LOW);
delay(1000); //wait a second to be sure motor is stopped

digitalWrite(7, LOW); //start motor in reverse direction, full speed
digitalWrite(8, HIGH);
digitalWrite(13, LOW); //turn off led
delay(5000);//wacht

digitalWrite(7, LOW); //stop motor
digitalWrite(8, LOW);
delay(1000); //wait a second to be sure motor is stopped
}
Speed control
Just like with the LED in the first session, the analogWrite() command can be used to set a speed for the
motor:

void setup() {
// initialize the digital pins as outputs.
// Pin 13 has an LED connected on most Arduino boards:
pinMode(13, OUTPUT);
pinMode(5, OUTPUT);//Motor aangesloten op pin 7 en 8, deze zijn PWM capable
pinMode(6, OUTPUT);

digitalWrite(6, LOW);
}

void loop() {
analogWrite(5, 128);
digitalWrite(13, LOW);//Show speed on LED

delay(4000); //wait a bit

analogWrite(5, 255);
digitalWrite(13, HIGH);//Show speed on LED

delay(4000);
}

  1. You need to post your code between [ code] [ /code] tags. Use the # button above the smileys.
  2. You can only have one setup() and one loop() in any program.
  3. You need to get rid of your delay()s. See the 'blink without delay' example in the IDE (File > Examples > 02.digital > blinkwithoutdelay). Your Arduino can't do anything else when it's in a delay.
  4. Look up 'Finite State Machine' for how to order your code, so that it follows a logical, easy to understand, sequence.

For simple testing, but probably not for real life with all those delays as already pointed out, you can simply duplicate the code for another motor. Probably best to use variable names for the pins, easier to keep track of.

Btw on a Uno pins 7 and 8 are not PWM as your comment says: but then you didn't say what board you have.

Anyway, where you have this:

pinMode(5, OUTPUT);//Motor aangesloten op pin 7 en 8, deze zijn PWM capable 
 pinMode(6, OUTPUT);

.... you could add another motor on say pins 10 and 11:

pinMode(5, OUTPUT);//Motor aangesloten op pin 7 en 8, deze zijn PWM capable 
 pinMode(6, OUTPUT); 
 pinMode(10, OUTPUT);//Motor aangesloten op pin 7 en 8, deze zijn PWM capable 
 pinMode(11, OUTPUT);

Connect pins 10 and 11 to the unused input pins on the L293 (we don't know which ones you used: you should post a schematic), and the second motor on the unused output pins (we don't know which ones you used: you should post a schematic).

Then lines like this for an existing motor:

analogWrite(5, 128);

.... become like this for the new one:

analogWrite(10, 128);

http://people.mech.kuleuven.be/~dvanthienen/soiree_pratique/HackerManual.pdf

Here' the link for the circuit diagram. Please take a look.

Chinhao:
http://people.mech.kuleuven.be/~dvanthienen/soiree_pratique/HackerManual.pdf

Here' the link for the circuit diagram. Please take a look.

I'm just leaving home for work.... will try to get a gap later.

Chinhao:
http://people.mech.kuleuven.be/~dvanthienen/soiree_pratique/HackerManual.pdf

Here' the link for the circuit diagram. Please take a look.

Apply your mind; have a look at the photo in that pdf.... One motor has pink wires from Arduino, one has blue. So trace back to the pin numbers on Arduino, and adjust / add code as appropriate. Hint: kind of double-up the code but on a new set of pins.