Building a Home Watering System

Hi folks,

Looking for some help building a home watering system. I’ve sketched out some schematics that I think should work, but I’m concerned connecting up the components in case I damage my UNO (I’m not 100 percent on how to work out which resistors, capacitors, transistors, I need to make it work.

So here goes, I have two parts of this circuit:

  1. Pump Circuit
  1. Probe Circuit
  • 100Ω Resistor
  • 57-100KΩ Resistor
  • Simple Moisture Sensor (2 stainless steel screws separated by a medium)

See the attached diagrams.

This is a very simple system but I’m just checking to make sure my Diode, Transistor, Resistors, and layout aren’t likely to cause any damage to the board.

Cheers,

Steven

If your pump is drawing water from a rain barrel or bucket, then it would be a good idea to add a float switch to detect when the water level is too low. These types of pumps are dependent on water to lubricate the impeller bearings and will quickly wear out if allowed to run dry.

That transistor can't handle your pump, it can do no more than 200 mA continuous. That 4.8W, 12V pump draws double that.

You need a bigger transistor, and then you may still need the BC547 as driver to get to the approx. 40 mA that switching transistor needs to supply 400 mA. 40 mA is too much for an Arduino to supply directly. Or get a MOSFET instead.

For your moisture probe, don't keep it electrified at all times, or it will corrode(I know it's stainless steel. It still will corrode). Just take your measurement (a few millisecond or so) and switch it off. Also keep in mind that measuring moisture in soil is very inaccurate, and there's a long delay between switching on the pump and that sensor sensing anything. Don't wait for that, time the pump.

I second the above suggestions. The startup current needed by the pump’s motor can be double the normal current, if not more. Stp16nf06l or similar would be a suitable MOSFET to use (n-channel with a logic level gate). I have found the simple type of soil moisture sensor to be reliable enough, as long as the sensor is calibrated for a particular position and then not disturbed. If you were making a portable sensor which you could take from plant to plant, push the probe into the soil and get an immediate accurate reading, then something much more sophisticated would be needed. But it does not sound like that is what you are asking for. Use, say, a 10K resistor to form a voltage divider with the probe. Power the voltage divider from a digital Arduino pin and feed the output to an analog pin. Make the digital pin HIGH just before you perform the analogRead(), then set it LOW again. If the moisture level is too low, switch on the pump for 30s only. Then wait perhaps 15 mins before measuring again, and if still too low, pump for another 30s.

Thanks for the quick response guys. So I’m starting to learn what to look for. Greatly appreciating the knowledge.

So, I have on me a IRF520 MOFSET which has an ID @ 25C of 9.2A and @ 100C 6.5A. (http://media.nkcelectronics.com/datasheet/irf520.pdf)

This should work yes? I’ tried comparing the specs to the Stp16nf06l (http://www.mouser.com/ds/2/389/stp16nf06l-956429.pdf) as suggested but I’m having a hard time with all of the specifications.

So assuming that it works, the connection should look like the attached?

Regarding the probe, I was torn between the system above with sporadic readings and using a voltage flipping style probe like here to combat corrosion. That being said I could combine the two technique to maximize the probe life.

This system is going to be in my balcony and designed to handle four or five pots. I’m just testing the basics first. Once I get the pump on, I have two solenoid valves that I want to engage tied to two probes. Unfortunately, I accidentally ordered two 24V solenoids instead of the two 12V solenoids I intended.

Regarding the bucket mikb55, good idea, I have a water level sensor, but I’m thinking I can just use a third probe and set the tips just above the safe level height. This should result in zero or near zero readings and be able to switch off the pump. I’m a better coder than I am a electrical engineer :slight_smile:

But, one thing at a time!

Cheers,

Steven

Circuit MOFSET.png

IRF mosfets need 8-10V on gate to fully open, so not suitable for control by Arduino. IRL mosfets need 5V to fully open (the L designates it's a Logic Level one). stp16nf06l will also open at 5V.

irf520 has a Gate Threshold Voltage of between 2.0V and 4.0V. The 5V from the Arduino pin will be at least 1V higher than that, so it may be ok. The danger is that 1V might not be enough to fully switch the MOSFET on, leading to increased heat dissipation and failure. stp16nf06l has a Gate Threshold Voltage of between 1.0V and 2.5V. The 5V from the Arduino pin will be at least 2.5V higher than that, so it should be fully switched on and stay cool.

The irf might be ok. Give it a go.

Your schematic looks fine. For safety put a low value resistor (e.g. 330R) between the Arduino pin and the gate. Also put a 10K pull-down on the Arduino pin to ensure the motor does not come partially on as the Arduino is booting. You might want to use a pwm capable pin in case you want to experiment with running the pump motor more slowly.

Regarding the probe, I was torn between the system above with sporadic readings and using a voltage flipping style probe like here to combat corrosion.

People have great difficulty with soil moisture probes. Many simply don't work in any useful way.

Experiment with different ones (resistive and capacitive), over a period of weeks, and make sure that you have one that actually works before you make the system automatic.

PaulRB: irf520 has a Gate Threshold Voltage of between 2.0V and 4.0V. The 5V from the Arduino pin will be at least 1V higher than that, so it may be ok.

The IRL versions are specifically for logic level, the IRF ones won't open completely (or even enough for the pump to work) at 5V. A major clue is in the data sheet: the IRF520 only gives the Rds(on) for a 10V Vgs. The stp16nf06l gives Rds(on) for both 10V and 5V levels (and the 5V is barely higher than the 10V one).

wvmarle: The IRL versions are specifically for logic level, the IRF ones won't open completely (or even enough for the pump to work) at 5V. A major clue is in the data sheet: the IRF520 only gives the Rds(on) for a 10V Vgs. The stp16nf06l gives Rds(on) for both 10V and 5V levels (and the 5V is barely higher than the 10V one).

@wvmarle Thanks, that's a good tip. Will look for that in mosfet data sheets in future. @stevenblanc you could use that irf520 in combination with your bc547. But for a simpler circuit, get that irl520 or stp16nf06l or something else with a logic level gate.

Thanks folks,

I got it working using the IRF520, as I happened to have a 12V 2A power supply lying around. So far this is working well and I’ve handed over to the probes and I’m getting good results. As discussed, its absolutely dead in the water on 5V, but for the time being this is tolerable. I was hoping to migrate this to a Nano and I suspect there is no way to power a nano at 12V.

I’ll order the 12V solenoids tonight and hopefully have them in by next weekend to test out on the system. I’ll pick up the IRL520 as well and maybe a STP16NF06L as they’re all under a dollar.

Adding multiple sensors is not a problem, but I’m not 100 percent on how to add multiple solenoid valves. Attached in the Pump and Solenoids circuit is how I imagine it working for individual control. I’ll test it out next weekend but if you see a glaring error please let me know.

@wvmarle: Thanks for the tip. I’m learning a lot with this little project!

Cheers,

Steven

As discussed, its absolutely dead in the water on 5V, but for the time being this is tolerable. I was hoping to migrate this to a Nano and I suspect there is no way to power a nano at 12V.

What do you mean dead on 5V? What discussion? On this thread? I don’t remember that. Yes you can run a Nano on 12V

Sometimes I have conversations with myself and think I've spoken to others about it. In this case I was discussing this with myself:

The IRL versions are specifically for logic level, the IRF ones won't open completely (or even enough for the pump to work) at 5V. A major clue is in the data sheet: the IRF520 only gives the Rds(on) for a 10V Vgs. The stp16nf06l gives Rds(on) for both 10V and 5V levels (and the 5V is barely higher than the 10V one).

Using the IRF520, the pump won't come on if I power through USB with a 5.5V power block. I don't have a suitable power supply higher than that, but I'll scout for one and see if I can work through the barrel jack.

It is entirely possible I'm missing something.

Regarding the 12V on the Nano, just did a little looking and I found a couple threads on it. So I'll go through those. Should mean I can shrink the project down when I'm done. I'm trying my very best to keep this to one power source for 2-3 of the solenoids and the pump.

Sounds like you are attempting to run a 12V pump using a 5V supply? If so, that may be nothing to do with the MOSFET, just that the pump won't run at 5V.

Also note that you should not run the power for the pump through the Arduino. The board is not designed for such high currents. Split the cable from the power supply and have separate cables going to the Arduino and to the MOSFET/pump.

|500x380

Things to fix in your circuit:

You can't control a solenoid valve directly with an Arduino pin. You need a transistor of some sort. Post a link to data sheet of the valve you are considering and we can advise what's needed.

You are still missing the 10K pull-down on the Arduino pin controlling the pump.

Analog input pins, like A0, are not the same thing as pwm output pins. You cannot use analogWrite() on A0. (They should not have named the function "analogWrite()". It confuses beginners.)

You seem to be using 2 digital outputs and 1 analog input per soil sensor, plus 2 resistors. This is unessesarily complicated and wastes pins. You can power all your probes with one digital output pin and each sensor will need one analog input pin and one 10K pull-up resistor.

PaulRB: You are still missing the 10K pull-down on the Arduino pin controlling the pump.

Additional info here for OP: this resistor is to pull down the gate of the MOSFET. You should never keep the gate of a MOSFET floating or it may start flipping on and off by itself. This happens when you have the pin in INPUT mode, as is the case upon start-up. In normal operation the pull-down resistor is not doing much if anything, really, as your Arduino pin set to OUTPUT will pull down the gate when set to LOW. It just makes the whole thing that much more reliable.

Solenoids indeed can't be operated from the pin directly, they draw way too much current, use a MOSFET circuit just like the one you use for the pump to drive them. Your pump may or may not run on 5V, connect your pump to your 5V power supply directly to see what happens.

The probe circuit: remove the resistor in the D6 line, it's not needed. Reduce the value in the D7 line to 10k, and connect it to GND instead. I wouldn't connect it to Vcc as suggested, as then you have to switch it off by setting both sides to Vcc. If you have this resistor connected to GND you can switch off the probe by pulling D6 LOW and then the whole thing is connected to GND.

The value of this resistor needs some experimenting. Build a probe, and using a multimeter get some resistance values for your soil between moist (how wet you'd like it to be) and dry (when it's time to water), and take the value that's roughly in the middle.

You can’t control a solenoid valve directly with an Arduino pin. You need a transistor of some sort. Post a link to data sheet of the valve you are considering and we can advise what’s needed.

The solenoid is a 1/4" NPT US solid valve that draws approximately 415mA. Which puts my circuit amperage at about (250mA + 400mA + 415mA + 415mA)
The technical Specifications are here.

Regarding the circuit changes you recommended, see the attached. I don’t have the actual solenoids on me to test but the following should work. I may have to change out the transistors (I have the BC547s on hand) in the diagram for MOSFETs as the solenoids are also operating at 400mA.

Whats the maximum the UNO and Nano boards can handle? I’m guessing about 200mA per GND?

Regarding the probes, I’m using the design found here which fights corrosion by flip flopping the charge. Scroll down to The local circuit - simple, voltage flipping style sensor. I honestly don’t expect this system to cross about 3 probes so:

  • 4 probes = 8 digital / 4 analog
  • 3 solenoids = 3 digital
  • 1 pump = 1 digital
    - Total = 12 digital / 4 analog

That should be fine, the fourth probe will really be the level sensor on the resevoir to prevent the pump running dry. I can use a simpler 1 pin per probe system, but I’ll have to see how long the screws that I’m using as probes hold up in the soil!

@wvmarle: Thanks for the tips, I appreciate the explanation of what these components are doing as I’m fairly new to electronics, mostly following step-by-step tutorials with no idea what I was doing in the past! I haven’t had a chance to actually touch my electronics tonight, but I’ll play with your suggestions regarding the probe resistors. Right now I have a 100 ohm resistor and I’m getting a good range of readings. Mostly I’ve been testing with water but the 100 ohm certainly works as a water level sensor. I’d appreciate your evaluation of the voltage flipping style probes.

Cheers,

Steven

stevenblanc: Whats the maximum the UNO and Nano boards can handle? I'm guessing about 200mA per GND?

That number is more like PER BOARD rather then PER GND (they have multiple GND pins, but they're all connected).

Pumps, solenoids, etc. have to be powered separately, or from an external power supply (where the ground of the power supply has to be connected to the GND of the Arduino and all other grounds). If you have multiple power supplies, link the ground (or 0V) of all of them together, and have them power separate things. You could have e.g. one power supply for the solenoids, one for the pump, and one for the Arduino this way.

That should be fine, the fourth probe will really be the level sensor on the resevoir to prevent the pump running dry. I can use a simpler 1 pin per probe system, but I'll have to see how long the screws that I'm using as probes hold up in the soil!

A 2 pin per probe (one digital to switch the probe on and off, one analog to take the reading) should solve that, provided your power it on for as long as it takes to take the analog reading, then power it off right away. That should keep galvanic corrosion in check.

Voltage flipping (effectively putting an AC through the probe) adds quite some complication. It's got to be done fast (3-10 kHz) to work. I'm doing the exact same thing with my EC probe, took me a month of hard work to get it to work but now it works really well. Big difference with your probe is that I'm not doing it to prevent corrosion, but to prevent electrolyses, as it's measuring an ionic liquid.

  • 4 probes = 8 digital / 4 analog

No. Please listen to what I’m telling you. If you can’t understand, please ask me to clarify. Otherwise please let me know my advice is not wanted. 1 digital output, 4 analog inputs. Corrosion due to current flow will not be a problem because the current flows for < 1ms every 15 mins.

Don’t use Arduono pin D1, it is needed for sketch upload & serial comms with the PC.

Are you planning to have two pumps? Your diagram indicates two of them, connected to pins D1 and A0. I suspect you should remove the top-right section of the diagram.

That 10K will prevent the pump from working. You need a 10K pull-down on the Arduino pin controlling the mosfet.

I would also suggest you keep looking for solenoid valves. The ones you linked to cost too much and draw too much current in comparison to the pump. They are overkill for the job. If you can’t find anything lower cost & power, you might as well have 2 or 3 pumps.

@PaulRB:

No. Please listen to what I’m telling you. If you can’t understand, please ask me to clarify. Otherwise please let me know my advice is not wanted. 1 digital output, 4 analog inputs. Corrosion due to current flow will not be a problem because the current flows for < 1ms every 15 mins.

I’m appreciating your help greatly, but I was focused on the corrosion problem (I might have thrown around the word electrolysis accidentally. Thanks @wmarle for correcting me) and I was under the impression that using your method wouldn’t solve that. Particularly as for testing waiting 15 minutes in between readings will kill me!

Don’t use Arduono pin D1, it is needed for sketch upload & serial comms with the PC.

Noted, but out of curiousity, why do they have it available if it’s used for that? Can it be used for trouble shooting or something?

Are you planning to have two pumps?

No. You’re absolutely correct, I just left the original pump only drawing there for reference. I’ll clean up the drawing and reupload once I clarify:

That 10K will prevent the pump from working. You need a 10K pull-down on the Arduino pin controlling the mosfet.

The arduino pin is the one currently marked as D1 then? As in replace the 330K resistor? I looked up pull down resistors and found this which seemed to indicate that a pulldown had to be attached to the ground.

If you can’t find anything lower cost & power, you might as well have 2 or 3 pumps.

I’m going to look around some more, they are exactly the same price. I went ahead with them because for me this as much a learning project as a practical project. When I read your sentence I thought… wait… you just bought a valve for the same price as the pump! Definitely going to have to work on the acquisition portion of my skillset.

@wmarle:

Pumps, solenoids, etc. have to be powered separately, or from an external power supply

I’ll do a little research on this before I start picking apart your brain on the separate power supplies thing. I really wish I could sit down with an electronic engineer and understand all of this. I keep getting lost along the way. Once I have a draft revised circuit I’ll post it up for review with all the changes above and this part.

I was reallllly hoping to have this whole system powered from one power supply though as I only have one available power socket and I don’t want to rely on a battery pack (Though I want to build it that way as well for learning purposes).

Regarding the level sensor. I would imagine I would have to turn it on right before the pump switches on to take a level check and keep it on as long as the pump is on to ensure the level doesn’t drop below the threshhold. If the level does drop I would also need it sporadically turn it on to check if I’ve refilled the water trough to allow pump function again.

I can deal with this at the code level once the whole circuit is a beautiful efficient and safe masterpiece!

You can set the delay between sampling the sensors to a few seconds for testing. For installation, there's no point doing it more than every 15 mins or so. Every couple of hours might be enough.

A single power supply should be sufficient as long as it has comfortably more current than the pump + valves draw at maximum, and you include some substantial reservoir caps in the circuit, particularly near the Arduino. You could also stagger starting up the pump & valves to minimise current surges.