Run a 12V water pump for 10 or 20 seconds after pressing a button

Hello Community,

first of all I would like to introduce myself, as I have just registered. I am Johannes from Germany and my interests are CAD, CNC and additive manufacturing. Unfortunately I have only little experience with Arduino. I have programmed boards for 3d printers 15 years ago, but so much has changed in that time that I need your help.

About my project:

I would like to run a 12V water pump for 10 or 20 seconds after pressing a button. I assume the time can be set exactly in the software/code?

Can you tell me what to look for on google to get help? Or even better, does anyone here know which Arduino board I need and how I can possibly create the code with ChatGPT? or is that not how it's done? I am infinitely grateful for your help! This is a home and hobby project so there is no time pressure and I can spend some money without any problems.

Have a good time
Johannes

Download the IDE to Your computer.
Look into the example codes for buttons, and look for motor or solenoid examples.
Any Arduino would manage but needs a driver for the motor.

To accomplish what you’ve described is a very simple project. It wouldn’t even need an Arduino at all, just a few basic components.

But if you also want to renew your interest in Arduino and electronics as a hobby, then as @Railroader says you should start with the basics. I would suggest stepping through the example sketches at your own pace until you know enough to build your pump project.

Precisely enough for controlling a water pump, yes.

I would recommend a Nano V3 (ATMEGA328) for beginners. Don't buy an Arduino kit, they are full of junk. Get a large breadboard on which to build your prototype circuit. Also some resistors with values like 330R, 10K, a few 5mm LEDs, a few 1N400x diodes, a few pushbuttons...

No Arduino can control a 12V pump directly, so you will need a component to go between the Arduino and the pump. An IRLZ44 MOSFET would be a suitable choice.

Best avoided. The code will not be difficult for someone with technical skills. There are lots of code examples available in the IDE menu. The forum can help as needed if you get stuck.

For wiring your circuit on breadboard, I would recommend using solid-core hook-up wire and avoid Dupont wires as much as possible. Get several colours including red and black. Get a wire cutting & stripping tool and a pair of small, fine pliers. You can then cut wires to the correct length and lay them flat on the breadboard. This results in a much neater, robust breadboard prototype.

Oh, you are so quick...

So I've now bought an Arduino pro Mini and a DC motor driver up to 45V. Plus a breadboard, cables and connectors.
I hope I can work with it.

Then I'll try the standard codes for switches and buttons, I had actually forgotten that these standard directories exist.

thank you all very much!
I will be happy to let you know if there is any progress.

Johannes

Hopefully you bought USB-serial converter as well...

2 Likes

Why? Did you have a particular reason for deciding against the recommendation given in post #4? Do you know how to program a Pro Mini?

By 'standard codes' I assume you mean 'sketches'.?

By 'standard directories' I assume you mean 'sketches'?

I'll repeat the recommendation I made in post #3,.

Hey,

That's right, I decided in favour of the mini against the recommendation because it's just so nice and small. Was that a mistake?

I just realised it was a mistake, it doesn't have a USB port, oh crap. Yes well ok....

Is there a small board that is good for me? It's really best if it's nice and small and narrow like the Pro Mini.

Yes I mean the sketches, thanks I missed that word.....

Thanks for the tips, I've just learnt something :folded_hands:t2::+1:t2:

Johannes

Hey again,

I just saw that I mixed up the nano and the uno v.3.....

My mistake! The recommendation is great! The nano is perfect.

Sorry for the confusion

Were you able to cancel the order for Pro Mini? If not, don't waste them. Just get a USB-Serial adaptor. A few more wires to connect, but once you have done that, it's almost exactly same as Nano.

You don't need to buy 4x USB-Serial adapters, you can re-use the same one with the other Pro Mini in other projects.


If your PC/laptop runs windoze, it may be safer to go for one that uses an FT232 chip. If you run Linux, you can alternatively choose CP2102 or CH340 chips, they all seem to work well with Linux.

1 Like

Hi,

I now know again why first I ordered the Arduino pro mini, it can also get 12v directly...

It doesn't matter now because the nano is here and the motor drivers are here and the stepdown 12v to 5v have also been delivered.
Unfortunately I have cancer and have to go to the doctor a lot this week, so I won't be able to put the parts into operation until the weekend.

Many thanks for your help!
Johannes

Nano can take 12V on VIN as well. They both likely use same/similar voltage regulator.

1 Like

Hi,

const int ButtonPin = 2;
const int RelayPin = 3;

void setup() {
    pinMode(ButtonPin, INPUT_PULLUP);

    digitalWrite(RelayPin, LOW);
    pinMode(RelayPin, OUTPUT);
}

void loop() {
    if (digitalRead(ButtonPin) == LOW) { // If button to Ground is closed
        digitalWrite(RelayPin, HIGH);  // Turn on relay
        delay(13000);  // Wait 13 seconds
        digitalWrite(RelayPin, LOW);   // Tun off relay
    }
}

this code works fine!!!

but I can't get it to run with two buttons. I have tried it with definition of button1 and button2 triggering the same output and the same relay.

I want it to run like this:
When I press button 1 (PIN2) - the water pump runs for 13 seconds.
when I press button 2 (PIN4)- the water pump runs for 20 seconds

Relay Pin is PIN3

two buttons, but only one output to the relay for the Motor control.

Maybe you can modify the code to help me.

Thank you very much
Johannes

Please show us your modified code so we can see what is wrong with it.

const int ButtonPin1 = 2;
const int ButtonPin2 = 4;
const int RelayPin = 3;

void setup() {
    pinMode(ButtonPin1, INPUT_PULLUP);

    digitalWrite(RelayPin, LOW);
    pinMode(RelayPin, OUTPUT);

    pinMode(ButtonPin2, INPUT_PULLUP);

    digitalWrite(RelayPin, LOW);
    pinMode(RelayPin, OUTPUT);
}

void loop() {
    if (digitalRead(ButtonPin1) == LOW) { // If button1 to Ground is closed
        digitalWrite(RelayPin, HIGH);  // Turn on relay
        delay(13000);  // Wait 13 seconds
        digitalWrite(RelayPin, LOW);   // Tun off relay
    


        if (digitalRead(ButtonPin2) == LOW) { // If button2 to Ground is closed
        digitalWrite(RelayPin, HIGH);  // Turn on relay
        delay(20000);  // Wait 20 seconds
        digitalWrite(RelayPin, LOW);   // Tun off relay
}

I just tried to add a new switch in the same scheme, but I don't think it works that way...
I feel so stupid, I just don't understand the basics anymore.

so it doesn't work like that with that code?

Hi,

no the Code is not working, no Buttons are working not even Button1, which was working pretty good with the first code.

the "not working code" again:

const int ButtonPin1 = 2;
const int ButtonPin2 = 4;
const int RelayPin = 3;

void setup() {
    pinMode(ButtonPin1, INPUT_PULLUP);

    digitalWrite(RelayPin, LOW);
    pinMode(RelayPin, OUTPUT);

    pinMode(ButtonPin2, INPUT_PULLUP);

    digitalWrite(RelayPin, LOW);
    pinMode(RelayPin, OUTPUT);
}

void loop() {
    if (digitalRead(ButtonPin1) == LOW)  // If button1 to Ground is closed
        digitalWrite(RelayPin, HIGH);  // Turn on relay
        delay(13000);  // Wait 13 seconds
        digitalWrite(RelayPin, LOW);   // Tun off relay
    


        if (digitalRead(ButtonPin2) == LOW)  // If button2 to Ground is closed
        digitalWrite(RelayPin, HIGH);  // Turn on relay
        delay(20000);  // Wait 20 seconds
        digitalWrite(RelayPin, LOW);   // Tun off relay

}

Can you see whats wrong here?
Arduino gives no Errorcode or what ever, the code is compiling with no problem.