Load switching from arduino/mcu
ok so your arduino / raspi / beaglebone software is working fine and now you want to connect the shark lasers. But those wimpy microcontroller outputs cannot handle the mega-amps that the shark lasers require!! to rectify this deleterious situation, your friends at TAMI (R) have prepared this fine document.
whats a mosfet
its like a dam. it has a gate which you can open or close, letting tons of water thru or blocking it. The force required to open the gate is nothing compared to the force of the water it can control. In non-metaphonical terms, the current required to turn on the gate is almost immeasurably small (e.g. pico-amps, that is 10^-12 amps) while the current flowing thru the 'dam' can be tens or hundreds of amps.
mosfet = metal oxide semiconductor field effect transistor for those who like their terminology
To switch devices on/off from logic levels (like the digital outs of an arduino), the easiest way is to put a mosfet switch between the device and ground:
How this thing works - when the gate (it has a G(1) next to it, meaning that pin one of that transistor is the gate) is a few volts above the source (has a S(3) next to it) then you have 'lifted the gate' and the transistor is 'on' - almost no resistance from drain (at the top, connected to the load) to source - current can flow freely from the voltage supply thru the load to ground. If the gate is at the same voltage as the source, the gate is lowered, the transistor is off, there's mega mega resistance from drain to source.
SO - since the mcu (your arduino/raspberry/anything else in the digital world) can supply 5V (or even 3.3V ) which is above the turn-on voltage of the transistor (called 'Vthreshold') it can turn the thing on and off no problemo.
To make an inverter (when the mcu goes high, inverter output goes low and vice versa) you can do this:
and as you may surmise , the 'nand' is not far behind, and with it the entire machinery of digital logic
high side switch
Sometimes the ground has to be left connected and you want to turn the device on/off using a switch between the positive supply and the device - so-called 'high-side switching'. One way to do it is shown here, using the inverter idea (above) to turn on a pmos (which is like the nmos except it's on when gate is <lower> than the output pin (confusingly now called the source) by Vthreshold ~ 2.5V
The idea is that the mcu logic level turns the nmos on/off, which pulls the gate of the pmos down or lets it float up to the positive supply level (thats why it's connected to the resistor. When the nmos is off the resistance of the nmos is much higher than that of the resistor and hence the resistor 'sees' the positive rail much more, but when the nmos is on (and the resistance of the nmos is low) then the gate 'sees' ground. Alternatively you can think of voltage drop over the resistor when there is/isnt current thru the resistor.)
If you have a device that has tristate output (raspberry and arduino I'm looking at you) you can actually lose the nmos and just tristate the pin when you want off, ground it when you want on.
Here's a way to do a SPDT switch - only one or the other load is connected to +V. Make sure the maximum Vgs of the right nmos is not exceeded.