Back to Step by Step Course by Robojax

Lesson 49: Using L293D with Arduino to control drive a DC Motor

  • L293D Motor Driver Datasheet (pdf)
  • Part 5: DC Motors

    In this lesson we learn how to use L293D Motor driver to drive a DC motor using Arduino code. Please watch the video for full details.

    • Introduction to L293D chip
    • Wiring of L293D Explained
    • Code Explained
    • Running code demonstration
    AliExpress.com Product - 5pcs/lot L293D L293 DIP-16 In Stock
    
     /*
    * Lesson 49: Introduction to L293D Motor driver | Arduino Step By Step Course
    
     * This is the Arduino code L293 DC motor Driver 
    Using this code you can control a motor to rotate in one direction
    
    Watch the video explaining L293D and this code:https://youtu.be/D4yLsWvZDw4
    
     *  * 
     // Writeen by Ahmad Shamshiri for Robojax Robojax.com on 
    // on Jan 26, 2019 at 08:01 in Ajax, Ontario, Canada
    
    This code is available at http://robojax.com/course1/?vid=lecture49
     
    with over 100 lectures Free On  YouTube Watch it here http://robojax.com/L/?id=338
    Get the code for the course: http://robojax.com/L/?id=339  
     * on Saturday November 24, 2018 
     * in Ajax, Ontario, Canada
     * 
     
     * This code is "AS IS" without warranty or liability. Free to be used as long as you keep this note intact.* 
     * This program is free software: you can redistribute it and/or modify
        it under the terms of the GNU General Public License as published by
        the Free Software Foundation, either version 3 of the License, or
        (at your option) any later version.
    
        This program is distributed in the hope that it will be useful,
        but WITHOUT ANY WARRANTY; without even the implied warranty of
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        GNU General Public License for more details.
    
        You should have received a copy of the GNU General Public License
        along with this program.  If not, see <https://www.gnu.org/licenses/>.
    
    */
    
    #define MOTOR1 2 // define pin 2 as for MOTOR1
    #define EN12 3// define pin 3 for EN1,2 
    
    /*
     * 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(MOTOR1, OUTPUT);// define pin as OUTPUT for MOTOR1
      pinMode(EN12, OUTPUT);// define pin as OUTPUT for EN12
      //digitalWrite(EN12, HIGH);// set EN12 pin HIGH
      
      // L293 Motor Control Code by Robojax.com 2018025   
    }
    
    void loop() {
      // L293 Motor Control Code by Robojax.com 2018025
    
    
        Serial.println(" Motor 1 ON");
        digitalWrite(MOTOR1,HIGH);// turn MOTOR1 ON
        
        analogWrite(EN12, 255);// run motor at (255 PWM value) maximum speed 
        delay(3000);//for 3 seconds
    
        analogWrite(EN12, 127);// run motor at half (125 PWM value) speed
        delay(5000);//for 3 seconds
    
        analogWrite(EN12, 95);// run motor at 80 PWM value
        delay(5000);//for 3 seconds
        
        digitalWrite(MOTOR1,LOW);// turn MOTOR1 OFF    
        Serial.println(" Motor 1 Stopped"); 
        delay(3000);// wait for 3 seconds
    
    
      // L293 Motor Control Code by Robojax.com 2018025 
    }
    
    
       

    The least I expect from you is to give the video a thumbs up and subscribe to my channel. I appreciate it. I have spent hundreds of hours making these lectures and writing code. You don't lose anything by subscribing to my channel. Your subscription is a stamp of approval for my videos, helping more people find them and, in turn, helping me. Thank you!

    If you found this tutorial helpful, please support me so I can continue creating content like this. support me via PayPal

    **** AFFILIATE PROGRAM **** We are a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for us to earn fees by linking to Amazon.com and affiliated sites.

    Right Side
    footer