Arduino Code and video L293D and DC Motor Controller (witout speed control)

Project Video
Project Details

Using L293 and L293D DC motor driver you can control two motors with controlling direction of rotation.
This code is NOT for Stepper Motor control. it is just for DC motor control.
Code to contorl speed of DC motor using L293D Is here
Code for L293D Motor shield to control 4 DC motors Is here

Project Code


/*


 * This is the Arduino code L293 DC motor Driver (Advanced)
Using this code you can control a motor to rotate in both direction Clockwise(CW) 
and Counter-clockwise(CCW)

 *  * 
 // Writeen by Ahmad S. for Robojax.com on 
// on Feb 25, 2018 at 18:30 at city of Ajax, Ontario, Canada
 * Permission granted to share this code given that this
 * note is kept with the code.
 * Disclaimer: this code is "AS IS" and for educational purpose only.
 * 

 * watch L293 video for details https://youtu.be/jAmDliHcTJ0
 * Code is available at http://robojax.com/learn/arduino

 * 

*/
// DC motor 1 control
#define P1A 2 // define pin 2 as for P1A
#define P2A 7 // define pin 7 as for P2A
#define EN12 8 // define pin 8 as for 1,2EN enable



// DC motor 2 control 
#define P3A 10 // define pin 10 as for P3A
#define P4A 13 // define pin 13 as for P4A
#define EN34 9 // define pin 9 as for EN3 and EN4 enable

/*
 * Permission granted to share this code given that this
 * note is kept with the code.
 * Disclaimer: this code is "AS IS" and for educational purpose only.
 * 
 */

void setup() {
  // L293 Motor Control Code by Robojax.com 2018025
  Serial.begin(9600);// setup Serial Monitor to display information
  pinMode(P1A, OUTPUT);// define pin as OUTPUT for P1A
  pinMode(P2A, OUTPUT);// define pin as OUTPUT for P2A
  pinMode(EN12, OUTPUT);// define pin as OUTPUT for 1,2EN
   
  pinMode(P3A, OUTPUT);// define pin as OUTPUT for P3A
  pinMode(P4A, OUTPUT);// define pin as OUTPUT for P4A
  pinMode(EN34, OUTPUT);// define pin as OUTPUT for 3,4EN   
  // L293 Motor Control Code by Robojax.com 2018025   
}

void loop() {
  // L293 Motor Control Code by Robojax.com 2018025


    Serial.println(" Rotating CW");
    digitalWrite(EN12 ,HIGH);// Enable 1A and 2A 
    digitalWrite(P1A,HIGH);// send + or HIGH singal to P1A
    digitalWrite(P2A,LOW);// send - or LOW singal to P2A       
    delay(3000);// motor runs for 3 seconds
    digitalWrite(EN12 ,LOW);// Disable 1A and 2A
    delay(2000);// motor stop for 3 seconds 
    Serial.println(" Motor Stopped"); 

  // L293 Motor Control Code by Robojax.com 2018025
    // now changing the direction of rotation of motor
    Serial.println(" Rotating CCW");
    digitalWrite(EN12 ,HIGH);// Enable 1A and 2A     
    digitalWrite(P1A,LOW);// send + or HIGH singal to P1A
    digitalWrite(P2A,HIGH);// send - or LOW singal to P2A  
    delay(3000);// motor runs for 3 seconds
    digitalWrite(EN12 ,LOW);// Disable 1A and 2A
    delay(2000);// motor stop for 3 seconds    
    Serial.println(" Motor Stopped");   
     

  Serial.println("=========== Loop done"); 
  delay(500);
  // L293 Motor Control Code by Robojax.com 2018025 
}

Required File(s)