Back to Arduino Step By Step Course

Lesson 95: Using L293D 4 DC Motors Shield | Arduino Step By Step Course

If you don't like to see ads while video is being played you can purchase this course for $200 from Udemy or purchase YouTube premium Here

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

    In this lesson we learn how to use L293D Motor Shield to control 4 DC motors. We learn to control the speed of eah motor, changed the direction and start or stop them. Wiring diagram shown, Code is fully explained and demonstrated using Arduino UNO and Arduino MEGA. this code is for single sensor.

    Amazon USA:

    Amazon Canada

    * Lesson 95: Control 4 DC Motor for Smart car using Motor Shield 
    * this code works with Arduino UNO and Arduino Mega. 
    * Wiring diagram and how to wire and connect power supply is shonw in the video.
      Watch full video instruction:
     * Download this code from:
    * Written by Ahmad Shamshiri for on Jan 09, 2022
     * in Ajax, Ontario, Canada
    This video is part of Arduino Step by Step Course which starts here:
    If you found this tutorial helpful, please support me so I can continue creating contents like this
    and make donation using PayPal
     * This code is "AS IS" without warranty or liability. Free to be used as long as you keep this note intact.* 
     * This code has been download from
        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
        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 <>. 
     *  Library location:
     Adafruit Motor shield library
    // copyright Adafruit Industries LLC, 2009
    // this code is public domain, enjoy!
    #include <AFMotor.h>
    AF_DCMotor motor1(1);
    AF_DCMotor motor2(2);
    AF_DCMotor motor3(3);
    AF_DCMotor motor4(4);
    void setup() {
      Serial.begin(9600); // set up Serial library at 9600 bps
      Serial.println("Robojax L293D Example");
    void loop() {
      motor1.setSpeed( speed(50) ); //set speed for motor 1 at 50%;//send motor 1 to Foarward rotation
      delay(2000);//wait for 2 seconds
      motor2.setSpeed( speed(100) );//set speed for motor 2 at 100%;//send motor 2 to Foarward rotation
      motor3.setSpeed( speed(70) );;
      motor4.setSpeed( speed(90) );;
     * speed percent to speed converter
     * receives value between 0 to 100 and converts it to value between
     * 0 to 255 which are 8 bits Arduino PWM value
     Watch full video instruction:
    int  speed(int percent)
      return map(percent, 0, 100, 0, 255);

    The least I expect from you is to thumb up the video and subscribe to my channel. I appriciate that. .I have spent months making these lectures and writing code. You don't lose anything by subscribging to my channel. Your subscription is stamp of approval to my videos and more people can find them and in it turn it helps 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 and affiliated sites.