|
Research & Learning Class pages
Shop Admin
ITP Help Pages |
Using a transistor to control high current loads with an ArduinoIn 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. Table of Contents (hide) 1. PartsYou will need the following parts for this tutorial.
- or -
2. Prepare the breadboardConect 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 potentiometerConnect 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 microcontrollerThe 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 motorIn 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 lampLikewise, 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 microcontrollerHere'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. NotesFor the motor users: |