If you intend to build your own robot, you’ll need to control various motors like DC motors, stepper motors, and servos, and there’s no better option than the L293D Motor Driver Shield. It is capable of controlling all of these motors; there is no need for additional modules. Show
The L293D motor driver shield has all the bells and whistles required for a wide variety of low- to moderate-complexity projects. It can control: Hardware OverviewDriver ChipsetThe brains of the shield are two L293D motor drivers and a 74HC595 shift register. The L293D is a dual-channel H-Bridge motor driver that can control two DC motors or a single stepper motor. Because the shield includes two such motor drivers, it can control up to four DC motors or two stepper motors. The 74HC595 shift register, on the other hand, extends the Arduino’s four digital pins to the eight direction control pins of two L293D chips. Motor Power ConnectionsThe shield supports a motor voltage range of 4.5 to 25 volts. This power can be shared with the Arduino or used separately. In order to choose between the two, a special jumper labeled PWR is provided near the two-terminal power connector. When the jumper is in place, power is supplied to the motors via the Arduino DC power jack. In this case, the motors and Arduino are not physically isolated from each other. This method makes the shield easier to use because it requires only one power supply; however, you can use this method only when the motor supply voltage is less than 12V. When the jumper is removed, the motor power is disconnected from the Arduino, allowing the motors to be physically isolated from the Arduino. In this case, however, you must provide a separate motor power supply to the two-terminal power connector labeled EXT_PWR. Warning: Applying power to the EXT_PWR two-terminal power connector while the jumper is in place will short the two power supplies together, potentially damaging the motor shield as well as the Arduino! DC Motor ConnectionsThe output channels of both L293D ICs are broken out to the edge of the shield with two 5-pin screw terminals labeled M1, M2, M3, and M4. A total of four DC motors operating at 4.5 – 25V can be connected to these terminals. Each channel on the module can supply up to 600 mA (1.2A peak) current to the DC motor. The amount of current supplied to the motor, however, depends on the capacity of the motor power supply. Stepper Motor ConnectionsYou can also connect two stepper motors to the output terminals. One stepper motor is connected to M1-M2 and the other to M3-M4. If you have a 5-wire unipolar stepper motor, connect the center tap wire to the center ground terminal. Servo Motor ConnectionsThe shield brings out the 16-bit PWM output lines to two 3-pin headers, which you can use to connect two servo motors. Unfortunately, the servo motors are powered directly from the Arduino’s 5V supply, which is generally a bad idea. Doing so can cause the Arduino’s on-board 5V regulator to overheat and can also introduce electrical noise on the 5V supply. On the plus side, it has a 100uF capacitor on these power pins, which helps a little. So, if you want to use this feature, only use small servos like the SG90. Bonus FeaturesAmong the shield’s perks are the following: The shield includes a pulldown resistor array to keep motors off during power-up. The on-board LED indicates that the motor power supply is working properly. The motors will not run if it is not lit. The RESET button is nothing but Arduino’s reset button. It has been brought to the top for easy access. Six analog pins (A0 to A5), as well as 5V and ground connections, are provided in the bottom right corner. You can populate these with headers, making them useful for connecting various sensors. Arduino to Shield Pin ConnectionsFor DC and stepper motor control, the shield makes use of pins D3, D4, D5, D6, D7, D8, D11, and D12. D9 and D10 are used to control the servo motors. D10 is connected to Servo 1, while D9 is connected to Servo 2. Please note that the shield does not use the D2 or D13 pins. Installing AFMotor LibraryTo communicate with the shield, we must first install the AFMotor.h library. This will let us control DC, stepper, and servo motors with simple commands. To install the library, navigate to Sketch > Include Library > Manage Libraries… Wait for the Library Manager to download the libraries index and update the list of installed libraries. Filter your search by entering ‘motor shield’. Look for Adafruit Motor Shield library(V1 Firmware) by Adafruit. Click on that entry and then choose Install. Experiment 1 – Driving DC Motors with L293D ShieldNow that we’ve learned everything there is to know about the shield, we can start connecting it to the Arduino! WiringBegin by mounting the motor shield on top of an Arduino. Next, connect the motor power supply. In our experiment, we are using DC gearbox motors, also called “TT” motors, which are often found in two-wheel-drive robots. They are rated for 3 to 12V. So, we will connect the external 9V power supply to the EXT_PWR terminal. Finally, connect the motor to one of the M1, M2, M3, or M4 terminals. We are connecting it to M4. Arduino CodeThe sketch below will show you how to control the speed and spinning direction of a DC motor using the L293D motor driver shield and can serve as the basis for more practical experiments and projects. The sketch accelerates the DC motor in one direction before slowing down to stop. After one revolution, the motor reverses its spinning direction and repeats the process.
Code Explanation:The sketch begins by including the AFMotor.h library. The second line If you want to connect multiple motors to the shield, make a separate object for each motor. The following code snippet, for example, creates two AFmotor objects.
In the setup and loop sections of the code, we simply call the two functions listed below to control the speed and direction of a motor.
Experiment 2 – Driving Stepper Motors with L293D ShieldOur next experiment will involve connecting a stepper motor to the L293D shield. Begin by mounting the motor shield on top of an Arduino. Wiring for the 28BYJ-48 unipolar stepper28BYJ-48 unipolar stepper motors are rated at 5V and provide 48 steps per revolution. So, connect an external 5V power supply to the EXT_PWR terminal. Don’t forget to remove the PWR jumper. Finally, connect the motor to the stepper motor terminals M1-M2 (port 1) or M3-M4 (port2). We are connecting it to M3-M4.Wiring Unipolar Stepper Motor to L293D Motor Shield & ArduinoWiring for the NEMA 17 bipolar stepperNEMA 17 bipolar stepper motors are rated at 12V and provide 200 steps per revolution. So, connect an external 12V power supply to the EXT_PWR terminal. Don’t forget to remove the PWR jumper. Finally, connect the motor to the stepper motor terminals M1-M2 (port 1) or M3-M4 (port2). We are connecting it to M3-M4.Wiring Bipolar Stepper Motor to L293D Motor Shield & ArduinoArduino CodeThe following sketch will show you how to control a unipolar or bipolar stepper motor with the L293D shield, and it is the same for both motors except for the
0 parameter. Before running the sketch, modify this parameter to match the specifications of your motor. For example, set it to 200 for NEMA 17 and 48 for 28BYJ-48.
Code Explanation:The sketch begins by including the AFMotor.h library. The second line
1 creates a library object. Here, you must specify the motor’s steps-per-revolution and the port number to which the motor is connected. In the setup and loop sections of the code, we simply call the two functions listed below to control the speed and direction of a motor.
Experiment 3 – Driving Servo Motors with L293D ShieldOur final experiment will involve driving a servo motor with the L293D shield. WiringThe shield brings out the 16-bit PWM output pins D9 and D10 to two 3-pin headers, which you can use to connect two servo motors. Keep in mind that D10 is connected to Servo 1, whereas D9 is connected to Servo 2. The servo motors are powered directly from the Arduino’s 5V supply, so there is no need to connect anything to the EXT_PWR terminal. Wiring Servo Motor to L293D Motor Shield & ArduinoArduino CodeThis sketch is based on the standard sweep sketch found in the Arduino Examples under servo. It sweeps the shaft of a servo motor back and forth across 180 degrees. |