
A DC motor's speed can be controlled smoothly using pulse-width modulation (PWM), with a potentiometer serving as a simple manual control interface the user feels directly, as if turning an actual speed knob.
Components needed
An Arduino Uno board, a DC motor, a 2N2222 transistor acting as an electronic switch, a 100k-ohm potentiometer, a 0.1µF capacitor, and a base resistor for the transistor.
Wiring it up
The potentiometer's wiper connects to analog pin A0. The motor connects to a switching circuit controlled by the 2N2222 transistor, where the Base pin connects to digital pin 12 through a protective resistor, and the motor is wired between the power supply and the transistor's Collector pin.
How it works
Rather than actually lowering the voltage delivered to the motor, the principle relies on switching current to it on and off very rapidly; the higher the ratio of on-time to off-time within each full cycle (duty cycle), the higher the effective average voltage the motor receives, and the faster it spins. The code reads the potentiometer's value from A0, then calculates a time delay inversely proportional to this value, which determines the duty cycle sent to the transistor's base via digital pin 12 — enabling smooth speed control from a full stop to maximum speed simply by turning the knob.
You can find DC motors and suitable transistors at Juthour Tech.
اترك تعليقا