L293D Motor Driver IC Documentation
The L293D is a dual H-bridge motor driver IC that enables the control of two DC motors simultaneously. It is a popular choice for robotic and IoT projects that require motor control. This documentation provides an overview of the L293D motor driver IC, its pinout, and code examples to demonstrate its usage in various contexts.
The L293D motor driver IC has 16 pins, which are divided into four sections:
Input Pins (1-4, 13-16): These pins are used to control the motor driver IC. Pins 1-4 are used to control Motor A, while pins 13-16 are used to control Motor B.
Enable Pins (1, 9): These pins are used to enable or disable the motor driver IC. A high signal on these pins enables the motor driver, while a low signal disables it.
Output Pins (5-8, 10-12): These pins are connected to the motor coils. Pins 5-8 are used for Motor A, while pins 10-12 are used for Motor B.
VCC and GND Pins (17, 16): These pins are used to power the motor driver IC. VCC is connected to a positive voltage source, while GND is connected to a negative voltage source.
### Example 1: Controlling a Single DC Motor using Arduino
In this example, we will demonstrate how to control a single DC motor using the L293D motor driver IC and an Arduino board.
Arduino Board (e.g., Arduino Uno)
L293D Motor Driver IC
DC Motor
Breadboard and Jumper Wires
Code
```c
const int motorPin1 = 2; // Pin 2 of Arduino connected to Pin 2 of L293D
const int motorPin2 = 3; // Pin 3 of Arduino connected to Pin 7 of L293D
const int enablePin = 4; // Pin 4 of Arduino connected to Pin 1 of L293D
void setup() {
pinMode(motorPin1, OUTPUT);
pinMode(motorPin2, OUTPUT);
pinMode(enablePin, OUTPUT);
}
void loop() {
// Set motor direction to clockwise
digitalWrite(motorPin1, HIGH);
digitalWrite(motorPin2, LOW);
// Enable the motor
digitalWrite(enablePin, HIGH);
// Delay for 2 seconds
delay(2000);
// Set motor direction to counterclockwise
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, HIGH);
// Enable the motor
digitalWrite(enablePin, HIGH);
// Delay for 2 seconds
delay(2000);
}
```
### Example 2: Controlling Two DC Motors using Raspberry Pi
In this example, we will demonstrate how to control two DC motors using the L293D motor driver IC and a Raspberry Pi.
Raspberry Pi (e.g., Raspberry Pi 3B+)
L293D Motor Driver IC
Two DC Motors
Breadboard and Jumper Wires
Code
```python
import RPi.GPIO as GPIO
# Set up GPIO mode
GPIO.setmode(GPIO.BCM)
# Set up motor pins
motor1_pin1 = 17
motor1_pin2 = 23
motor1_enable = 24
motor2_pin1 = 12
motor2_pin2 = 16
motor2_enable = 20
# Set up GPIO pins as outputs
GPIO.setup(motor1_pin1, GPIO.OUT)
GPIO.setup(motor1_pin2, GPIO.OUT)
GPIO.setup(motor1_enable, GPIO.OUT)
GPIO.setup(motor2_pin1, GPIO.OUT)
GPIO.setup(motor2_pin2, GPIO.OUT)
GPIO.setup(motor2_enable, GPIO.OUT)
try:
while True:
# Set motor 1 direction to clockwise
GPIO.output(motor1_pin1, GPIO.HIGH)
GPIO.output(motor1_pin2, GPIO.LOW)
# Enable motor 1
GPIO.output(motor1_enable, GPIO.HIGH)
# Set motor 2 direction to counterclockwise
GPIO.output(motor2_pin1, GPIO.LOW)
GPIO.output(motor2_pin2, GPIO.HIGH)
# Enable motor 2
GPIO.output(motor2_enable, GPIO.HIGH)
# Delay for 2 seconds
time.sleep(2)
# Set motor 1 direction to counterclockwise
GPIO.output(motor1_pin1, GPIO.LOW)
GPIO.output(motor1_pin2, GPIO.HIGH)
# Enable motor 1
GPIO.output(motor1_enable, GPIO.HIGH)
# Set motor 2 direction to clockwise
GPIO.output(motor2_pin1, GPIO.HIGH)
GPIO.output(motor2_pin2, GPIO.LOW)
# Enable motor 2
GPIO.output(motor2_enable, GPIO.HIGH)
# Delay for 2 seconds
time.sleep(2)
except KeyboardInterrupt:
# Clean up GPIO pins
GPIO.cleanup()
```
Note: In both examples, the motor driver IC is powered from a separate power source (e.g., a battery or a wall adapter). The VCC pin of the L293D motor driver IC should be connected to the positive terminal of the power source, and the GND pin should be connected to the negative terminal. Additionally, the motor coils should be connected to the output pins of the motor driver IC.