Past exam question: Assignment 3, Q13
Open in the Padhaiko appHow do you interface DC motor using transistor (using pwm to control speed)?
Solution
Why a Transistor Driver & Flyback Diode Are Required: An Arduino / ATmega328P digital pin can source at most at , which is insufficient to start and run a DC motor (, hundreds of mA).
- Power NPN / Darlington Transistor (e.g., TIP120): Acts as a low-side electronic switch controlled by a PWM output pin, capable of switching up to and .
- Base Resistor (): Limits base current from the microcontroller pin.
- Flyback Diode (
1N4001/1N4007): Connected in reverse bias across the motor terminals to clamp inductive back-EMF voltage spikes when the transistor turns OFF, protecting the transistor and MCU. - PWM Speed Control: Varying the duty cycle ( via
analogWrite()) varies the average DC voltage across the motor (), smoothly controlling its speed.
Hardware Wiring Diagram:
+9V Battery / Supply
|
+----------+----------+
| |
(Motor) [1N4001] Flyback Diode
| (Cathode to +9V)
+----------+----------+
| Collector (C)
Arduino Pin 9 ----[ 1k ohm ]----(B) TIP120 NPN Darlington
(PWM Output) | Emitter (E)
|
Arduino GND -----------------------+---------- (-) 9V Supply GND(Optionally, a pushbutton on digital pin 2 with a pull-down resistor can trigger speed ramping.)
Arduino PWM Speed-Control Program:
const int PUSH_BUTTON = 2; // Pushbutton input on Pin 2
const int MOTOR_PIN = 9; // PWM output to TIP120 Base on Pin 9
void setup() {
pinMode(PUSH_BUTTON, INPUT);
pinMode(MOTOR_PIN, OUTPUT);
}
void loop() {
if (digitalRead(PUSH_BUTTON) == HIGH) {
// Ramp motor speed smoothly from 0% to 100% duty cycle
for (int speed = 0; speed <= 255; speed++) {
analogWrite(MOTOR_PIN, speed);
delay(20);
}
// Ramp motor speed down from 100% to 0%
for (int speed = 255; speed >= 0; speed--) {
analogWrite(MOTOR_PIN, speed);
delay(20);
}
}
delay(1);
}Connect the DC motor between the external supply and the Collector of an NPN power transistor (TIP120) with its Emitter tied to common GND, place a 1N4001 flyback diode across the motor leads (cathode to ) to absorb inductive spikes, and drive the transistor Base via a resistor from an Arduino PWM pin (e.g., pin 9); calling analogWrite(9, value) () varies the PWM duty cycle to control motor speed.