What is an Arduino motor driver?
A motor driver acts as the power interface between a microcontroller and a motor. Arduino pins send low-current logic signals; the driver switches the higher current that the motor needs. With a suitable driver, you can command a motor to run forward, reverse, stop or change speed.
A common beginner setup uses an Arduino Uno, a brushed DC motor, a motor driver such as the L293D or L298N, and a separate supply selected for the motor's voltage and current. The exact wiring depends on the board and driver module you own.
L293D vs L298N: which should you choose?
| Feature | L293D | L298N module |
|---|---|---|
| Typical form | Small IC or breakout board | Larger module, often with screw terminals and a heatsink |
| Common use | Small, low-current DC motors and simple beginner builds | Projects needing a more substantial dual H-bridge module, within its specifications |
| Wiring | Requires careful identification of logic, enable, motor and supply pins | Module labels often make motor and supply connections easier to identify |
| Limitations | Voltage drop, current limits and thermal limits apply | Voltage drop, current limits and heat still matter; a heatsink does not make every motor suitable |
Neither driver is automatically the best choice for every robot. Check the exact manufacturer's datasheet or module documentation for recommended motor voltage, continuous current, peak current and thermal limits. For modern low-voltage motors, another driver may be more efficient.
Parts you will need
- Arduino Uno R3 or a compatible 5 V logic board.
- An L293D IC/breakout or an L298N module.
- One brushed DC motor whose voltage and current fit the driver.
- A suitable motor power supply or battery.
- Jumper wires and, for an IC, a breadboard or breakout board as appropriate.
- USB cable for programming the Arduino.
If you are new to the board, start with the Arduino Uno R3 guide for beginners to identify power, digital and PWM pins before connecting the driver.
Basic Arduino-to-driver wiring
The following is a conceptual wiring checklist for one DC motor on a driver channel. Always match the labels and pinout of your exact driver board; L293D breakout boards and L298N modules do not all use identical labels.
| Signal / connection | Typical purpose | Check before power-on |
|---|---|---|
| Arduino digital output → IN1 | Sets one direction input | Confirm the input pin number on your board. |
| Arduino digital output → IN2 | Sets the other direction input | Use a separate output pin. |
| Arduino PWM-capable pin → EN / enable | Enables the channel and can carry PWM for speed control | Some modules have an enable jumper; follow its manual before connecting PWM. |
| Driver OUT1 / OUT2 → motor terminals | Supplies the motor from the H-bridge output | Do not connect the motor directly to Arduino I/O pins. |
| Motor supply → driver motor-power input | Provides the motor's power | Stay within the driver's and motor's rated voltage and current. |
| Arduino GND ↔ driver GND ↔ supply negative | Provides a common reference for logic signals | Follow the driver board's grounding instructions. |
Example Arduino code: direction and PWM speed
This sketch illustrates the two direction inputs and an enable pin for a single driver channel. It uses Arduino pin 9 for PWM, pin 7 for IN1 and pin 8 for IN2. Change these assignments to match your wiring and board.
const int enA = 9; // PWM-capable enable pin
const int in1 = 7; // Direction input 1
const int in2 = 8; // Direction input 2
void setup() {
pinMode(enA, OUTPUT);
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
}
void loop() {
// Direction A
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
analogWrite(enA, 150); // PWM: 0 to 255
delay(2000);
// Stop the motor
analogWrite(enA, 0);
delay(1000);
// Direction B
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
analogWrite(enA, 150);
delay(2000);
// Stop before the next cycle
analogWrite(enA, 0);
delay(1000);
}
Important: This example assumes the driver accepts the indicated logic levels and PWM on its enable input. Follow the board's instructions about enable jumpers and logic voltage. On some boards, a PWM pin must be connected differently or a jumper must be removed before speed control works.
What does the PWM value do?
On a standard Arduino Uno, analogWrite() commonly accepts values from 0 to 255. A value of 0 requests no PWM output; larger values increase the duty cycle. The motor's actual speed also depends on its load, supply voltage, driver voltage drop and motor characteristics, so PWM values do not translate directly into a fixed RPM.
Test the motor safely
- Check the motor rating and the driver's voltage/current limits.
- With power disconnected, inspect polarity, motor terminals, direction inputs, enable pin and ground wiring.
- Upload the sketch with the motor disconnected if you want to verify that the board accepts the code.
- Connect the motor and supply. Raise the motor off the table so wheels or shafts cannot catch objects.
- Start at a moderate PWM value, watch for unexpected heat or noise, and disconnect power immediately if the driver or wiring heats quickly.
- If direction is reversed from what you expect, turn power off before swapping the motor wires or changing the direction logic.
Common problems and fixes
Motor does not move
Check the motor supply first, then common ground, enable pin/jumper, IN1/IN2 wiring and the motor terminals. Test the motor with a suitable, current-limited supply only if you know its rating and can do so safely.
Arduino resets when the motor starts
Startup current or electrical noise may cause a voltage dip. Use a power source sized for the motor, keep motor current out of the Arduino board's logic supply path, arrange grounding according to the driver documentation and add recommended decoupling components where required.
Speed does not change
Check that the enable input actually receives PWM, that the module's enable jumper is configured correctly and that the selected Arduino pin supports PWM. Also confirm that your code changes the PWM value and that the load is not too heavy.
Driver becomes very hot
Stop and disconnect power. The motor may exceed the driver's current rating, the supply voltage may be wrong, or the driver may be overheating because of voltage drop and load. Recheck the datasheet and choose a driver with suitable electrical and thermal ratings.
Motor spins in the opposite direction
Direction depends on the polarity at the motor terminals and the input logic. Reverse the direction inputs in code or, with power disconnected, swap the two motor leads.
What can you build next?
Once you can control motor direction and speed separately, use the same building blocks in a simple robot. Add sensors only after motor control works reliably.
Frequently asked questions
Can I connect a DC motor directly to an Arduino Uno?
No. A typical DC motor needs more current than an Arduino I/O pin can provide and can generate electrical noise. Use a suitable motor driver and motor supply.
Can the L293D control two motors?
The L293D is a dual H-bridge driver designed to control two DC motors independently when each motor and the required load fall within the device's ratings. Consult the datasheet for the limits that apply to your exact part.
Can I use an L298N for speed control?
Many L298N modules support PWM speed control through an enable input. Check the module's jumper configuration and documentation, then connect a compatible PWM signal.
Why does the same PWM value produce different speeds?
Motor speed depends on load, supply voltage, driver losses, friction and the motor itself. PWM is a control input, not a direct RPM setting.
Should the motor and Arduino use the same power supply?
It depends on current requirements and the driver design. A separate motor supply is often practical, with grounds connected as the driver documentation requires. Never exceed the rating of any board or component.