Controlling a Solenoid Valve from an Arduino. Updated.

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 vales 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 the Arduino does not give a warning when another device wants more power than it can supply, it simply tries to provide the current the device wants. 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 fulfil 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. 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.

Continue reading