Control water pump

Dear forum,
Being fairly new to the world of Arduino I seek your guidance on a simple project I would like to bring to life: running a 12V pump to water a plant. Every time I visit my boyfriend I have to water his ONE plant. Been playing around with Arduino for 2 months and thought I try to create something useful of my own!
My level of Arduino experience is that I've done most of the projects in "Getting started with Arduino" (except for the last big project with the water valves) and most of the projects in the Arduino starter kit.
I have also bought an RTC (DS3231N) and played around with the LCD lib to create a digital clock.

My idea for the project is to have a pump take water from a reservoir and water the plant every 3-4 days. I could to this with a long delay or would it be any benefit to use the RTC?
I want this project to be a living one that I will keep on improving, adding sensors later to measure the soil moisture etc. For now I'm just happy to run the pump without killing my sweet little board :slight_smile:

I have ordered a pump from Amazon Germany (Amazon is not available in my country).
Link to pump
I do not speak very good German, but Google helped me translate enough to understand that this pump hopefully works for my project.
"DC6-12V (recommended 9V 1A; 12V-1A) 6W / H 1.5-2L / min... It can used for Water or Air"

To run the pump I need to use a 12V supply and MOSFET to avoid killing my Arduino. Here I'm a bit lost as my skills in electronics is at a beginner level. The ones supplied in my starter kit reads "IRF520", could I use them for to run this project? I have tried to read the datasheet, but boy it's a bit over my head right now. Have I understood it correctly that the pump runs on 12V 1A and that the IRF520 can take that load?
I found a page that supply a tutorial on how to run a 12V DC motor and write:
"You can also use an IRF510 or IRF520 MOSFET transistor for this. They have the same pin configuration as the TIP120, and perform similarly. They can handle more amperage and voltage, but are more sensitive to static electricity damage."

Based on what I learned from the tutorial I drew for the first time in Fritzing (I understand some of you hardcore electronics gurus want real schematics, it is just too hard for me to draw one of those at the moment). I based my drawing on this guide. If you scroll almost to the bottom you find it. They used a potentiometer, which I do not need.
I have attached the picture below.

I'm really thankful for all the help I could get. I'm not looking for someone to post a finished code and a fixed drawing on how to connect it: I just want to get pointed in the right direction and learn as much as possible on the way.

Andrea :-*

[u]Here is a schematic[/u] of a MOSFET motor driver.

You can also use an IRF510 or IRF520 MOSFET transistor for this. They have the same pin configuration as the TIP120, and perform similarly.

I'd say "somewhat similarly". Both allow you to control a higher voltage & current with a lower voltage & current. Bipolar transistors are current-operated and MOSFETs are voltage-operated. As a general rule you can't drop-in a MOSFET as a replacement for regular transistor, but you might be able to use a MOSFET with some slight circuit changes.

I could to this with a long delay or would it be any benefit to use the RTC?

It's obviously a lot easier & cheaper without an RTC. The Arduino's built-in clock/timer isn't as accurate so the time will drift, but the plant doesn't care what time of day it gets watered.

On the other hand, you've already made a clock, and adding a timer easy. I'd say the main advantage is that you have an LCD, so it's easier to add a user interface and make the watering-timer stand-alone. Without the LCD, you'd need to use a computer to set the watering time/interval.

...adding sensors later to measure the soil moisture etc.

From what I've read, most moisture sensors tend to corrode and give you unreliable results. It might be worth a try, and it might be fun to try, and maybe it will work but you'll have to experiment. There are people here on the forum making watering systems, so hopefully you can get some better information & advice.

no need for a delay or an RTC. just use the Arduino millis() function.

since the plant does not care how many minutes too soon or too long, your time can be 1 hour off and the plant would still be happy.

considder this pump.

can run on batteries or a solar panel.

put it in a small container near the plant ( it cannot pump water a meter over the reservoir)
the container should hold enough water for 2 weeks.

here is a simple sketch.

it uses millis() to time out. it will water the plant every 48 hours after power comes on. that means 48 hours after you plug it in, and then, 48 hours later, or 48 hours after you lose power and power is turned back on.

while I am writing this, I think I would change so that it starts watering as soon as it is plugged in, then count for 48 hours.

const int pump = 6;  // can be any pin


unsigned long currentMillis;
unsigned long previousMillis;
unsigned long duration;
unsigned long hour = 3600000UL; // one hour
unsigned long duration2 ;
unsigned long pumpstart ;

int counter = 0;



void setup() {
  pinMode (pump, OUTPUT) ;
  duration = millis();
}

void loop() {


  duration = millis() - previousMillis;
  
  if (duration >= hour) {
    duration = millis() ;   // resets to now
    counter ++ ;            // adds 1 for each elapsed hour
  }

  if(counter >= 48){           // over 48 hours from last Arudino power ON or last rollover 
    counter = 0;               // resets counter to 0
    digitalWrite(pump,HIGH);   // turns pump on
    pumpstart = millis() ;     // sets pump start time to now
  }

duration2 = pumpstart- millis() ; // sets the duration2 time

if (pump == HIGH) {              // check to see if pump is running
   if (duration2 >= 60000 ){     // 1000 = 1 second
      digitalWrite(pump,LOW);    // turns pump off
      }
} 


} // end loop

maybe change setup to

void setup() {
  pinMode (pump, OUTPUT) ;
  duration = millis()+ 3599930UL;  // sets to 30 seconds before rollover
  hour = 47 ;
}

Hello,

That MOSFET you mentioned is not really suitable. It does not have a "logic level gate" and will not switch fully on with the 5V signal from the Arduino. As a result it may get hot and fail and won't run the pump as efficiently.

A better MOSFET would stp36nf06l or something else in a to220 package with a logic level gate.

The stp36nf06l has a diode built in to protect it from the reverse voltage that is generated when the motor stops, but I would add an extra one anyway such as in1004.

It's all explained in more detail in that link you were given in the first reply.

Paul

1N4001?

baeckman:
I have ordered a pump from Amazon Germany (Amazon is not available in my country).
Link to pump
I do not speak very good German, but Google helped me translate enough to understand that this pump hopefully works for my project.
"DC6-12V (recommended 9V 1A; 12V-1A) 6W / H 1.5-2L / min... It can used for Water or Air"

you can copy the words and search e-bay or the internet to find a similar unit in your language.

this pump is listed at 1.5 to 2 L per minute.
that is a lot of water if you let it run for a full 60 seconds.
I would test how much it puts out when the resouviuor is full, and when it is empty.

Good evening everyone!
Thank you all for taking your time to answer my thread. I have been away from my computer today, but kept reading from my telephone and reading up on links you posted.

considder this pump.

1pcs Mini Micro Submersible Motor Pump Water PUMPS DC 3-6v 120l/h Low for sale online | eBay

I have already ordered the pump from Amazon.de I posted. Reason I choose that one is because it can run without water, just a backup if the reservoir is empty (which most likely will be the case unless I keep it filled).

Here is a schematic of a MOSFET motor driver.

DVDdoug, superb link!

I checked gammon.com and what you all wrote here in the thread regarding MOSFET. The IRF520 needs 10V to run stable. For my purpose I need a logic-level MOSFET that runs properly on 5V, PaulRB suggested stp36nf06l. Will order one tomorrow and it should arrive by the time I receive the pump.

On gammon.com they use a 150 ohm resistor to limit the gate current and a 10k as pull-down. I have checked the schematic they provide and I think I start to understand it, I attached a new drawing with added resistors.

The stp36nf06l has a diode built in... but I would add an extra one anyway...

In my drawing I have two diodes. If the MOSFET has one built in, should I remove one instead of using three? If so, which one? (I would guess it's the one closest to the motor/pump).

no need for a delay or an RTC. just use the Arduino millis() function.

One of the reasons I asked about the RTC was that I don't know how much vibration and sound the pump makes. Even if it only needs to be on for a few seconds (1½L - 2L p/min waters a plant quick) it might be disturbing at nighttime if the plant is close to bed.
And I was also just proud I managed to get the RTC to work and would like to incorporate it in some "real" project :slight_smile:

Thank you for your code, dave-in-nj. I want to create my own one, but it is really nice to have something to look at for tips once I start writing!

It's getting late here, tired after a long day. Should have gone to bed hours ago but I really wanted to answer the thread before I go to sleep.

Good night!
Andrea :-*

groundfungus:
1N4001?

Yes, you are absolutely collect!

I did mean 4001 not 1004, if there is such a thing!

baeckman:
In my drawing I have two diodes. If the MOSFET has one built in, should I remove one instead of using three? If so, which one? (I would guess it's the one closest to the motor/pump).

Andrea, not sure what purpose your diodes are fulfilling. The important thing is to have a diode that allows any reverse current generated when the motor stops to be shorted. So the diode should be across the motor terminals, in the direction that allows any current to flow in the reverse direction to that which it would flow when the motor is running. Ignore my comment about the stp36 having a built-in diode, that was a "red herring" (thanks Leo).

@ Andrea
Better ignore everything from https://itp.nyu.edu/physcomp...
Those pages are full off hardware blunders.
Here's one about connecting a NPN transistor to an Arduino pin:
"You can generally connect the base to a microcontroller’s pin directly without a current limiting resistor because the current from the pin is low enough."
And another one:
"You also need to add a diode in parallel with the collector and emitter of the transistor, pointing away from ground. The diode to protects the transistor from back voltage generated when the motor shuts off".
Edited by Tom Igoe...
That dude needs to go back to school again.
Leo..

baeckman:
On gammon.com they use a 150 ohm resistor to limit the gate current and a 10k as pull-down. I have checked the schematic they provide and I think I start to understand it, I attached a new drawing with added resistors.

can you change view on Fritzring and get a schematic view ?

I have already ordered the pump from Amazon.de I posted. Reason I choose that one is because it can run without water, just a backup if the reservoir is empty (which most likely will be the case unless I keep it filled).

good pump choice. I missed the part of it running when out of water.

you can use a current sensor to watch current to the motor.
the current when dry is different than when there is water. then chose to not run, or maybe beep a little beep to say it is out of water.

as you grow the project, add wifi and send you a message whenever it is low.

If you have a non-logic level FET, you can use a small transistor to make it work.

FET with NPN.jpg

If you have a logic level FET, you just need to make sure the gate has a pull-down.
here is the schematic with the internal diode. this is not the same as above that has a separate diode, in reverse, across the motor.

logoc level FET.jpg

IRL530 this is the logic level version of the one you have

yet another FET is the AOI514 about 50 cents from digikey

[ edit was made to change resistor values as per next post , thanks PaulRB ]
[ removed reference to FET model, per following posts, thanks Wawa. ]

btw, I really hate ubunto because it lacks any decent drawing programs. spent more time moving things using pinta than it would have taken in ms paint.

observation... I posted the pics in the post, but the stats say they were also downloaded over 50 times.

Should R1 be 220R rather than 220K?

Yes.
And a different fet.
The BUZ11 is not a logic level fet.
Leo..

dave-in-nj:
btw, I really hate ubunto because it lacks any decent drawing programs. spent more time moving things using pinta than it would have taken in ms paint.

Try going back to Windows and then see which you hate more! I am a member of a maker group where there are a few Arduino enthusiasts. They all use Win 7 or 10 and I'm the only one there using Ubuntu. I can compile and upload sketches several times over before most of those windows laptops have done it once.

For schematics, Eagle is free and runs fine on Ubuntu. As does Fritzing, which does in fact have a proper schematic editor as well as the "cartoon" breadboard mode that newbies love so much and everyone else seems to hate.

PaulRB:
Try going back to Windows and then see which you hate more! I am a member of a maker group where there are a few Arduino enthusiasts. They all use Win 7 or 10 and I'm the only one there using Ubuntu. I can compile and upload sketches several times over before most of those windows laptops have done it once.

For schematics, Eagle is free and runs fine on Ubuntu. As does Fritzing, which does in fact have a proper schematic editor as well as the "cartoon" breadboard mode that newbies love so much and everyone else seems to hate.

I dislike the libreOffice word processor. I believe that 99% of the users only need some of the capabilities, but you have to take them all or nothing. Windoz is no better.

pinto is half way there and twice the capabilities as it has layers. seems more like it is incomplete. guess you get what you pay for !

Ubunto has built in driver for my usb chip, windoz does not
no problems with Arduino IDE on ubuntu, but the IDE no longer supports win-xp.
wondows does not recognise the 340 usb chip, so one has to download a Chinese driver.
cannot play balloons tower defense as there is no flash on unbuntu. sigh....
and I cannot get the 64 bit liveCD because I installed the 32 bit and it knows better than to allow me to change.
ubunto speal cheaker is less than roubust. but it could be the one on this forum.
kicadd is free on ubuntu.

I am perfectly happy with both, and not happy with either.

Hello everybody!
I tried to understand the schematic dave-in-nj posted and redid my work in Fritzing, I also tried to draw my own schematic.

Am I getting closer?

The schematic shows R1 1k ohm resistor. PaulRB writes "Should R1 be 220R rather than 220K?".

Andrea :-*

That looks almost correct. Value of R1 is not too critical, 220R or 1K will be fine. However, the 10K should be connected directly to the Arduino pin, i.e. to the left of the 220R in your diagram.

It will probably work as you have shown it, but the 220R and 10K form a voltage divider, resulting in slightly less than 5V at the MOSFET gate. This should still switch most logic-level MOSFETs on OK, but it would be more correct to make the change I suggested.

I take it that you only wish to turn the pump on and off, you do not want to control the speed of the pump with PWM? I cannot see a need to do that with a simple plant watering circuit. You can control the amount of water dispensed simply by controlling the length of time the pump is switched on (at full speed).

Also, if you have not purchased that pump yet, there is another approach you could consider, which might be cheaper and use less power.

Raise the water reservoir so that the water can flow under gravity to water the plant(s). Control the flow with a solenoid valve.