
Embedded · CLEAR
PWM Motor Control
Speed control for an F130 DC motor from an Arduino Uno R3: the duty cycle of a PWM signal sets the average voltage the motor sees.
The problem
Switching a motor on and off is easy. Controlling how fast it spins is the next step, and an Arduino pin only gives 0 V or 5 V, nothing in between.
PWM gets around that: switch the pin fast enough and the motor responds to the average voltage, so the duty cycle sets the speed.
The approach
A potentiometer on an analog input sets the speed. The Arduino reads it (0 to 1023), maps it to 0 to 255, and writes that duty cycle to a PWM pin with analogWrite.
The PWM pin drives a transistor that switches the F130 motor, with a flyback diode across the motor for the same reason as in my Motor Switch circuit.
I simulated it in Tinkercad first, then built it on a real breadboard.
Next steps
Port it to the STM32 and do the same speed control with its hardware timers.