In an earlier instructable, presenting an automatic garden watering project with an Attiny, I mentioned it could also be done with an op amp. So, let me put my money where my mouth is and present you one. It has an option to use a regular relay, or a solid state relay
Here is what you need:
1 Opamp UA741 (or LM741, or other '741 'type')
1 LED (red or green, for LED's with a high voltage drop, like blue, you may want to adapt R2)
1 resistor of 10-200k (I'll get back to that in the text)
1 resistor of 10-100 Ohm (whatever you have lying around)
1 reed switch (The small ones in a glass) if you can't find one, try a door contact
1 8 pins DIL IC foot
1 electrolytic capacitor 220uF 16-25 V (optional)
1 small submersible pump (I use a 5 W pump that pumps 430 l/h that is about 7 liters a minute) (Garden centers, eBay)
- if you chose to build the thing with a solid state relay add the following:
1 resistor 220 Ohm
1 solid state Relay (I use a 39MF22)
1 8 pins IC foot
1 resistor of 100 Ohm (optional)
1 capacitor of 100 nf 400 V (optional)
Note. I have chosen the 39MF22 solid-state relay because it is rather cheap. If you cannot find
it in your area, choose the mechanic relay. If that is no option consider replacing the solid state relay by an optocoupler with TRIAC. If you have a low voltage DC pump, consider switching it with a FET or transistor, or the mechanical relay
- if you chose to build it with a mechanical relay, add the following
1 resistor 1k
1 NPN transistor such as BC547
1 diode 1N4001
1 relay (make) voltage 5-18 Volt (depending on your situation)
A large bucket (DIY stores, I use one that is used to mix cement)
Tubing/Hose (DIY stores, garden stores)
Double cable low voltage
110-220 V cable suitable for outside use (DIY stores)
2 galvanized nails or a galvanized clothes hanger (DIY store, your mothers closet), or 2 carbon rods from an old battery
heat shrink tubing
blank PCB of about 5x5 cm
Hydrochloric acid (drugstore, diy store)
A watertight wall socket for outside use (DIY store)
A wallwart PSU of 5-15 Volt (depending on your situation).
That is very difficult to say as I had much of the stuff already available. The most expensive was I think the pump (14 euro's). The electronic components are really nickle and dime stuff. A 741 cost 25 cents (euro's), the 39MF22 was 1.80 euro.
I used a watertight wall socket that I had available, but I think these are about 3 euro's. Everybody must already have a wallwart PSU available somewher.
Mains cables for outside use are not really cheap (say a euro/meter) but often you can get it cheaper and if you are a gardener, you may have something left over from a previous installation.
I am not really counting the chemicals for etching either coz I had these for other projects as well, but also that is very cheap.
If I just count stuff that I had to buy especially for this project, it may have costed me 20-25 euro's, but I guess that if you dont have that much stuff laying around, it could be 35-40 euro's.
I will cover the following steps:
The electronic circuit (Intro)
Printing the PCB (step 1)
Etching the PCB (step 2)
Mounting the components (step 3)
Using a stripboard instead of a PCB (step 4)
Making a humidity sensor out of galvanized material (step 5)
Making an alternative humidity sensor out of gypsum (step 6)
Making a level indicator (step 7)
On overview of the finished project (step 8)
Seeing it in action (step 9)
Expansions (step 10)
The circuit is quite simple. P1 is used to set the level where the pump should start pumping. In dry soil the resistance of the spikes is high and the voltage on the inverting pin of the opamp is low. If that is lower than the voltage on the non-inverting pin (set by P1) the output will go high. This will activate the solidstate relay (a 39MF22) and or activate the mechanical relay. The PCB allows for both. The value of R1 is depending on your humidity sensor and the type of soil you use. For me 10 K was a good choice. In Step 4, where I describe the humidity sensor. I will tell you how to choose a good value for this resistor.
The pump that I use is a small submersible pump, used for small pond fountains. It pumps water from a container into a drip line in my veggie bed. Submersible pumps do not like to run dry, so we need some way to measure the waterlevel and to stop the pump when the level is too low. That is where S1 and R5 come in. S1 is a simple Normally Open float switch. I use a reed relay attached to the outside of the container and a floating device with a magnet on the inside (more about that later. When the level in the container goes too low, the float switch closes.
The trick is that I connect the floatswitch via a very small resistor (10-100 R) to the same terminals that the moisture sensor is attached to. So if the water level is too low, and the switch closes, there suddenly is a very low resistance over the humidity spikes and the 741 Op amp is 'tricked' into 'thinking' that the soil is wet enough and will switch off the pump.
You could use other switches than a reed relay, but this one has worked for me (I will come with some suggestions later)
C2 is not really necessary. One can put it in to give a bit of a delay with switchin the relay's on or off and thus avoid jittering.
The voltage to feed the 741 op amp is not so critical. Mine works on 5 Volts (I would not go much lower) but depending on the type of 741 you use you may go as high as 18 or 22 Volts. If you do though, you may want to recalculate R2. The current value of R2 is 220 Ohm.
In calculating the resistor value for other voltages, take the following in consideration: The 39MF22 has forward voltage of 1.2 Volts. Current should be between 5 and 20 mA. Most green or red LED's have a forward voltage of 2 Volts. Therefore the value of R should be at least (Vcc-3.2)/20 (gives value in kOhm) and at most (Vcc-3.2)/5 (gives value in kOhm).
So for 5 Volts this would be 1.8/20=90 Ohm till 1.8/5=360 Ohm
This table will save you calculating the value of R2:
Voltage Minimal value Max value
5 90 360
6 140 560
7 190 760
8 240 960
9 290 1160
10 340 1360
11 390 1560
12 440 1760
13 490 1960
14 540 2160
15 590 2360
16 640 2560
17 690 2760
18 740 2960
Values in Ohms. Just chose one sort of in the middle of the range for your voltage
The snubbing network around C1 and R3 is optional and most likely not necessary as I understand solid state relays to be quite capable of handling inductive loads. If you use it, put it in the wall socket (more about this later)
Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.
Step 1: Irrigating Your Garden With an Opamp: Printing the PCB
To facilitate construction, I have made a PCB, although you could also build this on veroboard or stripboard. You will find the PCB design here for download. (Note There is a new printdesign here) The design for the printed circuit is orientated to make it suitable for direct toner transfer. That means that the printed side will have to go against the copper.
The design as you see it on paper is as if you would be looking at it from the component side, so if you want to use this design for any other method than toner transfer, keep that in mind.
Though this is not a tutorial on how to make your own printed circuit boards, I will quickly lead you through the steps of how I did it. The pictures I use are not specifically from this board but from another board but the method is the same:
-Print the PDF on glossy paper in a 1:1 scale, and cut it out. This can be special photopaper but just printed paper from a glossy magazine do well. Some people use paper that is normally used in baking
-Thoroughly clean a piece of PCB of about 4x5 cm, use steelwool. (picture 2)
-Heat up a regular flat iron on its highest temperature (setting for linnen or cotton). (picture 3)
-Put the printed design, face down on the copper and hold it in place with your fingers
-Take the tip of the hot iron and put it on a spot neer the center and hold it there for a few seconds, while you still hold the paper in place.
-This should have fixated the design to the board so it won't move anymore.
-Now put the flat iron, completely on the paper and press it down
-Hold that for about 30 seconds, while presing firmly.
-Now use the tip of the iron to rub down every part of the paper.
-Throw it in some water (watch it, probably very hot) and leave it there for about 10 minutes. Dont forget to switch off your iron
-After 10 minutes, peel of as much paper as possible, use your thumbs to really rub hard.
-Throw it in water again to let is soak and then take off more paper
-Repeat this till all the paper is gone
-You will probably be left with a final very thin layer of paper that is hard to remove. Use a soft tootbrush to remove that.
Your PCB now has its mask and is ready for etching . (picture 3)
Just one remark: the design you will download is very slightly different from the one you see below: I moved the position of the diode that protects the transistor from the relay, to make it easier to mount
Step 2: Irrigating Your Garden With an Opamp: Etching the PCB
As learning how to etch PCB's is not the goal of this ibble, I will quickly go through it,
Also, as I already etched my PCB before I thought of taking pictures, I will use pictures from another PCB's etching process.
First a warning:
You will be using hazardeous materials that, if proper care is taken should not pose an unacceptable risc, however, if no proper care is taken, they can cause bodily harm, cause material damage and lead to your wife not speaking to you for some time to come
-Do this outside (Do not do it in that beautiful stainless steel kitchen sink)
-Use plastic or glass utensils only
DO NOT ALTER THE ORDER OF THIS MIX-UP
Measure 15 ml of water
Put that in a plastic container
Measure 25 ml of 10% Hydrochloric acid (sometimes called Muriatic acid)
Put that in that same plastic container
Add a few drops of Hydroyxperoxide (H2O2)
Put in the PCB that you have just applied a mask to. (Picture 1)
Swirl the solution gently: you will see the copper layer change color (Picture 2)
You will see the copper being eaten away and the solution turn green (Picture 3)
When the copper is completely eaten away, take out the PCB with a plastic 'one time use' spoon. and put it in some water to rinse
You will be left with a proper PCB that only has the required traces left (Picture 4)
Clean the PCB either with acetone or a Scotchbrite pad to remove all the protective ink (in fact it is not ink, but a plastic like polymer)
Step 3: Irrigating Your Garden With an Opamp: Mounting the PCB
Populating the PCB with the components is quite straightforward and should be clear from the picture.
Like always there are a few things to consider:
Orientate your IC's the right way. Most have a notch that should line up with the notch on the IC foot. These notches are clearly visible in this picture.
Watch the polarity of your LED: It has two legs, a short one and a long one. The long one is the anode, the short one the kathode. It also has a flat side at the base, at the side of the kathode
Watch the polarity of your diode. The cathode is normally indicated by a white band.
Watch the polarity of your electrolytic capacitor. It usually has a white band, possibly with arrows on it, running down one side. That is the kathode.
Watch the orientation of your transistor. If you are using a BC547, the orientation is clear from the picture. If you are using another NPN, then check its datasheet sou you know for sure what the base, emmitter, and collector are
Stick your component yhrough the proper holes. Cut off the legs almost flush with the copper side and quickly heat it with your soldering iron while applying solder. Remove any stray solder that might have made a short with another copper track. I always like to inspect every solder joint with a small magnifying glass directly after I make it.
You may have noticed that in the print design I switched the positions of R2 and the LED. Though that should not be a problem if you are using the 39MF22 version, but if you are using the Relay version, it could prevent the relay from switching off:
Solution 1: Switch the positions of the resistor and the LED. I will upload a corrected version of the PCB
Solution 2: desolder the right side of the base resistor of the Transistor and connect that with a piece of wire to pin 2 of the 39MF22
When the soldering is done test the board: insert the 741 opamp in its foot, but do not insert the 39MF22.
Take a piece of wire, possibly a piece that you cut off from one of the resistors, bend it in a 'U' shape and stick that in leg 2 and 3 of the IC foot of the 39MF22.
Set P1 in the middle position and apply power.
As there is nothing attached to the sensor input, the LED should light up. If it does not, turn P1 till it does (but really, it should already light up in the middle position).
If you are using a relay, measure if the relay really closes.
If you have come this far, things are looking good. Time for the next step
Remove the piece of wire from the IC foot, (but leave it there if you are using a mechanical relay only)
Insert your 39MF22
Apply power again
Your LED should be on, albeit a bit less bright than before.
If it does not light up then there are a few possibilities:
The value of the LED-resistor is too high and therefore the trigger current of the 39MF22 is not met
The value of the resistor was too low and you have burned out your 39MF22
Your 39MF22 was broken to begin with.
Check your resistor values and try again
Attach your humidity sensor and stick it in the soil. Turn P1 till the LED just goes off. Pull your humidity sensor out of the soil. Your LED should be on again.
Stick your sensor back in the soil and turn P1 so your LED is just on. Water your soil around the sensor and check your LED, it should be off or go off very soon.
If that is all OK you are in business. If not, don't despair. It is a simple circuit and there really cannot be much wrong with it. check all your connections, inspect your PCB, did you make any shorts?
If necessary, ask a question
A little bit of experience and some issues:
After having tried this system for some time I am quite happy, but I discovered that even when the soil is wet enough, the irrigation might continue with water trickling out of the irrigation system
The root of this problem might actually not be the components that are being used but the kind of irrigation system being used. The pump actually does switch off with the 39MF22 but the irrigation system may still have a bit of syphon action if your reservoir is higher than your irrigation system. The effect also seems more frequent if the drainage holes in your systme are larger. It does not happen with soaker hoses or sprinklers. That is also why it happens with some pumps and not with others: some pumps actually allow waterflow when turned off, others dont.
If this is happening to your system: do a simple test: cut the power!. If there is still water coming from your irrigation system it is NOT the circuit, but the irrigation system.
-Make sure your water supply is below your irrigation system, or
-install an airator ( a valve that closes when the pump is active, but lets in air when the pump is off)
Relay will sometimes not switch off
I have tested both the SSRI version and the mechanical relay version and the latter may show a problem that eventhough the 741 goes low, the voltage on the output is still high enough to open the tranistor. Oddly though that is a problem that sometimes disapepars.
The root of this is most likely the fact that the 741 is not ideal as an on/off comparator. Even in the 'Off state' there still may be a considerable (2 Volt) output on the 741. There is in fact a more suitable -pin compatible- Opamp, namely the CA3140. The 741 however costs 25 cts, the CA3140 costs 1.50 euro
In this case the problem might be caused because I made a small mistake in the print design that initially I thought would not matter. The circuit shows that the transistor for the relay is fed from a resistor and an LED in which the LED ensures a voltage drop before it connects to the base resistor of T1. In the original print design however, I accidentally switched the position of the LED and the resistor going to the 39MF22. As a result, the base transistor for T1 did no longer connect via the LED and thus does not benefit from the volgate drop.
1- switch the LED and R2 from position on the original print so base resistor R4 will be connected after the LED, or
2-use the new print design (of which i have provided the download link)
3 use a CA3140 instead of an LM741
Step 4: Irrigating Your Garden With an Opamp: Stripboard
If you do not want to etch a PCB, it is also possible to do it on a piece of 6x24 stripboard. I have added a lay-out for the solidstate relay version. One word of warning though: I have build the circuit on PCB, so the stripboard lay-out is not tested by me. It is OK as far as I can see, but should you want to use stripboard, really check every connection while you build.
You probably can pack this lay-out even tigther if you wish (R2 and everything to the right of it can at least shift left one position).
Nevertheless, I would really recommend the PCB
Step 5: The Humidity Sensor: Spikes
The simplest form of a soil humidity sensor is made from two galvanized nails that are stuck in the soil. Though technically other metals or conducting materials can be used, stainless steel and galvanized iron seem to be the best resistent against corrosion in the soil. Stainless steel however is very difficult to solder, therefore galvanized material is a better choice.
Copper will corrode very fast and also easily start to act as a voltage cell, actually delivering a voltage that could disturb your measurements.
You could stick in these spikes just randomly, but I like to have them not to far apart and always more or less at the same distance. So I took a piece of electrical pipe, drilled two holes in it to stick in the spikes. I roughed up the top part to solder a wire to and covered that with heatshrink (remember to put the heatshrink on the wire before you solder.
Once you have made that sensor, stick it in your veggie bed and measure its resistance at a moment that you think the soil couls use some water. The ristance at that moment is a great ball parc indicator for your resistor R1. Choose it more or less equal to the resistance you just measured.
Step 6: The Humidity Sensor: a Gypsum Alternative
For completeness sake, I will describe how to make a gypsum sensor as there seems to be an eternal debate about what is better, a Gypsum sensor, or just a spike sensor. I dont have the answer, personally I do not have much problems with just spikes, but gypsum has a couple of advantages (so they say).
-A more even read out
Anyway, this is how to do it:
Take two spikes of galvanized iron, about 5 cm long. (Picture 1)
Take two short pieces of copperwire
Rough up one end of each spike with a file or some sandpaper, wrap the copperwire around it and solder
Put some heat shrink around that contact and let it shrink (Picture 2)
Saw off a piece of electrical conduit pipe that is about 6-6.5 cm
Splice that piece lengthwise
Put a bit of grease (cooking oil) on the inside and then tape it back together with Scotchtape
Also close off one end with a bit of Scotchtape
Mix some gypsum according to instruction on the pack.
Put the pipe upright, with the open side up. Fill with gypsum
Stick in the two spikes, make sure they are in completely but do not come out at the other end
Make sure they do not touch eachother
Let the Gypsum harden
When it has set, remove the scotchtaype, thanks to the grease, the two halves of the pipe should come loose easily (Picture 3)
Let it dry for another day an dthen cure it in an oven at 180 degrees Celsius for about half an hour. In order not to waste energy, this can be done best while baking something else (Picture 4).
You now have a piece of gypsum with two copperwires sticking out, partly covered with heat shrink.
Take some more heatshrink and slide that over the wires that will carry the info from the sensor to the circuit.
Solder those to the copperwire
Slide the heatshring all the way over the copperwire and the previously applied heatshrink.
Shrink that. (Picture 5)
The reason why I have soldered copperwire to the galvanized spikes rather than just solder wire directly to it, is because in the end it is a bit easier to solder wire to the copper than it is to solder wire to the galvanized spikes. The connection between the copper and the galvanized material is fortified by the heatshrink and the encasing in gypsum. I could have done that ofcourse already with the wire, but then it would be hard to cure the gysum in an oven because the insulation on the attached few meters of wire would melt.
However, it is no necessity, you could just leave a few milimeters of the galvanized material stick out, cure the gypsum and then solder and shrink wrap your wire to it.
Step 7: Irrigating Your Garden With an Opamp: the Level Switch
As I already soldered my level switch together before I wrote this 'ible', I'll have to make do with an illustration.
The level switch: Picture 1
A Reed switch is just a small glass tube with a magnetically sensitive wire in it that closes a contact when it passes through a magnetic field. I soldered a 100 Ohm resistor to one of the leads, soldered a wire to the other lead and to the resistor and covered it with shrink wrap. (Obviously the picture is not in scale: a reed switch is not 5 times the length of a film cannister)
The float: Picture 2 + Picture 3
I made a float out of an empty film cannister and glued a strong neodynium magnet in it. It resides in a PVC pipe in the container that keeps it in line with the reed switch, otherwise it would bob all over the container and the reed switch might be out of the influence of the magnetic field. The cannister should be able to move freely up and down the pvc pipe. If you do not have a film cannister, use something else that will float and can hold a magnet. Consider using an empty pill bottle. You could glue a magnet on a piece of polysturene, but I am not sure what the continuous exposure to water will do with the magnet.
The PVC pipe that contains the float should be fixed in its place over the reed switch. I used poprivets for that (at the top only)
Positioning the switch
I filled the reservoir with water so the pump was completely covered, I put the float and the magnet in the water, attached a multimeter to the wires coming from the level sensor and moved it up and down till I found the proper level where it would close.
I indicated that level and then glued the switch on it.
I have added illustrations of some alternative methods of level detection:
With a pull switch attached via a string to a floating device,
With a tilt switch on a float, that will have a changing angle when the water level drops
Step 8: Irrigating Your Garden With an Opamp: the Alternative Level Switch
After having the reed relay in use for a long time already, I noticed it did not work that well anymore as it seemed magnitized by the magnet. I therefore made another switch.
I attached a lever micro switch to an upright piece of wood, glued on a round wooden bottem. In the bottem is a hole through which a nylon string goes: one side is attached to the switch, the other side is attached to a floating object. That could be a rubber duckie, or a piece of wood. The device is protected from the elements by a plastic cone that came from a whipped cream spray can. The entire device is suspended over the water reservoir. The length of the string determines the level at which the switch closes.
Step 9: Irrigating Your Garden With an Opamp: the Electrical Circuit
A quick overview from the wiring is as follows:
a 220 V line is interrupted and switched by the opamp circuit and led to a wall socket
The pump plugs into that wallsocket/
A moisture sensor goes to the opamp circuit
A levelswitch, attached on the basin, goes to the op amp circuit
A tube from the pump is going to the gardenbed
Step 10: Irrigating Your Garden With an Opamp: Finally, Irrigating
The first picture shows my (still experimental) set up:
The white wire is the sensor. the thin red and black are the power supply that (for now) feeds from a 12 Volt rail for my garden lights.
The level switch feeds in the same connector block as the sensor does.
The thick black and blue leads (lower right) form the switched supply to the wall socket to the right. Currently they all exit via one hole, which is probably not according to Code, but I will fix that eventually as for now I am not sure yet if I will leave the opamp circuit outside, or will bring it in the house eventually. Actually according to local Code I should have used a brown thick wire instead of a blue one but who is gonna know?
The plug in the wall socket is the plug of my pump.
There are several ways to deliver the water to your plantbed such as a drip system or a soaker hose.
I decided to go for a fast and cheap solution: an electrical conduit pipe with some 1 mm holes in it and a cork to plug it at one end.
This picture shows the complete lay-out: at the right is a black 160 liter container It effectively contains some 135 liters as I have the pump switch off at a safe level. The grey pipe in it is the riser for the floater that triggers the level switch.
From the pump a hose is connected to the diy nozzle in my plantbed and if you look at the picture in full, you will see that actually quite some water comes out: in fact, some 7 liters/minute.
In the picture you wil also see some moisture sensors (I have tested a few, only one is connected).
The sensor worked great. It shut off the pump in about 1.5 minutes (the bed was rather dry, I had not been watering it because of this test). I then pulled out the sensor and the pump switched on again. I let it run because I wanted to check the level sensor. In about 15 minutes, when the appropriate level was reached, the pump shut off perfectly.
A close up of the nozzle with sprays coming out of it and the moisture sensor
Empties pretty fast
Step 11: Irrigating Your Garden With an Opamp: Improvements, Expansions, Winter Use
It is fun to think of how one can improve or add functions to a simple circuit like this that only has 2 inputs, as opposed to the many inputs on a microcontroller. What you could add for instance:
-An LDR or light sensitive diode/transistor to only make this work during the bright hours of the day. (Hint: an LDR in series with R2 would set a very high level at night time)
-A manual override: attach the humidity sensor via a switch: breaking the citcuit would activate the pump
- Re-design the print so it contains a psu that directly attaches to the mains voltage line via it's own transformer so a wallwart is no longer necessary
Improve the efficiency of the pump by letting it float just under the surface of the water (attach to a wooden or polystyrene floater). It would be pumping water then from the surface of the reservoir and would not need to pump it up so high for some time. Make sure though the wires and hosing do not tip the float and let the pump run dry.
If anyone comes up with idea's I'd be interested to hear them.
In the area where I live, it is no use irrigating in the winter, coz nothing grows and all water will be frozen. Not good for your pump. So want to leave your circuit idle??
What I have been using this for is to heat up a small propagator:
Replace the humidity sensor with an NTC of 10 k. Instead of attaching a pump, use it to switch a 15 Watt lightbulb. Set P1 such that it will switch on the lightbulb when the temperature drops below 21 degrees. Put the NTC and the lightbulb in your propagator and let those seeds sprout.
Step 12: Irrigating Your Garden With an Opamp: Update
Ater having used the presented circuit with much success, i needed to make a more dedicated one for a strawberry tower.
I actually didnt want to fuss with a mains fed high voltage pump anymore, so I found the JT180-A. A 5-12 Volt DC pump for a relatively low price (7 euro). As the 741 can operate in that voltage range, there was no need for a relay, but it could be switched directly.
For the transistor one can take a 2n1613 or 2n1711 as wel, but it can cutting it very close with regard to the 150 mA collector current. I used it as I had it laying around, but it is relatively expensive at 65 cts (euro).
The BD 137 is a much safer option and even cheaper at 0.25 euro. the 2N1613 and 2N1711 would benefit from a cooling element.
Though not drawn, it might be wise to put a 100uf and a 100nF over the power line.
I presume the function of the Soil moisture sensor is clear. However, I added two other things in parallel to the sensor.
First there is S1. this is the float switch that closes when the waterreservoir is empty. If it closes the opamp will be fooled into thinking there is no need to pump, thus avoiding the pump to run dry.
The other sensor is a rain sensor. If the soil is dry, but it is aboutto rain, it seems futile to start irrigating. Again the rain sensor, like the float switch, will trick the op-amp into thinking the soil is wet enough and will not pump.
Depending on the Voltage used, one can decide to leave out the LED and lower the value of the base-resistor
1 Person Made This Project!
ashinstruct made it!