The L293D Motor Driver is an essential component for robotics and automation projects. It is designed to drive inductive loads such as relays, solenoids, DC, and stepping motors by allowing current to flow in both directions. This integrated circuit can control two DC motors simultaneously, making it a popular choice for dual-motor applications.
Pin Number | Name | Description |
---|---|---|
1 | 1,2EN | Enable pin for Motor 1 and 2; active high |
2 | 1A | Input 1 for Motor 1 |
3 | 1Y | Output 1 for Motor 1 |
4 | GND | Ground |
5 | GND | Ground |
6 | 2Y | Output 2 for Motor 1 |
7 | 2A | Input 2 for Motor 1 |
8 | Vcc2 | Motor supply voltage |
9 | 3,4EN | Enable pin for Motor 2; active high |
10 | 3A | Input 1 for Motor 2 |
11 | 3Y | Output 1 for Motor 2 |
12 | GND | Ground |
13 | GND | Ground |
14 | 4Y | Output 2 for Motor 2 |
15 | 4A | Input 2 for Motor 2 |
16 | Vcc1 | Logic supply voltage |
#include <Arduino.h>
// Define motor control pins
const int motor1Pin1 = 2; // Input 1 for Motor 1
const int motor1Pin2 = 3; // Input 2 for Motor 1
const int enableMotor1 = 9; // Enable pin for Motor 1
void setup() {
// Set motor control pins as outputs
pinMode(motor1Pin1, OUTPUT);
pinMode(motor1Pin2, OUTPUT);
pinMode(enableMotor1, OUTPUT);
// Enable the motor
digitalWrite(enableMotor1, HIGH);
}
void loop() {
// Spin motor in one direction
digitalWrite(motor1Pin1, HIGH);
digitalWrite(motor1Pin2, LOW);
delay(2000); // Run for 2 seconds
// Stop the motor
digitalWrite(motor1Pin1, LOW);
digitalWrite(motor1Pin2, LOW);
delay(1000); // Stop for 1 second
// Spin motor in the opposite direction
digitalWrite(motor1Pin1, LOW);
digitalWrite(motor1Pin2, HIGH);
delay(2000); // Run for 2 seconds
// Stop the motor
digitalWrite(motor1Pin1, LOW);
digitalWrite(motor1Pin2, LOW);
delay(1000); // Stop for 1 second
}
Q: Can the L293D drive stepper motors? A: Yes, the L293D can drive a bipolar stepper motor by controlling the current in each coil in a sequence.
Q: What is the function of the enable pins? A: The enable pins turn the motor driver channels on or off. When high, the corresponding motor channel is active.
Q: Can I use the L293D with a 3.3V logic level microcontroller? A: While the L293D is designed for 5V logic levels, it may work with 3.3V logic; however, performance is not guaranteed. Consider using a level shifter for reliable operation.