If you have something that simply needs to be on or off, then a transistor will probably do the job. If we look at the MOS Driver module, we can see there are not many components to it:
One of the resistors and the LED are simply used to indicate that the 'signal' pin is on. The minimum needed is the MOSFET and a resistor (the resistor ensures that the MOSFET is turned off if there is nothing connected to the SIG pin). This version, using an N-Channel MOSFET (actually a ZT2468), is what is called a 'low-side switch', as it switches the load on the side closest to ground, like this:
Although this means that the motor is normally floating and connected to the higher voltage, it also means that a low voltage device like the Arduino can control a higher voltage device. If it was a high-side switch, then the Arduino would have to connect to the higher voltage, which would be harder. Note in the circuit below the pins of a MOSFET are referred to as Gate, Drain and Source. Check the datasheet if using a different MOSFET, as they might be in a different order, and some might have different ratings. This MOSFET is rated up to 55V and 169A, and may need up to 4V on the Gate to activate the MOSFET. For example, the ZT2400 MOSFET is smaller, has a different pin order and can only drive up to 200mA but this would probably be sufficient for switching relay coils. A P-Channel MOSFET could be used as a high-side switch, but this requires a different circuit. I’ll examine other options for high-side switches later in this article.
Here is the equivalent circuit diagram:
The below code will demonstrate how it works by turning the motor on and off.
void setup() {}
void loop() {
analogWrite(3,100);
delay(1000);
analogWrite(3,0);
delay(1000);
}
Another option for lower currents is to use a different type of transistor, called a bipolar transistor. Again, these come in two main types, NPN and PNP, with an NPN transistor typically being used as a low side switch. Discussing NPN transistors for now, while MOSFETs typically work off the voltage applied to their gate (compared with their source (VGS), a bipolar transistor depends on the current flowing into the base (and out of the emitter), and permits a proportional current to flow into the collector. The proportion is called the gain, and for a device like ZT2283, this is around 100. Bipolar transistors are also more sensitive to voltage spikes (which can occur when a motor is turned off), so require a 'snubber' diode to shunt the spike away from the transistor.
The same code as above will work with this circuit. You can see that the pins of a bipolar transistor also have different names- Collector, Base and Emitter. Like previously, this is a low-side driver. To create a high-side driver, you would use a PNP type such at ZT2284.
So you can see that for simplicity, a MOSFET requires one less component, and is generally capable of more current. These circuits are probably all you would need for a relay coil, or even a speaker generating tones, as the power only needs to be applied one way. If you need to reverse the current flow (for example, to reverse the direction of a motor), then you would need four transistors arranged in what is called a H-bridge. Instead of building this from parts, there are a couple of H-bridge IC's which make setting this up much easier, and removing the need for many external components.