PadhaikoAll subjects

Past exam question: Assignment 3, Q13

Instrumentation · 5 marks

Open in the Padhaiko app

Topic: Sensor/Actuator interfacing with Atmega328P (Arduino): Analog and…

Question

How 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).

Hardware Wiring Diagram:

Arduino PWM DC Motor Control using TIP120 TransistorText
                             +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:

Arduino Sketch: PWM DC Motor Speed Control via TransistorC
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);
}
Answer:

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.

All past exam questions for Instrumentation