DC Motor Speed Control Using Arduino & PWM

DC Motor Speed Control Using Arduino & PWM

Speed control of DC motor with PC Interface is an easy DIY project. In this project DC motor’s speed is controlled by sending the command through PC. Arduino is directly connected to PC through the USB cable and command is given to Arduino on serial monitor of the Arduino IDE.

Motor is connected to a transistor, and the base of transistor is connected to PWM pin of Arduino and motors speed is varied according to PWM signal coming from Arduino.

Arduino DC Motor Control – Working

Arduino is connected to PC through the USB cable. We can send the command to PC on the serial monitor. We can change the speed of motor from 0 to 9. When 0 is sent over the Serial Monitor, the motor runs at minimum speed (that is zero). When the speed is varied from 1 to 9, the speed increases, with the value 9 set as the maximum speed of the motor.

A PWM DC motor controller technology is used to control the speed. In PWM, the Arduino sends a pulsating wave that is similar to astable mode of 555 timer IC.

PWM Speed Control (Pulse Width Modulation)

Microcontroller and Arduino are digital devices; they cannot give the analog output. Microcontroller gives Zero and ONE as output, where ZERO is logical LOW and ONE is logical HIGH. In our case, we are using 5 volt version of the Arduino. So it’s logical ZERO is zero voltage, and logical HIGH is 5 voltage.

Digital output is good for digital devices but sometimes we need the analog output. In such a case the PWM is very useful. In the PWM, output signal switches between zero and one, on high and fixed frequency, as shown in the figure below.

Output Signal of PWM

Output Signal of PWM

As shown in the above figure the ON time is “Ton” and the OFF time is “Toff”. T is the sum of the “Ton” and “Toff” which is called the Time Period. In the concept of PWM “T” is not varying and the “Ton” and the “Toff” can vary, in this way when “Ton” increase “Toff” will decrease and “Toff” increase when “Ton” decrease proportionally.

The duty cycle is the fraction of one Time period. Duty cycle is commonly expressed as a percentage or a ratio. A period is the time it takes for a signal to complete an on-and-off cycle. As a formula, a duty cycle may be expressed as:

DUTY CYCLE = (Ton ÷ T) x100 %

Now the motor’s speed varies according to duty cycle. Suppose the duty is zero, motor does not run and when duty cycle is 100 % the motor moves on maximum RPM. But this concept is not always right because motor starts running after giving some fixed voltage that is called threshold voltage.

Transistor (2N2222)

Microcontroller and the Arduino can process signals and consumes almost 20 to 40mA current but motors need high current and voltage, so we are using the transistor for driving the motor. Transistor is connected in series with motor and transistor’s base is connected to Arduino’s PWM pin through a resistance. PWM signal is coming from Arduino and the transistor works as a switch and it short circuit the Emitter (E) and Collector (C) when PWM signal is in High state and normally opens when PWM signal is in LOW state. This process works continuously and the motors runs at desired speed.


DC MotorLow Power1
Power Adapter12 Volts1
USB CableFor Arduino Nano1

Arduino DC Motor Control – Circuit

Circuit diagram is shown in the figure below. If you are making this circuit on the general purpose PCB (ZERO PCB) or breadboard, this figure is useful.