Controling A Solenoid Valve With An Arduino
Controling A Solenoid Valve With An Arduino
by fmarquis
I need to take some vacation time and unfortunately, while I don't have kids, I
have bonsais.
Like kids, these little critters need constant care and especially, water.
Each day.
Argh!
Why can't they drink beer/wine by themselves?
Anyways... Faced with no one close enough or willing enough to take care of
them, I decided to use solenoid valves and an Arduino to create my own watering
system.
At this point, it is easier and cheaper to buy an industry-made timer.
However, the final project will include watering based on a schedule and/or
humidity in the earth, and a wireless logging system that will tell me while I'm
away if everything is working as expected.
But let's start with the basic project, as this may be more than enough for the
regular plant...
Let me explain:
Your Arduino, according to the official site, can deal with 7-20 volts and they
recommend 7-12V, explaining that more than 12V can result in the board
overheating. The reason is that the Arduino uses a linear voltage regulator that
will get rid of the extra voltage by making some heat with it. If you give 7V 0.5A to
a linear regulator like the LM7805, you get 5V and 2Vx0.5A= 1W of heat. If you
give it 12.6V (typical voltage for a fully-charged lead-acid battery), you need to
get rid of 3.8W of heat. And do you see any heat sink on the board? No?
Actually, the board is the (very limited) heat sink.
This is the reason why I used a 85% efficient DC-DC buck converter that I had
previously made. As it is quite another project to built a switching regulator, I will
provide you with two clues. The first one (the inspiration for my own project) was
a project published in Nuts and Volts in June 2008 by Jim Stewart. I modified
their original design using information provided in the official datasheet of the
LM2576. If you are in a rush to built one, use the schematic on page 11 (figure
22) and read everything, paying extra attention on the layout guidelines,
stick to the recommended hardware and it will work. If you are not in a rush, I'll
try to publish an instructable on it when I'm finished with this watering thing...
This a simple project... The toughest part was not to find is the solenoid valves,
but the adapters...
Hardware
Solenoid valve: I got these 12V / 0.4 A NC valves quite cheap on Ebay . They
are working fine on domestic pressure. However, I should have pay a little bit
more for a valve threaded directly for garden hoses. See the next point...
Adapters: As my solenoid valve had threads for 1/2" (while a normal garden
hose is 3/4") I needed two adapters and a female/female adapter to connect two
hoses together. I got them from a general hardware store. Believe it or not,
together these are the most expensive pieces of this project!
What I was looking for (now I know, but I had to try many different adapters!) was
two 3/4" MH x 3/4" MIP x 1/2" tapped FIP. I have no idea what it means, but this
is what you are looking for and you need two of them! You will also need a 3/4"
hose x 3/4" hose solid bass double female swivel adapter.
A power source: I use a 12V lead acid battery for this project to power both the
Arduino and the solenoid. The unidentified piece of circuitry is a home made
switching regulator. Go back to the last step, background information, if you don't
know why it is there!.
MOSFET: I used a FQP50N06L for this project. Looking at the datasheet, it is
probably overkill here as nothing more than 12V 0.5A will be used.On the
positive side, I don't have to worry for thermal derating...
You can find the official datasheet here
The MOSFET is available from many distributors... Newark/Element
14 andDigikey sell them for less than 2,00$ each.
LED (Any color): Any LED will do, it is mostly for debugging purpose. It will be
on when the MOSFET is on, but it should be obvious if it is working as some
water should be flowing...
Resistor: I used a simple 330 Ohm resistor that was lying on my bench. The
idea is to make sure no more than 20 mA will flow through the LED. If you omit
the LED, omit the resistor.
Diode: That is the one guy you should not omit. A normal 1N4007 was used.
Wires: To connect everything
Breadboard : To support everything
Software
Arduino IDE
Don't power up anything just yet! Did you forget something? Where is your
diode???
It should be connected between the solenoid terminals, so that the little line on
the diode is closest to the positive terminal of the solenoid. I decided to put the
diode very close to the solenoid because:
1. There are two very convenient little holes waiting for the diode in the crimps;
2. I remember reading something about putting diodes as close as possible to
the inductive load, but I don't remember the details. Any references anyone?
/*
MOSFET FQP50N06L - For BonsaiDuino
This sketch will blink a LED and at the same time, use the MOSFET to
open a 12V solenoid.
Arduino D10 : To LED (Through 330 Ohm Resistor)
Arduino D02 : To MOSFET Gate
Step 7: In conclusion...
This is a work in progress; the final version including a three zones and a much
nicer sketch should be posted soon. But for now, you do have the tools and the
knowledge to create your own watering system!