The DRIVER SHIELD L293D is a motor driver shield designed for use with the Arduino platform. This shield allows for the control of up to two DC motors, enabling bi-directional rotation and providing the ability to create projects that require motorized movements such as robotics, automated machinery, and more. The L293D shield simplifies the process of controlling motors by integrating H-bridge circuits, which are essential for changing the direction of the motor's rotation.
Pin Number | Description | Notes |
---|---|---|
1-2 | Motor A Connection | Connect to DC motor A terminals |
3-4 | Motor B Connection | Connect to DC motor B terminals |
5 | Ground | Connect to Arduino GND |
6 | Voltage Supply for Motors (Vm) | 4.5V to 36V |
7 | Voltage Supply for Logic (Vss) | 5V from Arduino |
8-11 | Control Pins (Input) | Connect to Arduino digital pins |
12 | Enable Pin for Motor A | PWM capable for speed control |
13 | Enable Pin for Motor B | PWM capable for speed control |
#include <Arduino.h>
// Define motor control and PWM pins
const int motorAPin1 = 10; // Control pin for motor A
const int motorAPin2 = 9; // Control pin for motor A
const int motorBPin1 = 11; // Control pin for motor B
const int motorBPin2 = 3; // Control pin for motor B
const int enablePinA = 5; // PWM pin for motor A speed
const int enablePinB = 6; // PWM pin for motor B speed
void setup() {
// Set motor control pins as outputs
pinMode(motorAPin1, OUTPUT);
pinMode(motorAPin2, OUTPUT);
pinMode(motorBPin1, OUTPUT);
pinMode(motorBPin2, OUTPUT);
pinMode(enablePinA, OUTPUT);
pinMode(enablePinB, OUTPUT);
}
void loop() {
// Rotate Motor A forward
digitalWrite(motorAPin1, HIGH);
digitalWrite(motorAPin2, LOW);
analogWrite(enablePinA, 128); // Set speed (0-255)
// Rotate Motor B reverse
digitalWrite(motorBPin1, LOW);
digitalWrite(motorBPin2, HIGH);
analogWrite(enablePinB, 128); // Set speed (0-255)
delay(2000); // Run motors for 2 seconds
// Stop motors
digitalWrite(motorAPin1, LOW);
digitalWrite(motorAPin2, LOW);
digitalWrite(motorBPin1, LOW);
digitalWrite(motorBPin2, LOW);
analogWrite(enablePinA, 0); // Turn off PWM to stop motor
analogWrite(enablePinB, 0); // Turn off PWM to stop motor
delay(1000); // Wait for 1 second
}
This example demonstrates basic forward and reverse control of two DC motors using the L293D motor driver shield. Adjust the analogWrite
values to control the speed of the motors.