|
Research & Learning Class pages
Shop Admin
ITP Help Pages |
High Current LoadsIn 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. For this tutorial you'll need:
- or -
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: ![]() If you're using an Arduino breadboard shield, there is a row of sockets connected to 5V on the analog in side of the breadboard, and a row connected to ground on the digital in side of the board: ![]() 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.
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. 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).
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. 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:
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);
}
Note 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 |
||||||||||||