Main

Research & Learning

Class pages

Shop Admin

ITP Help Pages
Tom's pcomp site
DanO's pcomp site


Using a transistor to control high current loads with an Arduino

In this tutorial, you'll learn how to control a high-current DC load such as a DC motor or an incandescent light from a microcontroller.

1.  Parts

You will need the following parts for this tutorial.

Solderless breadboard
Solderless breadboard
hookup wire
22-AWG hookup wire
Arduino module
Arduino Microcontroller
module
Light Emiting Diodes
Light Emiting Diodes, LED
electrolytic capacitor
10uF electrolytic capacitor


resistors
10Kohm resistors
potentiometer
10Kohm potentiometer
Power diodes
power diodes
(for DC Motor version only)
DC power supply
DC power supply
TIP120 transistor
TIP120 transistor


DC Motor
DC Motor

- or -

Incandescent lamp and socket
Incandescent lamp and socket


2.  Prepare the breadboard

Conect power and ground on the breadboard to power and ground from the microcontroller. On the Arduino module, use the 5V and any of the ground connections:

3.  Add a potentiometer

Connect a potentiometer to analog in pin 0 of the module. You'll use this later to control the output, whether it's a motor or a light.

4.  Connect a TIP120 transistor to the microcontroller

The transistor allows you to control a circuit that's carrying higher current and voltage from the microcontroller. It acts as an electronic switch. The one you're using for this lab is an NPN-type transistor called a TIP120. The datasheet for it can be found here. It's designed for switching high-current loads. It has three connections, the base, the collector, and the emitter. The base is connected to the microcontroller's output. The high-current load (i.e. the motor or light) is attached to its power source, and then to the collector of the transistor. The emitter of the transistor is connected to ground.


Pinout of a TIP-120 transistor, from left to right: base, collector, emitter.


The schematic symbol of an NPN transistor where B is the base, C is the collector, and E is the emitter.

4.1  Connect a motor

In the motor circuit below, there is a diode in parallel with the collector and emitter of the transistor, pointing away from ground. This is there to protect the transistor should the polarity of the current reverse (for example, if the motor was turned in reverse, or when it releases back voltage). Be sure to add the diode to your circuit correctly. The silver band on the diode denotes the cathode which is the tip of the arrow in the schematic (diagram).

This circuit assumes you're using a 12V motor. If your motor requires a different voltage, make sure to use a power supply that's appropriate. Connect the ground of the motor's supply to the ground of your microcontroller circuit, though, or the circuit won't work properly.

4.2  Connect a lamp

Likewise, the lamp circuit below assumes a 12V lamp. Change your power supply accordingly if you're using a different lamp. In the lamp circuit, the protection diode is not needed, since there's no way for the polarity to get reversed in this circuit:

5.  Program the microcontroller

Here's a quick program to test the circuit:

int transistorPin = 9;    // connected to the base of the transistor

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

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

Now that you see it working, try changing the speed of the motor or the intensity of the lamp using the potentiometer. Try this code:

int potPin = 0;           // Analog in 0 connected to the potentiometer
int transistorPin = 9;    // connected to the base of the transistor
int potValue = 0;         // value returned from the potentiometer

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

void loop() {
  // read the potentiometer, convert it to 0 - 255:
  potValue = analogRead(potPin) / 4;
  // use that to control the transistor:
  analogWrite(9, potValue);
}

6.  Notes

For the motor users:
A motor controlled like this can only be turned in one direction. To be able to reverse the direction of the motor, an H-bridge circuit is required. For more on controlling DC motors with H-bridges, see the DC Motor Control lab

  Edit | View | History | Print | Recent Changes | Search Page last modified on February 19, 2009, at 02:10 PM