Introduction to L293D Motor Driver
The L293D is a popular motor driver IC that allows you to control the speed and direction of two DC motors simultaneously. It is widely used in robotics, automation, and other applications that require precise motor control. In this article, we will explore how to connect the L293D motor driver to a DC motor using an Arduino board.
What is an L293D Motor Driver?
The L293D is a 16-pin motor driver IC that can control two DC motors independently. It is designed to provide bidirectional drive currents of up to 600mA at voltages from 4.5V to 36V. The L293D is capable of driving inductive loads such as relays, solenoids, DC motors, and stepping motors, as well as other high-current/high-voltage loads.
Features of L293D Motor Driver
The L293D motor driver offers several key features that make it a popular choice for motor control applications:
- Dual H-Bridge Motor Driver: The L293D contains two H-bridge driver circuits, allowing it to control two DC motors independently.
- Wide Voltage Range: It can operate with a supply voltage range of 4.5V to 36V, making it suitable for various motor types and sizes.
- High Current Capability: Each driver circuit can provide a peak current of 1.2A and a continuous current of 600mA.
- TTL and CMOS Compatible Inputs: The input logic levels are compatible with standard TTL (Transistor-Transistor Logic) and CMOS (Complementary Metal-Oxide-Semiconductor) levels.
- Internal Clamp Diodes: The L293D includes internal clamp diodes to protect against voltage spikes generated by inductive loads.
- Thermal Shutdown Protection: It has a built-in thermal shutdown feature that protects the IC from damage due to excessive heat.
Connecting L293D Motor Driver to Arduino and DC Motor
Now that we have a basic understanding of the L293D motor driver, let’s dive into the process of connecting it to an Arduino board and a DC motor.
Required Components
To get started, you will need the following components:
- L293D Motor Driver IC
- Arduino Board (e.g., Arduino Uno)
- DC Motor
- Breadboard
- Jumper Wires
- External Power Supply (optional, depending on motor requirements)
L293D Pinout
Before we proceed with the connections, let’s take a look at the pinout of the L293D motor driver IC:
Pin Number | Pin Name | Description |
---|---|---|
1 | Enable 1 | Enable pin for Motor 1 |
2 | Input 1 | Input 1 for Motor 1 |
3 | Output 1 | Output 1 for Motor 1 |
4 | GND | Ground |
5 | GND | Ground |
6 | Output 2 | Output 2 for Motor 1 |
7 | Input 2 | Input 2 for Motor 1 |
8 | VCC2 | Supply voltage for motors (4.5V to 36V) |
9 | Enable 2 | Enable pin for Motor 2 |
10 | Input 3 | Input 3 for Motor 2 |
11 | Output 3 | Output 3 for Motor 2 |
12 | GND | Ground |
13 | GND | Ground |
14 | Output 4 | Output 4 for Motor 2 |
15 | Input 4 | Input 4 for Motor 2 |
16 | VCC1 | Supply voltage for the logic circuit (5V) |
Step-by-Step Connection Guide
Follow these steps to connect the L293D motor driver to your Arduino board and DC motor:
- Connect the L293D motor driver IC to the breadboard.
- Connect the Arduino board to the breadboard.
- Connect the VCC1 pin of the L293D to the 5V pin of the Arduino board. This provides power to the logic circuit of the L293D.
- Connect the VCC2 pin of the L293D to an external power supply or the Vin pin of the Arduino board, depending on the voltage requirements of your DC motor. This provides power to the motors.
- Connect the GND pins of the L293D to the GND pin of the Arduino board and the external power supply (if used).
- Connect the Input pins of the L293D (Input 1, Input 2, Input 3, Input 4) to the digital output pins of the Arduino board. These pins will be used to control the direction and speed of the motors.
- Connect the Output pins of the L293D (Output 1, Output 2, Output 3, Output 4) to the terminals of the DC motor. Make sure to match the polarity of the motor connections.
- Connect the Enable pins of the L293D (Enable 1, Enable 2) to the PWM (Pulse Width Modulation) pins of the Arduino board. These pins will be used to control the speed of the motors.
Here’s a simplified connection diagram for reference:
Arduino Board
+-----+
| |
| PWM |---> Enable 1 (L293D)
| |---> Input 1 (L293D)
| |---> Input 2 (L293D)
| |---> Enable 2 (L293D)
| |---> Input 3 (L293D)
| |---> Input 4 (L293D)
| |
| 5V |---> VCC1 (L293D)
| |
| GND |---> GND (L293D)
+-----+
|
| L293D Motor Driver
| +-----+
+---->| VCC1|
| | |
+---->| GND |
| | |
External | | VCC2|---> DC Motor Power Supply
Power Supply| | |
+---->| GND |
| |
| M1 |---> Output 1 ---> DC Motor Terminal 1
| M2 |---> Output 2 ---> DC Motor Terminal 2
| M3 |---> Output 3 ---> DC Motor Terminal 3
| M4 |---> Output 4 ---> DC Motor Terminal 4
+-----+
Arduino Code for Controlling DC Motor with L293D
Now that the hardware connections are established, let’s dive into the Arduino code to control the DC motor using the L293D motor driver.
// L293D Motor Driver Pins
const int enable1Pin = 11; // Enable 1 pin
const int input1Pin = 10; // Input 1 pin
const int input2Pin = 9; // Input 2 pin
void setup() {
// Set motor driver pins as output
pinMode(enable1Pin, OUTPUT);
pinMode(input1Pin, OUTPUT);
pinMode(input2Pin, OUTPUT);
}
void loop() {
// Set motor direction (clockwise)
digitalWrite(input1Pin, HIGH);
digitalWrite(input2Pin, LOW);
// Set motor speed (0-255)
analogWrite(enable1Pin, 200);
// Wait for 2 seconds
delay(2000);
// Stop the motor
digitalWrite(input1Pin, LOW);
digitalWrite(input2Pin, LOW);
// Wait for 1 second
delay(1000);
// Set motor direction (counterclockwise)
digitalWrite(input1Pin, LOW);
digitalWrite(input2Pin, HIGH);
// Set motor speed (0-255)
analogWrite(enable1Pin, 150);
// Wait for 2 seconds
delay(2000);
// Stop the motor
digitalWrite(input1Pin, LOW);
digitalWrite(input2Pin, LOW);
// Wait for 1 second
delay(1000);
}
In this code:
– We define the pin numbers for the Enable 1, Input 1, and Input 2 pins of the L293D motor driver.
– In the setup()
function, we set the motor driver pins as output pins using pinMode()
.
– In the loop()
function, we control the direction and speed of the motor.
– To set the motor direction, we use digitalWrite()
to set the Input 1 and Input 2 pins to HIGH or LOW. Setting Input 1 to HIGH and Input 2 to LOW will make the motor rotate clockwise, while setting Input 1 to LOW and Input 2 to HIGH will make it rotate counterclockwise.
– To set the motor speed, we use analogWrite()
on the Enable 1 pin. The speed value can range from 0 to 255, where 0 represents no rotation and 255 represents full speed.
– We introduce delays using delay()
to allow the motor to rotate for a specific duration before changing its direction or stopping.
Upload this code to your Arduino board, and you should see the DC motor rotating clockwise for 2 seconds, stopping for 1 second, then rotating counterclockwise for 2 seconds, and repeating the cycle.
Controlling Multiple DC Motors with L293D
The L293D motor driver has the capability to control two DC motors independently. To control multiple motors, you can follow a similar connection process as described earlier, but using the second set of input and output pins (Input 3, Input 4, Output 3, Output 4) for the second motor.
Here’s an example Arduino code snippet for controlling two DC motors with the L293D:
// L293D Motor Driver Pins
const int enable1Pin = 11; // Enable 1 pin for Motor 1
const int input1Pin = 10; // Input 1 pin for Motor 1
const int input2Pin = 9; // Input 2 pin for Motor 1
const int enable2Pin = 6; // Enable 2 pin for Motor 2
const int input3Pin = 5; // Input 3 pin for Motor 2
const int input4Pin = 4; // Input 4 pin for Motor 2
void setup() {
// Set motor driver pins as output
pinMode(enable1Pin, OUTPUT);
pinMode(input1Pin, OUTPUT);
pinMode(input2Pin, OUTPUT);
pinMode(enable2Pin, OUTPUT);
pinMode(input3Pin, OUTPUT);
pinMode(input4Pin, OUTPUT);
}
void loop() {
// Control Motor 1
digitalWrite(input1Pin, HIGH);
digitalWrite(input2Pin, LOW);
analogWrite(enable1Pin, 200);
// Control Motor 2
digitalWrite(input3Pin, LOW);
digitalWrite(input4Pin, HIGH);
analogWrite(enable2Pin, 150);
// Wait for 2 seconds
delay(2000);
// Stop both motors
digitalWrite(input1Pin, LOW);
digitalWrite(input2Pin, LOW);
digitalWrite(input3Pin, LOW);
digitalWrite(input4Pin, LOW);
// Wait for 1 second
delay(1000);
}
In this code, we define the pin numbers for both motors and control them independently using the corresponding input and enable pins. You can adjust the speed and direction of each motor by modifying the analogWrite()
and digitalWrite()
values accordingly.

FAQ
-
Q: Can I power the DC motors directly from the Arduino board?
A: It depends on the current requirements of your DC motors. The Arduino board has a limited current supply capability. If your motors require more current than the Arduino can provide, it is recommended to use an external power supply to power the motors through the VCC2 pin of the L293D motor driver. -
Q: What is the maximum voltage that the L293D motor driver can handle?
A: The L293D motor driver can operate with a supply voltage range of 4.5V to 36V. However, make sure to check the specifications of your specific DC motors and ensure that the voltage applied to the motors does not exceed their rated voltage. -
Q: Can I control the speed of the DC motors using the L293D motor driver?
A: Yes, you can control the speed of the DC motors by using PWM (Pulse Width Modulation) on the Enable pins of the L293D. By varying the PWM duty cycle, you can adjust the average voltage supplied to the motors, thereby controlling their speed. -
Q: How much current can the L293D motor driver provide to the motors?
A: The L293D motor driver can provide a maximum continuous current of 600mA per channel. It can also handle peak currents of up to 1.2A per channel for a short duration. Make sure that the current requirements of your DC motors do not exceed these limits. -
Q: Can I use the L293D motor driver with other microcontrollers besides Arduino?
A: Yes, the L293D motor driver can be used with various microcontrollers and development boards that provide compatible digital output pins. The connection process and code implementation may vary depending on the specific microcontroller or programming language used.
Conclusion
In this article, we explored how to connect the L293D motor driver to an Arduino board and control DC motors. We covered the basics of the L293D, its pinout, and the step-by-step connection process. We also provided example Arduino code snippets to demonstrate how to control the direction and speed of DC motors using the L293D.
By following the guidelines and code examples provided, you should be able to successfully integrate the L293D motor driver into your Arduino projects and achieve precise control over DC motors. Remember to consider the current and voltage requirements of your motors and use appropriate power supplies when necessary.
The L293D motor driver is a versatile and widely used component in robotics and automation projects. With its ability to control two DC motors independently, it offers great flexibility and simplifies the process of motor control.
Happy motoring with the L293D and Arduino!
No responses yet