L293D 4 Channel DC Motor Driver Documentation
The L293D is a quadruple high-current half-H driver designed to provide bidirectional drive currents up to 1A at voltages from 4.5V to 36V. It is commonly used to control DC motors, solenoids, and other high-current devices in robotics, automation, and IoT applications. This documentation provides a comprehensive guide on how to use the L293D 4 Channel DC Motor Driver, including code examples for various contexts.
Pinout and Connection Diagram
The L293D has a total of 16 pins, with the following connections:
VCC (Pin 8): Power supply voltage (4.5V to 36V)
GND (Pin 4, 5, 12, and 13): Ground connections
EN1 and EN2 (Pins 1 and 9): Enable inputs for motor channels 1-2 and 3-4, respectively
IN1-IN4 (Pins 2, 7, 10, and 15): Input control signals for motor channels 1-4
OUT1-OUT4 (Pins 3, 6, 11, and 14): Output connections for motor channels 1-4
### Example 1: Basic DC Motor Control using Arduino
In this example, we will use the L293D to control a single DC motor using an Arduino Board. We will connect the motor to OUT1 and OUT2, and use the IN1 and IN2 inputs to control the motor's direction and speed.
```c++
const int EN1 = 2; // Enable input for motor channel 1
const int IN1 = 3; // Input control signal for motor channel 1
const int IN2 = 4; // Input control signal for motor channel 1
void setup() {
pinMode(EN1, OUTPUT);
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
}
void loop() {
// Set the enable input high to enable the motor
digitalWrite(EN1, HIGH);
// Set the motor to rotate clockwise
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
delay(1000);
// Set the motor to rotate counter-clockwise
digitalWrite(IN1, LOW);
digitalWrite(IN2, HIGH);
delay(1000);
// Stop the motor
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
delay(1000);
}
```
### Example 2: Controlling Multiple DC Motors using Raspberry Pi and Python
In this example, we will use the L293D to control two DC motors using a Raspberry Pi and Python. We will connect the motors to OUT1-OUT2 and OUT3-OUT4, and use the IN1-IN4 inputs to control the motors' direction and speed.
```python
import RPi.GPIO as GPIO
import time
# Set up GPIO mode
GPIO.setmode(GPIO.BCM)
# Define the GPIO pins for the L293D
EN1 = 17
IN1 = 23
IN2 = 24
EN2 = 27
IN3 = 22
IN4 = 25
# Set up GPIO pins as outputs
GPIO.setup(EN1, GPIO.OUT)
GPIO.setup(IN1, GPIO.OUT)
GPIO.setup(IN2, GPIO.OUT)
GPIO.setup(EN2, GPIO.OUT)
GPIO.setup(IN3, GPIO.OUT)
GPIO.setup(IN4, GPIO.OUT)
while True:
# Set motor 1 to rotate clockwise
GPIO.output(EN1, GPIO.HIGH)
GPIO.output(IN1, GPIO.HIGH)
GPIO.output(IN2, GPIO.LOW)
time.sleep(1)
# Set motor 1 to rotate counter-clockwise
GPIO.output(IN1, GPIO.LOW)
GPIO.output(IN2, GPIO.HIGH)
time.sleep(1)
# Stop motor 1
GPIO.output(IN1, GPIO.LOW)
GPIO.output(IN2, GPIO.LOW)
# Set motor 2 to rotate clockwise
GPIO.output(EN2, GPIO.HIGH)
GPIO.output(IN3, GPIO.HIGH)
GPIO.output(IN4, GPIO.LOW)
time.sleep(1)
# Set motor 2 to rotate counter-clockwise
GPIO.output(IN3, GPIO.LOW)
GPIO.output(IN4, GPIO.HIGH)
time.sleep(1)
# Stop motor 2
GPIO.output(IN3, GPIO.LOW)
GPIO.output(IN4, GPIO.LOW)
```
Note: The above code examples are for illustrative purposes only and may require modification to suit your specific application. Ensure you follow proper safety precautions and voltage ratings when working with the L293D and DC motors.