Arduino L293D Motor Driver Shield Tutorial (2024)

Introduction: Arduino L293D Motor Driver Shield Tutorial

More by the author:

About: Passionate about electronics parts and tutorials. We're your go-to source for high-quality components and expert guidance. Join us on our journey of exploration and innovation in the world of electronics. More About Electropeak »

You can read this and many other amazing tutorials on ElectroPeak's official website

Overview

In this tutorial, you will learn how to drive DC, stepper and servo motors using an Arduino L293D motor driver shield.

What You Will Learn:

  • General information about DC motors
  • Introduction to L293D motor shield
  • Driving DC, Servo & Stepper motors

Step 1: Motors & Drivers

Motors are an inseparable part of many robotics and electronics projects and have different types you can use depending on their application. Here is some information about different types of the motors:

DC Motors: DC motor is the most common type of engine that can be used for many applications. We can see it in remote control cars, robots, and etc. This motor has a simple structure. It will start rolling by applying proper voltage to its ends and change its direction by switching voltage polarity. DC motors speed is directly controlled by the applied voltage. When The voltage level is less than the maximum tolerable voltage, the speed would decrease.

Stepper Motors: In some projects such as 3D printers, scanners and CNC machines we need to know motor spin steps accurately. In these cases, we use Stepper motors. Stepper motor is an electric motor that divides a full rotation into a number of equal steps. The amount of rotation per step is determined by the motor structure. These motors have a very high accuracy.

Servo Motors: Servo motor is a simple DC motor with a position control service. By using a servo you will be able to control the amount of shafts rotation and move it to a specific position. They usually have a small dimension and are the best choice for robotic arms.

But we can’t connect these motors to microcontrollers or controller board such as Arduino directly in order to control them since they possibly need more current than a microcontroller can drive so we need drivers. The driver is an interface circuit between the motor and controlling unit to facilitate driving. Drives come in many different types. In this instruction, you learn to work on the L293D motor shield.

L293D shield is a driver board based on L293 IC, which can drive 4 DC motors and 2 stepper or Servo motors at the same time.

Each channel of this module has the maximum current of 1.2A and doesn’t work if the voltage is more than 25v or less than 4.5v. So be careful with choosing the proper motor according to its nominal voltage and current. For more features of this shield let’s mention compatibility with Arduini UNO and MEGA, electromagnetic and thermal protection of motor and disconnecting circuit in case of unconventional voltage raise.

Step 2: How to Use Arduino L293D Motor Driver Shield?

While using this shield 6 analog Pins (which can be used as digital pins too), pin 2 and pin 13 of arduino are free.

In the case of using Servo motor, pins 9, 10, 2 are in use.

In the case of using DC motor, pin11 for #1, pin3 for #2, pin5 for #3, pin6 for #4 and pins 4, 7, 8 and 12 for all of them are in use.

In the case of using Stepper motor, pins 11 and 3 for #1, pins 5 and 6 for #2 and pins 4, 7, 8 and 12 for all of them are in use.

You can use free pins by wired connections.

If you are applying separate power supply to Arduino and shield, make sure you have disconnected the jumper on the shield.

Step 3: Driving DC Motor

#include <AFMotor.h>

The Library you need to control the motor:

AF_DCMotor motor(1, MOTOR12_64KHZ)

Defining the DC motor you are using.

The first argument stands for the number of the motors in the shield and the second one stands for the motor speed control frequency. The second argument can be MOTOR12_2KHZ, MOTOR12_8KHZ, MOTOR12_8KHZ, and MOTOR12_8KHZ for motors number 1 and 2, and it can be MOTOR12_8KHZ, MOTOR12_8KHZ, and MOTOR12_8KHZ for motors number 3 and 4. And if it left unchecked, it will be 1KHZ by default.

motor.setSpeed(200);

Defining the motor speed. It can be set from 0 to 255.

void loop() {

motor.run(FORWARD);

delay(1000);

motor.run(BACKWARD);

delay(1000);

motor.run(RELEASE);

delay(1000);

}

Function motor.run() specifies the motor’s motion status. The status can be FORWARD, BACKWARD, and RELEASE. RELEASE is the same as the brake but it may take some time until the motor’s full stop.

It is recommended to solder a 100nF capacitor to each motor pins to reduce noise.

Step 4: Driving Servo Motor

Arduino IDE library and examples are suitable for driving a Servo motor.

#include <servo.h>

The library you need for driving the Servo motor

Servo myservo;

Defining a Servo motor object.

void setup()
{

myservo.attach(9);

}

Determine the pin connecting to Servo.(pin 9 for sevo #1 and pin 10 for servo #2)

void loop()
{

myservo.write(val);

delay(15);

}

Determine the amount of motor rotation. Between 0 to 360 or 0 to 180 according to motor type.

Step 5: Driving Stepper Motor

#include <AFMotor.h>

Determine the library you need

AF_Stepper motor(48, 2);

Defining a Stepper motor object. The first argument is the motor step resolution. (for example, if your motor has the precision of 7.5 deg/step, it means the motor step resolution is . The second argument is the number of the Stepper motor connected to the shield.

void setup() {
motor.setSpeed(10);

motor.onestep(FORWARD, SINGLE);

motor.release();

delay(1000);

}

void loop() {
motor.step(100, FORWARD, SINGLE);

motor.step(100, BACKWARD, SINGLE);

motor.step(100, FORWARD, DOUBLE);
motor.step(100, BACKWARD, DOUBLE);

motor.step(100, FORWARD, INTERLEAVE);
motor.step(100, BACKWARD, INTERLEAVE);

motor.step(100, FORWARD, MICROSTEP);
motor.step(100, BACKWARD, MICROSTEP);

}

Determine motor speed in rpm.

The first argument is the amount of step needed to move, the second one is to determine direction (FORWARD or BACKWARD), and the third argument determines the steps type: SINGLE (Activate a coil), DOUBLE (Activate two coils for more torque), INTERLEAVED (Continuous change in the number of coils from one to two and vice versa to double precision, however, in this case, the speed is halved), and MICROSTEP (Changing the steps is done slowly for more precision. In this case, the torque is lower).By default, when the motor stops moving, it maintains its status.

You must use the function motor.release() to release the motor.

Step 6: Buy Arduino L293D Motor Driver Shield

Step 7: Related Projects:

Step 8: Like Us on FaceBook

If you find this tutorial helpful and interesting please like us on facebook.

Arduino L293D Motor Driver Shield Tutorial (2024)
Top Articles
MDMA und 2C-B! Ein Nexusflip, den ich nie vergessen werde. -
The 10 Best Shows With Multiple Timelines, Ranked
No Limit Telegram Channel
Pinellas County Jail Mugshots 2023
Rabbits Foot Osrs
Naturalization Ceremonies Can I Pick Up Citizenship Certificate Before Ceremony
Mustangps.instructure
Compare the Samsung Galaxy S24 - 256GB - Cobalt Violet vs Apple iPhone 16 Pro - 128GB - Desert Titanium | AT&T
Infinite Campus Parent Portal Hall County
Luciipurrrr_
Cape Cod | P Town beach
123Moviescloud
Pro Groom Prices – The Pet Centre
Superhot Unblocked Games
Fredericksburg Free Lance Star Obituaries
Mills and Main Street Tour
Https://Store-Kronos.kohls.com/Wfc
Traveling Merchants Tack Diablo 4
Ruse For Crashing Family Reunions Crossword
Milanka Kudel Telegram
Hewn New Bedford
Quick Answer: When Is The Zellwood Corn Festival - BikeHike
Between Friends Comic Strip Today
Understanding Gestalt Principles: Definition and Examples
Cookie Clicker Advanced Method Unblocked
Drift Hunters - Play Unblocked Game Online
Prey For The Devil Showtimes Near Ontario Luxe Reel Theatre
2487872771
Strange World Showtimes Near Savoy 16
Labcorp.leavepro.com
Gunsmoke Tv Series Wiki
10-Day Weather Forecast for Santa Cruz, CA - The Weather Channel | weather.com
Jamielizzz Leaked
Mississippi Craigslist
Evil Dead Rise Showtimes Near Regal Sawgrass & Imax
'Conan Exiles' 3.0 Guide: How To Unlock Spells And Sorcery
Rise Meadville Reviews
Vip Lounge Odu
Robeson County Mugshots 2022
Collier Urgent Care Park Shore
Bianca Belair: Age, Husband, Height & More To Know
Atlanta Musicians Craigslist
Rhode Island High School Sports News & Headlines| Providence Journal
Riverton Wyoming Craigslist
About My Father Showtimes Near Amc Rockford 16
Arnesons Webcam
Juiced Banned Ad
Walmart 24 Hrs Pharmacy
Air Sculpt Houston
Nearest Wintrust Bank
Leland Westerlund
Autozone Battery Hold Down
Latest Posts
Article information

Author: Mr. See Jast

Last Updated:

Views: 6452

Rating: 4.4 / 5 (75 voted)

Reviews: 90% of readers found this page helpful

Author information

Name: Mr. See Jast

Birthday: 1999-07-30

Address: 8409 Megan Mountain, New Mathew, MT 44997-8193

Phone: +5023589614038

Job: Chief Executive

Hobby: Leather crafting, Flag Football, Candle making, Flying, Poi, Gunsmithing, Swimming

Introduction: My name is Mr. See Jast, I am a open, jolly, gorgeous, courageous, inexpensive, friendly, homely person who loves writing and wants to share my knowledge and understanding with you.