DC Motors
DC motors are all around you. They allow your cellphone to vibrate, they run laptop fans and they run the dvd drives.
Parameters of motors
- direct-drive vs. gearhead—built-in gears or not
- voltage—what voltage it best operates at
- current (efficiency)—how much current it needs to spin
- speed—how fast it spins
- torque—how strong it spins
- size, shaft diameter, shaft length,etc.
Characteristics
- When they first start up, they draw a lot more
current, up to 10x more.
-
They draw a lot of current when they stall
- They can operate in either direction, by
switching voltage polarity Polarity controls the direction
- Usually spin very fast: >1000 RPM
- To get slower spinning, need gearing
To drive a motor, apply a voltage.
The higher the voltage, the faster the spinning.
Just as voltage causes rotation, rotation causes voltage.
The circuit for motors is more complex than prior circuits you have worked with. In addition to
using familiar components, you'll also be using a
DC Motor,
diode , and a
transistor.

Diodes
Diodes allow current to flow only in one direction. Motors often create current
spikes as they turn on and off. These spikes can damage the
transistor, so you use a diode
to protect the transistor from the spikes.
Diodes have polarity, so the direction you install them
matters. The bar in the schematic diagram corresponds to a white stripe on the actual diode. Current
can only flow in the direction of the triangle.
Since motors can act like generators,
need to prevent them from generating kickback into the circuit
Once a motor starts spinning, its inertia keeps it spinning, this turns it into a generator and thus
can generate a
kickback voltage. The kickback diode routes that voltage harmlessly back into the
motor so it can't damage the rest of the circuit.
Kickback is also called
back EMF (EMF == electromotive force == voltage)
Transistors
Transistors have three terminals:
The
base is the input that you use to open and close the
switch across the
collector and
emitter.
On this type of transistor (called an
NPN, you need to make sure the
collector is always more positive than the emitter. Generally you do this by connecting the emitter
to ground.
Because the motor requires much more
power than the Arduino is capable of providing, you use batteries to power the motor. The transistor
allows you to control the amount of current that flows from the battery through the motor.
Transistors are used to run loads larger than 5V.

Typical Tip120 circuit
Controlling Motors
You can control speed of motor with
analogWrite()
just like controlling brightness of LED.
If you use a small motor, you can wire it up on the same breadboard:
In Arduino add this code:
int motor=___;
char val;
void setup(){
pinMode(_____,OUTPUT);
Serial.begin(19200);
Serial.println("enter speed number 0-9");
}
void loop(){
val=Serial.read();
if(val>='0' &&val<='9'){
val=val-'0'; //converts from char to num
val=28*val; //converts num to 0-255
analogWrite(____,___);
Serial.println("enter speed number 0-9");
}
}