Inquire: Call 0086-755-23203480, or reach out via the form below/your sales contact to discuss our design, manufacturing, and assembly capabilities.
Quote: Email your PCB files to Sales@pcbsync.com (Preferred for large files) or submit online. We will contact you promptly. Please ensure your email is correct.
Notes: For PCB fabrication, we require PCB design file in Gerber RS-274X format (most preferred), *.PCB/DDB (Protel, inform your program version) format or *.BRD (Eagle) format. For PCB assembly, we require PCB design file in above mentioned format, drilling file and BOM. Click to download BOM template To avoid file missing, please include all files into one folder and compress it into .zip or .rar format.
Arduino PWM Motor Speed Control: Complete Guide – From Basics to Advanced Applications
After designing motor control circuits for industrial automation, robotics, and consumer electronics for over twelve years, I’ve implemented Arduino PWM motor speed control in hundreds of products. While the basic concept seems straightforward—vary the pulse width to change motor speed—the devil is in the details. Understanding how PWM actually works at the hardware level, selecting appropriate driver circuits, and avoiding common pitfalls separates functional prototypes from reliable production systems.
In this comprehensive guide, I’ll share practical insights from real-world implementations, including driver selection, proper wiring techniques, code optimization, and troubleshooting strategies. Whether you’re building your first Arduino robot or designing commercial motor control systems, this tutorial provides the foundation for successful PWM motor control.
Understanding PWM Fundamentals for Motor Control
What is PWM and Why It Works for Motors
Pulse Width Modulation (PWM) is a technique that creates variable average voltage through rapid switching between fully ON and fully OFF states. Instead of varying actual voltage levels (which wastes energy as heat in linear regulators), PWM delivers full voltage in controlled bursts.
DC motors respond to the average voltage they receive. When you apply a 50% duty cycle PWM signal at 12V, the motor experiences an effective 6V average, running at approximately half speed. The beauty of this approach is efficiency—the transistor switches are either fully conducting (minimal voltage drop) or completely off (no current flow), minimizing power loss.
Key PWM Parameters:
Parameter
Definition
Typical Range
Impact on Motors
Frequency
How many on/off cycles per second
100Hz – 40kHz
Too low: audible whine<br>Too high: switching losses
Duty Cycle
Percentage of time signal is HIGH
0% – 100%
Directly controls average voltage
Resolution
Number of discrete duty cycle levels
8-bit (256 levels)<br>10-bit (1024 levels)
Smoothness of speed control
Arduino PWM Motor Speed Control Architecture
Arduino boards generate PWM using hardware timers that automatically toggle pins at precise intervals. On Arduino Uno, six pins (3, 5, 6, 9, 10, 11) support PWM output through three independent timers.
Arduino Uno PWM Pin Configuration:
Pin(s)
Timer
Default Frequency
Notes
5, 6
Timer0
980Hz (976.56Hz)
Also controls millis() and delay()
9, 10
Timer1
490Hz (490.20Hz)
16-bit timer, can support servos
3, 11
Timer2
490Hz (490.20Hz)
Independent from Timer0
Important: Modifying Timer0 frequency affects millis(), delay(), and other timing functions. Always use Timer1 or Timer2 for custom PWM frequencies.
How Motors Respond to PWM
DC motors contain electromagnetic coils with significant inductance. This electrical property acts as a low-pass filter, smoothing the rapid PWM pulses into relatively steady current flow. The motor’s mechanical inertia further smooths the rotation, preventing it from starting and stopping with each pulse.
Motor Characteristics That Affect PWM Performance:
Inductance: Higher inductance smooths current better, allows lower PWM frequencies
Back-EMF: Generates voltage opposing applied voltage, varies with speed
Stall Current: Maximum current at zero speed, can be 5-10× running current
Torque-Speed Curve: Torque decreases as speed increases
Thermal Limits: Continuous operation vs. intermittent duty ratings
Essential Hardware for Arduino PWM Motor Speed Control
Why You Cannot Drive Motors Directly
Arduino digital pins can source approximately 20-40mA at 5V. Even small hobby motors draw 100-500mA, with larger motors consuming several amperes. Attempting direct connection causes:
Immediate Arduino damage from overcurrent
Voltage drops that reset the microcontroller
Back-EMF voltage spikes when motor de-energizes
Insufficient torque due to voltage/current limitations
Solution: Use a motor driver that switches high current using Arduino’s low-power PWM signal.
Motor Driver Selection Guide
Option 1: Single Transistor (Simple, Unidirectional)
For basic speed control in one direction only:
Component
Specifications
Use Case
Cost
NPN Transistor
2N2222, TIP120, TIP122
Small motors (<500mA)
$0.10-0.50
N-Channel MOSFET
IRF540N, IRLZ44N
Medium motors (1-5A)
$0.50-1.50
Logic-Level MOSFET
IRLZ44N, IRL540N
Arduino direct drive
$0.75-2.00
Wiring Example (N-Channel MOSFET):
Motor (+) → External Power Supply (+)
Motor (-) → MOSFET Drain
MOSFET Source → GND (Common with Arduino GND)
MOSFET Gate → Arduino PWM Pin (via 220Ω resistor)
Arduino GND → Power Supply GND (CRITICAL)
Option 2: H-Bridge (Bidirectional Control)
For speed AND direction control:
Driver IC
Max Current
Voltage Range
Channels
Price
Features
L293D
600mA
4.5-36V
2 motors
$1-2
Built-in protection diodes
L298N
2A
5-46V
2 motors
$2-4
Dual full-bridge, heatsink included
TB6612FNG
1.2A
4.5-13.5V
2 motors
$3-5
More efficient than L293D
VNH2SP30
30A
5.5-16V
1 motor
$8-12
High current applications
BTS7960
43A
5.5-27V
1 motor
$5-10
Extreme current capacity
L298N Module Benefits:
Onboard voltage regulator for Arduino power
Enable pins for PWM speed control
Direction control via logic pins
Protection diodes integrated
Screw terminals for easy connections
Power Supply Considerations
Motor power requirements often exceed Arduino capabilities significantly.
Power Supply Sizing:
Required Current = Motor Stall Current × 1.5 (safety factor)
Required Voltage = Motor Rated Voltage + Driver Drop (1-3V)
Example: 12V motor rated 1A running current, 3A stall current:
Supply Current: 3A × 1.5 = 4.5A minimum
Supply Voltage: 12V + 2V = 14V recommended
Critical Design Rules:
Common Ground: Arduino GND must connect to motor power supply GND
Separate Supplies: Don’t power motors from Arduino’s 5V regulator
Decoupling Capacitors: 100µF electrolytic + 0.1µF ceramic near motor terminals
Current Capacity: Account for starting surge (2-5× running current)
Arduino PWM Motor Speed Control Programming
Basic Speed Control with analogWrite()
The simplest Arduino PWM motor speed control uses the built-in analogWrite() function:
Dead Zone Concept: The middle potentiometer position (approximately 512) creates a neutral zone where the motor stops. This prevents jerky transitions when passing through zero speed.
Advanced PWM Techniques
Adjusting PWM Frequency
Default Arduino PWM frequencies (490Hz/980Hz) work for most applications but can cause issues:
Problems with Default Frequencies:
Audible whining from motor windings
Interference with other circuits
Insufficient for high-speed switching applications
Changing Timer1 Frequency (Pins 9, 10):
void setup() {
// Change Timer1 frequency (pins 9 and 10)
// Default: TCCR1B = 0x03 (490Hz)
// 31.37kHz (nearly silent operation)
TCCR1B = (TCCR1B & 0xF8) | 0x01;
pinMode(9, OUTPUT);
}
void loop() {
analogWrite(9, 128); // 50% duty cycle at 31.37kHz
}
Available Timer1 Frequencies:
Divisor
Code
Frequency
Best For
1
0x01
31.37kHz
Silent operation, small motors
8
0x02
3.92kHz
Reduced noise
64
0x03
490Hz
Default, general use
256
0x04
122Hz
High-inductance motors
1024
0x05
30Hz
Very slow switching
Implementing Soft Start
Instant application of full power causes mechanical stress and current spikes. Soft start gradually accelerates:
PWM Duty Cycle Calculator: Converts voltage to PWM value
Timer Prescaler Calculator: Determines frequency from register settings
Current Sense Resistor Calculator: Sizes shunt resistors for monitoring
Motor Power Calculator: Estimates battery runtime
Frequently Asked Questions
1. Why does my motor make a high-pitched whining noise?
The whining sound comes from motor windings vibrating at the PWM frequency—typically 490Hz or 980Hz on Arduino, which falls within the audible range. This is normal but annoying. Solutions include: (1) Increase PWM frequency above 20kHz (human hearing limit) by modifying timer prescalers. Use TCCR1B = (TCCR1B & 0xF8) | 0x01; for 31kHz on pins 9 and 10. (2) Use a motor driver with built-in frequency control like TB6612FNG. (3) Add mechanical damping with rubber motor mounts. (4) Accept the noise—it won’t damage the motor and many commercial products have audible PWM. The frequency that causes least noise varies by motor construction, so experimentation may be needed.
2. My motor doesn’t respond smoothly at low PWM values. Why?
DC motors have a minimum voltage threshold below which they cannot overcome internal friction and produce torque. This “dead zone” typically occurs at PWM values roughly 0-40 (out of 255). Below this threshold, the motor draws current but doesn’t rotate. Solutions include: (1) Implement a minimum speed threshold in code—map your control input to skip the dead zone, for example map(input, 0, 1023, 50, 255). (2) Use a gear reduction to increase torque at low speeds. (3) Ensure proper lubrication and minimal mechanical binding. (4) Accept the limitation—for precise low-speed control, consider stepper motors instead of DC motors with PWM. The dead zone varies significantly between motor types; high-quality brushless motors have smaller dead zones than cheap brush motors.
3. Can I connect multiple motors to the same PWM pin?
Technically yes, but practically problematic. Multiple motors connected in parallel to one PWM pin will: (1) Draw combined current that likely exceeds driver capacity—a driver rated 2A cannot safely drive two 1.5A motors. (2) Run at identical speeds since they share the same control signal—you cannot independently control them. (3) Create unequal loads if motors have different characteristics, causing one to work harder. For proper multi-motor control: (1) Use separate driver channels for each motor, even if they’ll run at the same speed—this allows individual current limiting. (2) Use a multi-channel driver like L298N (controls two motors) or shield designs supporting 4+ motors. (3) Control each motor with its own PWM pin for independent speed control. If motors truly must run identically and combined current is acceptable, use a higher-rated driver to safely handle the total load.
4. How do I prevent voltage spikes from damaging my Arduino?
Motor-generated voltage spikes occur when current suddenly stops, causing inductance to generate high voltage (back-EMF). Protection requires: (1) Always use drivers with integrated flyback diodes (L293D, L298N have these built-in). For discrete transistor circuits, add a diode across the motor terminals with cathode (+) to motor positive. (2) Add decoupling capacitors: 100µF electrolytic across motor power supply, 0.1µF ceramic near motor driver pins. (3) Ensure common ground between Arduino and motor power supply—floating grounds worsen noise coupling. (4) Use optoisolators to completely isolate Arduino from motor circuits in critical applications. (5) Add TVS (Transient Voltage Suppressor) diodes across power rails for additional protection. The key principle: provide a path for inductive current to circulate rather than seeking ground through Arduino pins.
5. Why does my motor speed vary with load?
DC motors naturally slow down under increasing load—this is fundamental to their operation. Without feedback control, Arduino PWM motor speed control is “open-loop,” meaning it sets voltage but doesn’t monitor actual speed. When load increases: (1) Motor draws more current, causing voltage drop in wiring and driver. (2) Mechanical resistance absorbs more power, reducing rotational speed. (3) Back-EMF decreases with slower rotation, allowing higher current but not compensating for load. Solutions for speed stability: (1) Implement closed-loop control using encoders to measure actual speed and adjust PWM to maintain setpoint. (2) Use higher voltage power supplies—12V motors run more consistently than 5V motors under varying load. (3) Select motors with higher torque rating than minimum required. (4) Add current monitoring and increase PWM when current exceeds threshold (simple load compensation). For critical speed regulation, consider stepper motors or servo motors with built-in position feedback.
Conclusion
Arduino PWM motor speed control represents one of the most accessible yet powerful techniques in embedded systems. From simple fan controllers to complex robotic vehicles, understanding PWM fundamentals and proper implementation separates functional prototypes from reliable systems.
The key takeaways from this comprehensive guide emphasize hardware selection matching your motor specifications, proper power supply design with common ground connections, and appropriate driver circuits to protect Arduino while delivering necessary current. Software implementation using analogWrite() provides immediate functionality, while advanced techniques like frequency adjustment and soft start enhance performance.
Remember that PWM control is inherently open-loop—the Arduino sets a duty cycle but doesn’t verify actual motor speed unless you add encoder feedback. This limitation means speed will vary with load, voltage fluctuations, and motor characteristics. For applications requiring precise speed regulation, consider implementing closed-loop control or selecting motors with integrated feedback.
Start with simple single-direction control using a MOSFET to understand basic principles. Progress to H-bridge drivers like the L298N for bidirectional control. Experiment with frequency adjustment to eliminate motor whine. Implement soft start for mechanical longevity. Add current sensing for protection and load detection.
The beauty of Arduino PWM motor speed control lies in its scalability—the same principles apply whether controlling a 5V hobby motor in an educational robot or managing multiple 24V industrial motors in production equipment. Master these fundamentals, and you’ll have the foundation for virtually any DC motor control application you can imagine.
Inquire: Call 0086-755-23203480, or reach out via the form below/your sales contact to discuss our design, manufacturing, and assembly capabilities.
Quote: Email your PCB files to Sales@pcbsync.com (Preferred for large files) or submit online. We will contact you promptly. Please ensure your email is correct.
Notes: For PCB fabrication, we require PCB design file in Gerber RS-274X format (most preferred), *.PCB/DDB (Protel, inform your program version) format or *.BRD (Eagle) format. For PCB assembly, we require PCB design file in above mentioned format, drilling file and BOM. Click to download BOM template To avoid file missing, please include all files into one folder and compress it into .zip or .rar format.