DC Motor Speed Control Using Arduino & PWM With Program and Circuit
DC Motor Speed Control Using Arduino & PWM With Program and Circuit
(http://www.circuitstoday.com)
Ads by Google
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 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.
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 xed frequency, as shown in the gure below.
http://www.circuitstoday.com/dc-motor-speed-control-arduino-pwm 1/11
3/13/2018 DC Motor Speed Control Using Arduino & PWM with program and circuit
(http://www.circuitstoday.com/wp-content/uploads/2017/11/Output-Signal-of-PWM.jpg)
As shown in the above gure 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:
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 xed 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.
Components
Arduino Nano 1
Transistor 2N222 1
Resistance 1K 1
Diode 1N4004 1
http://www.circuitstoday.com/dc-motor-speed-control-arduino-pwm 2/11
3/13/2018 DC Motor Speed Control Using Arduino & PWM with program and circuit
(http://www.circuitstoday.com/wp-content/uploads/2017/11/Arduino-DC-Motor-Speed-Control.bmp)
Moreover, if you are good in the PCB Etching, use the images provided below.
(http://www.circuitstoday.com/wp-content/uploads/2017/11/Arduino-PWM-DC-Motor-Control-PCB-
Design-.png)
(http://www.circuitstoday.com/wp-content/uploads/2017/11/Speed-Control-of-DC-Motor.png)
http://www.circuitstoday.com/dc-motor-speed-control-arduino-pwm 3/11
3/13/2018 DC Motor Speed Control Using Arduino & PWM with program and circuit
In the circuit an Arduino Nano (http://www.circuitstoday.com/arduino-nano-tutorial-pinout-schematics) is used, which is very small in size and Breadboard friendly.
A transistor’s (2n2222) BASE pin is connected to D9 pin of Arduino through a Resistance of 1k ohm, Resistance is used for current limitation. Motor is connected
between collector pin of transistor and Vcc. A diode (1n4004) is connected parallel to the motor in reverse bias; it is used for blocking the reverse current. Emitter pin
of the transistor is connected to the ground. This circuit is powered by a 12 volt adapter.
(http://www.circuitstoday.com/wp-content/uploads/2017/11/Arduino-DC-Motor-Control.jpg)
http://www.circuitstoday.com/dc-motor-speed-control-arduino-pwm 4/11
3/13/2018 DC Motor Speed Control Using Arduino & PWM with program and circuit
(http://www.circuitstoday.com/wp-content/uploads/2017/11/Arduino-PWM-Motor-Control.jpg)
In the beginning of the code two integers are declared by name “out1” and “val”, where out1 is equal to 9 which shown that pin D9 of Arduino is used as output pin (or
PWM pin). Moreover, data coming from the serial monitor saved in the second integer “val”.
In the void setup() serial communication is begin by using function “Serial.begin(9600)” where 9600 is the baud rate of serial monitor. After it “out1” is declared as
output because the motor is an output device.
In the void loop “serial.available” is used inside the “if” condition, it become true when any data is sent over the serial monitor. This data is saved in “val” integer using
“Serial.read” function.
After it many “if” conditions are used, in the rst “if condition”, when ‘0’ is sent through the serial monitor, it become true. In the bracket “analogWrite(out1 , 0)” is used
for running the motor at the zero PWM value. In the function “analogWrite (out1, 0)”, “out1” is used to indicate the pin which we want to use and “0” is the PWM value
at this pin. After it “Speed is = 0” is shown on serial monitor using “Serial.println” function. After it the integer “val” is updated to 10, where 10 is the random value,
which is other than 0 to 9.
In the next line if condition is used for “val ==1”, at this time motor runs at PWM value of 175. Same conditions are used upto 9, at the 9 motor runs at 255 PWM value,
255 is the maximum PWM value.
Process
After typing any value from zero to 9, speed of the motor varies, but we cannot see varying speed in video properly, but you can see it live.
Ads by Google
tt
http://www.circuitstoday.com/dc-motor-speed-control-arduino-pwm 5/11
3/13/2018 DC Motor Speed Control Using Arduino & PWM with program and circuit
::
//
You may also like:
//
ww
8 Best Arduino Starter Kit for Beginners (http://www.circuitstoday.com/best-arduino-starter-kit-beginner)
w
w
Arduino Nano Tutorial – Pinout & Schematics (http://www.circuitstoday.com/arduino-nano-tutorial-pinout-
schematics) w
w
..
Arduino Mega Tutorial – Pinout & Schematics (http://www.circuitstoday.com/arduino-mega-pinout-schematics)
cc
Project: Home Automation Using IR Remote Control (http://www.circuitstoday.com/home-automation-ir-remote-
control) ii
rr
Project: Auto Intensity Control Of Street Light Using Arduino (http://www.circuitstoday.com/auto-intensity-control-
street-light-arduino) cc
uu
ii
tt
We recommend: ss
tt
Mains operated LED lamp (http://www.circuitstoday.com/mains-operated-led-lamp)
oo
Buck boost converter circuit (http://www.circuitstoday.com/buck-boost-converter-circuit)
dd
Voltage Controlled Oscillator (http://www.circuitstoday.com/voltage-controlled-oscillator)
aa
SCR Control circuits (http://www.circuitstoday.com/scr-control-circuits)
yy
cc
oo
m
m
COMMENTS
//
asish joseph cm
February 9, 2018 aa
rg
-n
can you give the circuit diagram and program code of ph value detecter using aurdino??
se
pt
eo
e-
LEAVE A REPLY dr
-e
Your email address will not be published. Required elds are marked *
ds
ei
Comment
ts
et
co
tr
o)
Name * d
http://www.circuitstoday.com/dc-motor-speed-control-arduino-pwm 6/11
3/13/2018 DC Motor Speed Control Using Arduino & PWM with program and circuit
Email * o
Website
POST COMMENT
SORT BY TYPE
http://www.circuitstoday.com/dc-motor-speed-control-arduino-pwm 7/11
3/13/2018 DC Motor Speed Control Using Arduino & PWM with program and circuit
http://www.circuitstoday.com/dc-motor-speed-control-arduino-pwm 8/11
3/13/2018 DC Motor Speed Control Using Arduino & PWM with program and circuit
Instant Quote
Dimensions
Length x Width mm
Quantity
Layers
2 Layers
Thickness
1.6mm
Quote Now
(https://www.wellpcb.com/)
OTHER LINKS
About (http://www.circuitstoday.com/about)
http://www.circuitstoday.com/dc-motor-speed-control-arduino-pwm 9/11
3/13/2018 DC Motor Speed Control Using Arduino & PWM with program and circuit
Authors (http://www.circuitstoday.com/authors)
Datasheets (http://www.circuitstoday.com/datasheets)
Disclaimer (http://www.circuitstoday.com/disclaimer)
PCBFOX
acebook.com/sharer.php)
http://www.circuitstoday.com/dc-motor-speed-control-arduino-pwm 10/11
3/13/2018 DC Motor Speed Control Using Arduino & PWM with program and circuit
http://www.circuitstoday.com/dc-motor-speed-control-arduino-pwm 11/11