User Tools

Site Tools


Small DC Motor Pwm Speed Controller

When page is bookmarked, text here is referenced verbatim

Small D.C. Motor P.W.M. Speed Controller Tutorial

Keywords: PWM, Speed Controller, DC Motor, Breadboard, Potentiometer, 555 Timer, LED indicator, Transistor, Diode


The photo depicts a speed controller, wired on a breadboard which allows you to vary the resistance in the potentiometer in order to, in effect, control the speed of the small DC motor. The big picture problem is creating an efficient PWM motor controller that allows for an analog variance of voltage across the motor. Solving this partially or completely is important because the process allows for a range of analog voltage control to a DC motor. This tutorial shows you how to gather and construct the materials for a working, low voltage PWM speed controller and takes approximately 2 hours to complete.

Motivation and Audience

This tutorial's motivation is to assist hobbyist and introductory micro-controller enthusiasts to establish a solid foundation in the workings of low voltage speed controllers. Readers of this tutorial assumes the reader has the following background and interests:
  • Know how to read fundamental circuit diagrams
  • Also know how to wire said diagram via breadboard or solder a perfboard
  • Troubleshoot circuit failure
  • Desire to understand how and why a PWM speed controller works
  • In addition, would like to have an analog response from the DC motor
  • Lastly, would like to have a common, open-source solution to a variety of controller needs

The rest of the tutorial is presented as follows:

Parts List and Sources

US-based vendors to obtain material to complete this tutorial include RadioShack.

To complete this tutorial, you'll need the following items:

TABLE 1: Parts needed to build (fill in the blank)
Arduino Uno REV 3RadioShack Model:Uno|Catalog #:276-128 $29.991
PNP Amplifying TransistorsRadioShack Model:2N3906|Catalog #:276-1604 $3.4915
Breadboard and Jumper Wire KitRadioShack Model:2760257|Catalog #:276-257 $19.991
10K-Ohm Linear-Taper PotentiometerRadioShackModel:271-1715|Catalog #:271-1715 $3.491
3VDC Micro-Vibration MotorRadioShackModel:273-107|Catalog #:273-107 $3.491


This section gives step-by-step instructions along with photos to construct a simple speed controller out of common electrical components and an inexpensive micro-controller. A schematic to construct the hardwired version of the pulse width modulated, low voltage, DC motor speed controller is shown here:


PDF of 'Nuts and Bolts' Tutorial for hard-wiring the circuit is the Acrobat file of the same schematic, located at the bottom of the last page of the tutorial document. You will need Adobe's free Acrobat reader to view it.
A modified version of that same circuit that makes use of the micro-controller that this tutorial focuses on can be seen in the schematic below:


Step 1

Secure the needed parts outlined in the parts list from a neighbourhood RadioShack. Set the Arduino onto a flat, open workspace, as seen below


Step 2

Set the perf-board or solderless breadboard on a flat surface with an open, well-lit area. Begin to layout the electrical components onto a printed version of the circuit diagram. Connect the Voltage, Ground, and Analog input wires into their respective pins. The choice of analog pin does not matter at this point, however, it will affect the Arduino code later on in terms of telling the hardware to which pin to look for the input signal. The code, as well as the pictures, will show the input pin being A3 (the third analog input pin).


Step 3

Next, attach the leads of the potentiometer into the circuit. The potentiometer will be the driving force of the speed control in this project. The variable output voltages due to varying resistances produces what we perceive as a pulse width modulated signal. In the hardwire version of this tutorial, the potentiometer controllers the rate at which the capacitor discharges into the circuit and thus, produces a train of square waves. In the modified version, making use of the micro-controller, the variances in the voltage from the potentiometer are fed into an analog input in the Arduino which then turns out a PWM signal from one of the PWM digital pins on the other side of the board. In terms of attaching the potentiometer into the circuit, there will be three terminals that need to be wired. Referencing the picture below, the black wire is the ground of the pot, the middle (red wire) will be the input into the Arduino, and the blue wire is the power taken from the Arduino's 5V power pin. After connecting ground to Arduino's ground, the signal output to the analog input (A3) on the Arduino, and the power to the 5V power source, the circuit should look the following:


Step 3

Connecting the transistor is the next step before the signal is delivered to the motor. A transistor is a semiconductor device used to amplify and switch electronic signals and electrical power. It is composed of semiconductor material with at least three terminals for connection to an external circuit. A voltage or current applied to one pair of the transistor's terminals changes the current through another pair of terminals. Because the controlled (output) power can be higher than the controlling (input) power, a transistor can amplify a signal. The middle pin of the transistor takes the PWM output from the Arduino. The right-most pin of the transistor taps into the power bus from the 5V Arduino output and the left-pin connects into the motor. The connected transitor should look like the following:


Step 4

Finally, connecting the motor to the transistor and grounding it out will complete the circuit necessary to power and regulate the motor and its speeds. The view of the connections is as follows:


Below is the video of the working motor controller:


The source code to the motor controller from the potentiometer is provided below:

To be compiled with Arduino
Note: download PWM_Speed_Controller.ino rather than cutting and pasting from below.

// July 15, 2013
// Use a potentiometer to control a DC motor
int sensor_pin = 3;
int motor_pin = 5; 
void setup()
 pinMode(motor_pin, OUTPUT);
void loop()
 int pot_val, motor_speed;
 pot_val = analogRead( sensor_pin );
 motor_speed = pot_val*255.0/1023.0; 
 analogWrite( motor_pin, motor_speed);

PWM_Speed_Controller Code Description

The PWM_Speed_Controller Code operates as follows: The code initializes the two pins that will be used. Next the hardware is setup to understand that the serial will be be at a baud of 9,600 and the motor pin (digital pin 5 - a PWM output pin) will be giving out a signal (output). Then go into the loop of the program and initialize the variables 'pot_val' and 'motor_speed', set 'pot_val' equal to the reading of the sensor_pin in the analog pin which is the voltage output from the potentiometer. The motor speed is then determined by mapping the analog read onto the digital, PWM pin. The analog input from the potentiometer is a 10 bit input, a 10-bit voltage scale to 8-bit PWM scale. The voltage scale ranges from 0 to 1023 while the PWM scale only ranges from 0 to 255, explaining why the 'pot_val' needs a multipying factor of 255/1023.

Final Words

This tutorial's objective was to assist hobbyist and introductory micro-controller enthusiasts to establish a solid foundation in the workings of low voltage speed controllers. Complete construction details and source code for a working motor controller with analog response to an analog variation across the potentiometer. Once the concepts were conveyed the reader could duplicate said results and have a working, efficient, low voltage motor controller.

Speculating future work, derived from this tutorial, includes using an Arduino mini to connect to a protoboard of the current circuit in order to make the assembly portable and useful in a range of mobile applications. In the big picture, the problem of multipurposing and motor control can be solved with this tutorial.

Click here to email Dili Click here to email Joe

drexel_star_speed_controller.txt · Last modified: 2016/11/09 18:46 by dwallace