A very short post I made sometime ago has been more popular that it should have been. It wasn’t particularly detailed and it was in desperate need of an update. So here is the update, this time giving more details and adding mosfets.
Arduinos are limited in the current and voltage they can supply. A typical 5V Arduino can provide 5V and 3.3v at a maximum 40mA from a single pin. 40mA is the maximum and ideally the current draw should be kept to around 20mA. 20mA is fine for a LED but not so good for motors, solenoid valves or long strings of RGB LEDs. For these we need a separate power supply and a way of controlling it.
One of the problems many beginners have is knowing what can be connected to and Arduino and what should not be. This post does not really help with this except to show how to use a high voltage/high current device with the Arduino. The high voltage/current is not connected directly to the Arduino but it can controlled by the Arduino by using devices that act as digital switches.
Knowing what to connect and what not to comes from experience and a little understanding of volts and current. I do not cover this here beyond saying voltages should match and currents are more difficult to determine. I have killed/partially killed more things because of current than I have because of volts simply because most things clearly say what voltage they are, A 24v power supply says 24v on it and I know I shouldn’t connect it to an Arduino. A very small 6v motor that looks like it hardly required power melted an Arduino with seconds. Finding a devices current requirement may mean reading data sheets and extensive online searches. Unfortunately Arduinos do not give a warning when a device wants more current than they can supply, they simply tries to provide it. This leads to over heating and mini explosions (or at least a dead Arduino and the smell of burnt plastic).
In this post I am using DC voltage solenoid valves only. Valves that use AC have very different requirements and the below does not apply. Most DC solenoid valves tend to use a voltage any where from 6v up and 12V and 24V are very common. The one I am using below is 24v. The Arduino cannot handle these voltages and so cannot (or should not) be connected directly to the valve. Instead, we use another device as a middleman, one that can accept the 5v signal from the Arduino as a control signal and also handle the higher voltage and current required by the valve. There are various different devices that can fulfill this role. I am using transistors. The Arduino controls the transistor and the transistor controls the valve. A simple way of thinking about this is we are using the transistor as a switch. The Arduino is controlling the switch and the switch is controlling the valve.
There are many transistors you can use and you pick one depending on the voltage and current you need to control. To know the voltage and current required means knowing about the device you want use. Here I am using the good old TIP120 and the IRFZ44N mosfet. Why these 2 devices? Because they are what I have. They were purchased sometime ago purely because they are suitable for use with 5v Arduinos.