Skip to content

Actuators · Motor

L293D Motor Driver Shield V1

Control small DC motors, steppers and hobby servos with an L293D V1 shield—plus safe standalone ESP32 wiring

Updated October 29, 2026 2 board guides
L293D Motor Driver Shield V1

What is the L293D motor driver shield?

The L293D motor driver shield is a stackable board for the Arduino Uno that lets you run up to four DC motors, or two stepper motors, plus two hobby servos, from one board. It carries two L293D dual H-bridge chips and a 74HC595 shift register. It is a clone of the original Adafruit Motor Shield (now called V1), which is why the same Adafruit library works with almost every one you can buy.

Two things surprise people the first time. First, you cannot drive the motors with plain digitalWrite() calls. The direction signals go through the shift register, so the Arduino has to clock a byte into it every time a motor changes direction. The Adafruit Motor Shield library (AFMotor) hides all of that. Second, the shield takes over most of the Uno's pins: up to eight digital pins are claimed as soon as you use a motor (four PWM pins and four shift-register pins), plus pins 9 and 10 for the servo headers. Plan your sensors around what is left.

This page covers what the shield is, its pins, how to power it without damaging anything, working code for DC motors, steppers and servos on an Arduino Uno, and how to drive the same shield from an ESP32. The ESP32 needs a different approach, because the AFMotor library only runs on AVR boards.

Which Arduino pins the shield uses

The shield leaves very little free, so check this table before adding sensors.

Arduino pinUsed forNotes
D11Motor 1 PWM (speed)Also stepper 1
D3Motor 2 PWMAlso stepper 1
D6Motor 3 PWMAlso stepper 2. Some vendor documents list D5 and D6 the other way round for M3 and M4
D5Motor 4 PWMAlso stepper 2
D474HC595 clockNeeded for any motor
D874HC595 dataNeeded for any motor
D1274HC595 latchNeeded for any motor
D774HC595 output enable (active low)Needed for any motor
D9, D10Servo headersOnly used if you attach a servo. Which header is numbered 1 or 2 varies between makers
D0, D1Serial (USB)Free, but shared with the USB serial port
D2, D13FreeD13 is also the onboard LED
A0 to A5FreeBroken out on the shield. A4 and A5 are the I2C pins

Two practical consequences. Hardware SPI is not available, because D11 and D12 are taken, so SPI devices such as an SD card module or an RFID reader cannot use the hardware SPI pins. I2C on A4 and A5 works fine, so I2C sensors and small displays are the natural companions for this shield.

Powering the shield correctly

Most problems with this shield are power problems, not code problems.

Use a separate motor supply. Connect the battery or adapter to the EXT_PWR screw terminal, with the right polarity and within your shield's voltage rating. The motors cannot run from USB.

Know what the PWR jumper does. On most clones a jumper marked PWR joins EXT_PWR to the Arduino's VIN pin. With it fitted, one supply powers both the motors and the Arduino. Remove it while you develop with the Arduino on USB, and whenever the motor supply is noisy or higher than the Arduino's regulator should see.

Expect to lose 2 to 3 V. The L293D uses bipolar output stages, so a 6 V supply gives the motor roughly 3 to 4 V. Choose the supply for what the motor needs plus that loss, without exceeding the shield's rating. This is the main reason motors run slower than people expect on this driver.

Respect 0.6 A per channel. Each channel is rated for 0.6 A continuous and 1.2 A peak. Small yellow TT gear motors are usually fine when running freely, but they can pull more than 0.6 A when they stall against an obstacle. If a chip is too hot to touch, you are over the limit. Use a TB6612FNG or L298N for bigger loads.

Decouple the motors. Solder a 100 nF ceramic capacitor across each motor's terminals, and add a 100 to 470 µF electrolytic across EXT_PWR close to the shield. This reduces the electrical noise that resets Arduinos and upsets sensors.

Servos draw from the Arduino's regulator. The servo headers take 5 V from the Arduino. Small servos like the SG90 are fine. Larger servos can brown out the board, so power them from their own 5 V supply and disconnect the header's 5 V line (check your board for the trace or pin to cut).

Controlling DC motors with AFMotor

AF_DCMotor motor(1); creates a motor object for terminals M1 (use 2, 3 or 4 for the others). Three calls do almost everything:

  • setSpeed(0 to 255) sets the PWM duty cycle, which is the motor speed.
  • run(FORWARD) and run(BACKWARD) set the direction.
  • run(RELEASE) cuts power so the motor coasts to a stop. The library has no true brake.

A few things worth knowing:

  • Low speed values do not turn the motor. Below roughly 80 to 120 out of 255, most hobby motors just hum, because the supply after the 2 to 3 V loss cannot overcome friction. Start your ramps above that.
  • PWM frequency. The second constructor argument picks the PWM frequency for motors 1 and 2 (for example AF_DCMotor motor(1, MOTOR12_1KHZ);). Motors 3 and 4 use Timer 0, which the Arduino core also uses for millis() and delay(), so leave their rate alone.
  • Each motor is independent. Different speeds and directions on different motors work at the same time.

Stepper motors

The shield drives two stepper motors. AF_Stepper(stepsPerRevolution, port) uses port 1 for the M1 and M2 terminals (one stepper) and port 2 for M3 and M4. A 1.8 degree motor has 200 steps per revolution.

step(steps, direction, style) takes one of four styles: SINGLE energises one coil at a time, DOUBLE energises two coils for more torque, INTERLEAVE alternates between them for half steps (finer motion, so you need twice as many steps per revolution), and MICROSTEP gives smoother motion. step() blocks until the move is finished. For non-blocking motion with acceleration, use the AccelStepper library, which can drive a motor through single-step calls.

Check the current rating first. Each coil sits on a 0.6 A channel, so small steppers rated up to about 0.5 A per phase suit this shield. A typical NEMA 17 draws 1.5 A or more per phase and is too much for an L293D. Use an A4988 or DRV8825 driver for those.

Servos on the shield

The two servo headers connect straight to Arduino pins 9 and 10, so the standard Servo library does the job and AFMotor is not involved. Which header is labelled SERVO_1 or SERVO_2 varies between manufacturers, so test both.

Remember that the servo headers draw power from the Arduino's 5 V regulator. One or two small servos are fine. A servo that jitters, or an Arduino that resets when the servo moves, is a sign that it needs its own 5 V supply.

Boards that cannot use the AFMotor library

The original V1 AFMotor library targets classic AVR boards such as the Arduino Uno R3 and Mega and uses AVR-specific timer setup. Do not assume it compiles or behaves correctly on the ESP32 or Uno R4. For those boards, use a compatible alternative: the custom shift-register/PWM approach below for the ESP32, or a driver/library designed for the Uno R4. The Uno R4 path has not been validated in this guide.

Using the shield with an ESP32

The V1 shield is designed around Uno-style pin labels and 5 V logic. It does not plug into a standard ESP32 DevKit as a working drop-in shield, and the AVR AFMotor library is not the ESP32 driver. The advanced wiring below recreates the shield's control signals from ESP32 GPIO and PWM.

For a direct ESP32 connection, use jumper wires and buffer all four 74HC595 control lines (data, clock, latch and output-enable) through a 5 V-powered 74AHCT125 or 74HCT245. A 3.3 V ESP32 HIGH is not guaranteed to meet the HIGH threshold of a 5 V 74HC input. The L293D enable inputs can accept the ESP32's 3.3 V PWM HIGH level, but the shift-register control inputs need proper level translation. Keep ESP32 GPIO pins on the signal side only—never connect a shield's 5 V output to an ESP32 GPIO.

Shield pinFunctionESP32 GPIO
D874HC595 dataGPIO25, through 5 V-powered level translator
D474HC595 clockGPIO26, through level translator
D1274HC595 latchGPIO27, through level translator
D774HC595 output enable (active LOW)GPIO33, through level translator
D11Motor 1 PWMGPIO16
D3Motor 2 PWMGPIO17
D6Motor 3 PWMGPIO19
D5Motor 4 PWMGPIO18
D9 servo-header signalServo position signalGPIO21

These are example pins for a classic ESP32 DevKit V1. Verify the pinout for ESP32-S3, C3 and other boards before wiring; GPIO availability differs.

Power rules: use a regulated 5 V supply for the shield's logic rail and a motor supply on EXT_PWR that stays within the exact shield's rating. Keep these rails distinct and join their grounds with ESP32 ground. Do not tie two independent 5 V outputs together or back-feed a USB-powered ESP32. Power servos from a supply rated for their startup/stall current; isolate the servo header's +5 V line when using a separate servo supply. Remove the shield PWR jumper for standalone wiring and verify the clone's power path before connecting supplies.

ESP32 sketch: library-free motor control

This sketch recreates what AFMotor does. motorRun(motor, command, speed) works like the AFMotor calls, with a command of forward, backward, brake or release. It uses the ESP32 Arduino core 3.x PWM functions (ledcAttach and ledcWrite).

How it works. The 74HC595 holds eight direction bits, two per motor (one for each side of the H-bridge). motorRun() sets the right two bits, shifts the whole byte out, and pulses the latch. The PWM pin for that motor then sets the speed. Forward means side A high and side B low, backward is the opposite, brake pulls both sides low with the enable fully on, and release switches the enable off so the motor coasts. The bit positions in BIT_A and BIT_B come from the shield's wiring and match the ones AFMotor uses.

Older ESP32 core (2.x). Replace ledcAttach(pin, freq, bits) and ledcWrite(pin, duty) with ledcSetup(channel, freq, bits), ledcAttachPin(pin, channel) and ledcWrite(channel, duty), using one channel per motor.

Tuning. Try PWM frequencies between 1 kHz and 20 kHz. Lower frequencies give more torque at low speed but can whine; higher ones are quieter. If M3 and M4 respond the wrong way round, swap their entries in PIN_PWM (see the note on D5 and D6 above).

Stepper motor on the ESP32

A bipolar stepper uses two motor channels, one per coil. This function steps a stepper on M1 and M2 using the motorRun() helper from the sketch above. It uses full steps with both coils on, so use a small stepper with a coil current under 0.6 A.

Servo control when the shield is wired to an ESP32

The V1 shield's servo headers are simple signal, +5 V and ground connections; AFMotor does not control them. With the shield wired to a standalone ESP32, run a jumper from an ESP32 GPIO to the signal pin of one servo header (GPIO21 is used below). The servo's signal wire must never be connected to a 5 V rail.

Power the servo from a regulated 5 V supply sized for its startup and stall current. Share ground with the ESP32 and shield. If that servo supply is separate from the shield's 5 V logic rail, isolate the header's +5 V connection so the supplies are not tied together. Do not rely on the ESP32 board regulator to power a loaded servo.

The snippet below is for the ESP32 Arduino core 3.x and uses LEDC PWM at 50 Hz, alongside the motor PWM pins in the preceding shield sketch. It is a position command, not closed-loop confirmation that the horn physically reached the requested angle; calibrate the pulse range for the exact servo.

Wi-Fi remote control from a phone

The ESP32's biggest advantage over the Uno here is built-in Wi-Fi. This version of the sketch serves a small control page. Replace setup() and loop() in the sketch above with the code below, and keep everything else. Motors 1 and 2 are the left and right wheels. A failsafe stops the motors if no command arrives for 800 ms, so a dropped connection cannot leave the robot running.

ESP32 with a bare L293D chip (no shield)

If you do not already own the shield, the simplest ESP32 setup is the L293D chip on a breadboard. There is no shift register, and the chip's inputs accept 3.3 V logic. The chip's logic supply (pin 16) needs 4.5 V or more, so give it 5 V and not 3.3 V.

L293D pinNameConnect to
11,2EN (enable, motor A)ESP32 GPIO16 (PWM)
21AESP32 GPIO17
31YMotor A terminal 1
4, 5GNDGND
62YMotor A terminal 2
72AESP32 GPIO18
8VCC2Motor supply (within the motor's rating)
93,4EN (enable, motor B)ESP32 GPIO19 (PWM)
103AESP32 GPIO21
113YMotor B terminal 1
12, 13GNDGND
144YMotor B terminal 2
154AESP32 GPIO22
16VCC15 V logic supply

Join all grounds: the ESP32, the chip and the motor supply. The 100 nF and 100 to 470 µF decoupling advice from the power section applies here too.

Troubleshooting

SymptomLikely causeFix
Nothing moves, but the Arduino runsNo motor supply on EXT_PWR, or it is switched offConnect and switch on EXT_PWR. USB cannot drive motors
Arduino resets when a motor startsSupply sag or electrical noiseUse a stronger supply, add 100 nF across each motor and 100 to 470 µF on EXT_PWR, remove the PWR jumper and power the Arduino separately
Motor hums but does not turnSpeed value too low, or too little voltage after the 2 to 3 V driver lossRaise setSpeed() and the supply voltage
Motor runs the wrong wayMotor wires swappedSwap the two wires, or swap FORWARD and BACKWARD in code
M3 and M4 respond the wrong way roundVendor documents disagree about D5 and D6Test, then swap the motor numbers in your code
AFMotor.h: No such file or directoryLibrary not installedInstall the Adafruit Motor Shield library (V1)
Compile errors on ESP32 or Uno R4AFMotor is AVR-onlyUse the library-free code in the ESP32 section
L293D too hot to touchOver 0.6 A, often from a stalled motorUse a smaller motor or a TB6612FNG / L298N
Servo jitters or the board resetsServo powered from the Arduino regulatorGive the servo its own 5 V supply
ESP32: motors ignore commands or act randomly3.3 V too weak for the 74HC595, a missing common ground, or OE not lowAdd the level shifter, join all grounds, and drive D7 low
ESP32: wrong motor movesWiring order of the PWM pinsCheck the GPIO table against your wiring and the PIN_PWM array

L293D shield or something else?

DriverCurrent per channelVoltage lossBest for
L293D shield (this page)0.6 AAbout 2 to 3 VLearning, small toy motors, four motors on one Uno
L298N module2 AAbout 1.5 to 2 VBigger brushed motors where efficiency is not critical
TB6612FNG1.2 A (3.2 A peak)LowBattery robots and small motors that need real torque
DRV88331.5 A (2 A peak)LowCompact low-voltage robots

The L293D shield is a good first motor driver, because the library makes motors, steppers and servos trivial. When you run into its limits (a motor that runs weakly on battery power, or a chip that gets hot), move to a MOSFET driver.

What to build with it

  • A two-wheel or four-wheel robot car. Four motors on one Uno is what this shield is best at, and the free A0 to A5 pins take line-follower or ultrasonic sensors.
  • A Wi-Fi controlled car. Use the ESP32 sketch above and add a camera board or sensors.
  • A pan and tilt mount. Two servos on the servo headers.
  • A small conveyor or turntable. A stepper on port 1 or 2, with a limit switch on a free pin.
  • A motorised blind or slider. A small gear motor with end stops.

Frequently asked questions

Can I run the shield from USB power alone? The Arduino will run, but the motors will not, and trying to power them from USB can reset the board. Use the EXT_PWR terminal.

Why does my motor run slower than the battery voltage suggests? The L293D loses roughly 2 to 3 V in its output stages, so a motor on a 6 V supply sees about 3 to 4 V. A MOSFET driver such as the TB6612FNG loses far less.

Can I connect the shield to an ESP32 directly, like an Uno shield? Not directly. The pins do not line up with Uno pin numbers and the logic is 5 V. Wire it with jumper wires as shown above. Some ESP32 boards use the Uno shield layout, but their header labels often do not match the GPIO the AFMotor code expects, so check the board's pinout and use the library-free code with your own pin table.

Do I need the level shifter on the ESP32? The PWM lines connect directly. The 74HC595 lines (data, clock, latch) are the ones where 3.3 V is borderline, so a 74AHCT125 is recommended. Some setups work without it, but it is the first thing to try when motors behave randomly.

Can I use the free pins for sensors? Yes. A0 to A5 are broken out on the shield, and D2 and D13 are free. Avoid hardware SPI devices, since D11 and D12 are in use.

Does it work with the Arduino Mega? The Adafruit library supports the Mega and the shield stacks on it. Check the library notes before relying on specific pins for other devices.

Specifications

Driver ICs
2 x L293D dual H-bridge (4 motor channels in total)
Direction control
74HC595 shift register on Arduino pins D4, D7, D8 and D12. The Arduino cannot drive the L293D direction pins directly
Outputs
4 DC motors, or 2 stepper motors (bipolar or unipolar), plus 2 hobby servo headers
Motor supply
Fed to the EXT_PWR terminal. The L293D chip accepts 4.5 to 36 V, but cheap shields use lower-rated parts, so stay within the limit on your seller's listing (often about 12 V maximum)
Current per channel
0.6 A continuous, 1.2 A peak (L293D rating). Stalled hobby motors can exceed this
Voltage lost in the driver
Roughly 2 to 3 V between the supply and the motor at load (bipolar output stages)
Logic voltage
5 V, taken from the Arduino header
Speed control
PWM on Arduino pins 11, 3, 6 and 5, one per motor
Servo outputs
2 three-pin headers on pins 9 and 10, powered from the Arduino's 5 V regulator
Protection
Internal clamp diodes in the L293D. No current sensing and no fault output
Software
Adafruit Motor Shield library (AFMotor) on AVR Arduinos, or library-free shift-register code on other boards
Form factor
Arduino Uno stacking shield (also fits the Mega headers)

Pinout

PinNameDescription
1M1Motor 1 screw terminals (or stepper 1, coil A). PWM speed on Arduino D11
2M2Motor 2 screw terminals (or stepper 1, coil B). PWM speed on Arduino D3
3M3Motor 3 screw terminals (or stepper 2, coil A). PWM speed on D6, though some vendor documents list D5 and D6 the other way round
4M4Motor 4 screw terminals (or stepper 2, coil B). PWM speed on D5 (see the note on M3)
5GNDMiddle screw terminal between M1/M2 and between M3/M4. Ground only, not a motor connection
6EXT_PWR +Motor supply input. Observe polarity and stay within the shield's voltage rating
7EXT_PWR GNDMotor supply ground. Shared with the Arduino ground on the board
8SERVO_1 / SERVO_2Three-pin servo headers on Arduino pins 9 and 10. Power comes from the Arduino 5 V regulator. Which header is numbered 1 or 2 varies between makers
9PWR jumperJoins EXT_PWR to the Arduino VIN pin when fitted, so one supply powers both. Remove it to power the Arduino separately

Swipe sideways to see every column →

Check which shield you have: V1 or V2

"Adafruit Motor Shield" covers two very different boards, and tutorials mix them up constantly.

Shield V1 (this page)Shield V2
Driver chips2 x L293D (bipolar transistors)2 x TB6612 (MOSFETs)
ControlArduino pins plus a 74HC595 shift registerI2C, through a dedicated PWM controller chip
LibraryAdafruit Motor Shield library (AFMotor.h)Adafruit Motor Shield V2 library (Adafruit_MotorShield.h)
Cheap clonesVery common, sold as "L293D motor driver shield"Rare

If your board has two chips marked L293D and a smaller 16-pin chip marked 74HC595 (or HC595), it is a V1 design and everything on this page applies. If it has I2C pads and TB6612 chips, you need the V2 library instead and the code here will not work.

Variants

VariantPriceNotesInterface
L293D motor shield (this listing)~$3-8Two L293D chips plus a 74HC595. Four DC motors or two steppers plus two servos on one Uno, at 0.6 A per channel and a 2 to 3 V loss. Great for learning and small toy motorsArduino pins + AFMotor library
Adafruit Motor Shield V2~$20-25A different board: TB6612 MOSFET drivers controlled over I2C, with its own library. Much less voltage loss, and V1 code does not run on itI2C
L293D chip (DIP-16)~$1-2The same driver without the shield: two motors per chip, no shift register, and it accepts 3.3 V logic, which makes it the easy choice for an ESP32PWM + 2 direction pins per motor
L298N module~$2-4Higher current (2 A per channel) in a bigger module with an onboard regulator. Also loses 1.5 to 2 V as heatPWM + 2 direction pins per motor
TB6612FNG / DRV8833~$2-5MOSFET drivers with far less voltage drop and heat. Better for battery robots and small motors that need real torquePWM + direction pins

Swipe sideways to see every column →

The L293D shield is the easiest way to run several small DC motors, a stepper and two servos from one Arduino Uno, and with the AFMotor library the code is only a few lines. Its limits are 0.6 A per channel and a 2 to 3 V loss in the driver, so it suits toy gear motors and small robots. For bigger motors or battery-powered builds, pick a MOSFET driver such as the TB6612FNG. On an ESP32, drive the shield with the library-free code on this page, or skip the shield and wire a bare L293D.

Wiring & code

Board integration

Library

Adafruit Motor Shield V1 library (AFMotor) + Servo by Adafruit / Arduino

Arduino IDE Library Manager: install the Adafruit Motor Shield V1-compatible library that provides AFMotor.h. Servo is included with the Arduino AVR core.

Wiring

Component pinArduino Uno R3 pinNote
Arduino Uno R3 headersStacking headersStack a V1-compatible shield onto the Uno with the header rows aligned. The shield itself handles the control-pin wiring.
Brushed DC motorM1 screw terminalsUse a small motor whose stall current stays within the shield/channel rating; test unloaded first.
Stepper motor coilsM3 + M4 screw terminalsConnect one coil pair to M3 and the other coil pair to M4. This example uses shield stepper port 2.
Servo signalServo header signal D9Use the header's signal, +5 V and GND pins. Provide a separate adequately rated 5 V servo supply if the servo current exceeds the Uno regulator budget, and isolate supply positives as needed.
External motor supplyEXT_PWR + / GNDObserve polarity and the exact clone's voltage rating. Remove the PWR jumper while the Uno is USB-powered unless the specific board's power arrangement is verified.

Swipe sideways to see every column →

C++

Combined bench example runs one small DC motor on M1, a 200-step stepper on M3/M4 (shield stepper port 2), and one servo on D9 in sequence. Keep motor current within the L293D channel rating and use adequate external supplies.

Step-by-step

Board guides