LWTL: DC Motor
2
1
10/25/12
Switch open
Switch closed
+5V +5V
LWTL: DC Motor
4
2
10/25/12
+5V
Inductive behavior of the
I motor causes current to
+ continue to flow when the
switch is opened suddenly.
Charge builds up on what
was the negative terminal
of the motor.
LWTL: DC Motor
5
Reverse current
LWTL: DC Motor
6
3
10/25/12
Motor Model
+5V +5V
LWTL: DC Motor
7
+5V
The flyback diode allows
charge to dissipate
+ without arcing across
the switch, or without
flowing back to ground
through the +5V voltage
supply.
LWTL: DC Motor
8
4
10/25/12
LWTL: DC Motor
10
5
10/25/12
LWTL: DC Motor
11
LWTL: DC Motor
12
6
10/25/12
7
10/25/12
LWTL: DC Motor
15
Use an NPN
2N4401 / MMBT4401
Transistor as a switch
2N4401 MMBT4401
E
C TO-92
B SOT-23 B
E
Mark: 2X
a medium power amplifier and TJ, Tstg Operating and Storage Junction Temperature Range
*These ratings are limiting values above which the serviceability of any semiconductor device may be impaired.
-55 to +150 C
up to 500 mA
Thermal Characteristics
Symbol Characteristic
TA = 25C unless otherwise noted
Max Units
2N4401 *MMBT4401
PD Total Device Dissipation 625 350 mW
Derate above 25C 5.0 2.8 mW/C
R!JC Thermal Resistance, Junction to Case 83.3 C/W
R!JA Thermal Resistance, Junction to Ambient 200 357 C/W
LWTL: DC Motor
16
8
10/25/12
Transistor
Diode
220 or 330
resistor
LWTL: DC Motor
17
+5V
1N4001
diode
Pin 9
P2N2222
330 NPN transistor
9
10/25/12
+5V +5V
PNP
transistor
PWM
PWM signal
signal
NPN
transistor
LWTL: DC Motor
19
+5V
Orient the diode so that the
silver stripe is at the same
+ voltage as the positive
motor terminal
PWM
signal
330
LWTL: DC Motor
20
10
10/25/12
LWTL: DC Motor
21
LWTL: DC Motor
22
11
10/25/12
+5V connections
LWTL: DC Motor
23
LWTL: DC Motor
24
12
10/25/12
Code is in spin_DC_motor.ino
// spin_DC_motor.ino Use PWM to control DC motor speed!
!
int motorPin = 3; // Pin 3 has PWM, connected it to the DC motor!
!
void setup() {!
pinMode(motorPin, OUTPUT); // Set motor pin to output mode!
}!
!
void loop() {!
analogWrite(motorPin, 150); // Motor at 150/255 of full speed!
delay(1000);!
analogWrite(motorPin, 250); // Motor at 250/255 of full speed!
delay(1000);!
}!
!
LWTL: DC Motor
25
13
10/25/12
LWTL: DC Motor
27
Code is in DC_motor_speed_control.ino
// File: DC_motor_speed_control.pde!
//!
// Use potentiometer input to set the speed of a DC motor!
// Output to the motor is PWM!
!
int motorPin = 3; // pin connected to the DC motor!
int potPin = 1; // analog input connected to the potentiometer!
!
void setup()!
{!
pinMode(motorPin, OUTPUT);!
}!
!
void loop()!
{!
int PWMoutput, potReading;!
!
potReading = analogRead(potPin);!
PWMoutput = map(potReading, 0, 1023, 0, 255 );!
analogWrite(motorPin, PWMoutput);!
}!
!
LWTL: DC Motor
28
14
10/25/12
LWTL: DC Motor
29
15