Using an Arduino can sometimes make it difficult to control high-voltage devices. The maximum voltage that the Arduino can output from its pins is +5 volts. Say we wanted to control a motor running at +12 volts? How could we do it?
The answer is transistors. Transistors are very powerful because they allow manipulation of very high voltages using only a very low voltage signal. Think of a transistor as a signal amplifier. A transistor can use a +5v signal from the Arduino to turn on or off a higher voltage +12v motor.
In common transistors like the TIP120, the "base" pin can connect to a control signal which controls current across the "collector" and "emitter" pins.
In the schematic below, a potentiometer is used to control the speed of a 12 volt DC motor via PWM. The potentiometer acts as a sensor and is connected to pin A0 as well as +5v and GND. Extra power comes from an external "wall wart" which provides a +12v current. Note: it is very important to connect
all the grounds together in circuits like this. The ground from the wall wart is connected to the ground of the Arduino even though they output different voltages.
To get this circuit to run on the Arduino, simply use the unmodified example code from Examples > Analog > AnalogInOutSerial. The Arduino reads the analog signal from the potentiometer on pin A0, and then outputs an equivalent PWM signal from pin 9. The transistor then amplifies the PWM signal in order to control the flow of +12v current through the motor.
Try it for yourself!