ITP Notebook

Lab: Using a Transistor to Control High Current Loads

November 28, 2020

Physical Computing

Lab Guide

In this lab I used a transistor to control a DC motor. The DC motor requires a high current load, supplied by a 9V power jack. I used a potentiometer along with the transistor to regulate how much of that load reaches the motor. I used a MOSFET transistor — the FQP30N06L.

Wiring the circuit Wiring the circuit

I first wired the circuit, connecting the transistor’s gate to the microcontroller, the source to the DC motor and a diode, and the drain to ground.

I then uploaded the following code to see if everything was connected properly.

const int transistorPin = 2;

void setup() {
  // set  the transistor pin as output:
  pinMode(transistorPin, OUTPUT);
}

void loop() {
  digitalWrite(transistorPin, HIGH);
  delay(1000);
  digitalWrite(transistorPin, LOW);
  delay(1000);
}

Starting and stopping the motor

Then I implemented logic to control the speed of the motor using the potentiometer:

const int transistorPin = 3;

void setup() {
  pinMode(transistorPin, OUTPUT);
}

void loop() {
  int sensorValue = analogRead(A0);
  int outputValue = map(sensorValue, 0, 1023, 0, 255);
  analogWrite(transistorPin, outputValue);
}

Controlling the motor's speed using a potentiometer