Skip to Content

How to Control A Water Pump With Arduino

How to Control A Water Pump With Arduino

This article will teach you how to drive a 12V DC motor water pump using Arduino. 

These DC motors are used in aquariums, indoor gardens, and pet water supply applications. 

You can bring in automation to ensure you take care of your plants, especially when you are away from home for a long time. 

Driving the water pump is very easy using Arduino. You don’t need many components to build the water pump controller project from scratch. 

This article will provide a step-by-step guide to building the Arduino-based water pump controller. 

We will also learn the basics of driving a DC motor. We will explore selecting the correct components and using a few safety methods to ensure you can run the project safely for a long time.

In the later sections, you will find the Arduino code for the pump controller and a collection of frequently asked questions about the Arduino-based pump controller projects with answers.

Let’s get started!

Components Needed To Build Arduino And Motor Project

Hardware Components

Software

Makerguides.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to products on Amazon.com.

Basics of Water Motor Control Using Arduino UNO

In this section, we will learn more about the water pump motors, several options available to drive the motors, and a few specifications you should study from the motor and the switch datasheet. 

You can find DC-powered water motors in several applications:

  1. Aquariums – The motors are used to blow fresh air into the water. The fresh air will carry oxygen that gets dissolved in the water. It helps the fish in the aquarium to get more fresh oxygen.
  2. Water motors are also used to filter water cans and aquariums and transfer liquids from one container to another in the labs.
  3. Garden watering – You can have a big container from which you can always pump the water based on the soil sensor data or pre-determined intervals. You can protect plants at home with the help of Arduino UNO (see our automatic plant watering system using Arduino IoT for example)

Options available to drive the motor

In this section, we will see the options available to drive a DC motor. Let’s get started. 

Dedicated Motor Driver modules

You can see dedicated motor driver ICs to drive the motor. One such example of motor driver IC is L298D IC.

Dedicated Motor Driver modules
  • Driver chip used in the board is L298 dual H-bridge driver IC
  • The Ic can accept voltage up to 35V DC
  • Can support motors with current requirement up to 2 A
  • Aduino UNO compatible logical pins

There are several modules you can find such as L9110S, for example.

L9110S driver board

The L9110S driver board has the following features. 

  • There are two L9110 motor ICs on the board
  • The module can drive dual DC motors in parallel
  • Operating voltage up to 12 V
  • Supports current up to 800 mA

For most of the simple projects, the ready made board may be an over design.

Let’s see the second method of driving simple, low voltage DC motors.

MOSFET based switch

You can use a MOSFET as a switch. You can turn on or off the MOSFET using Arduino UNO GPIO pins.

The MOSFET acts like a switch. If the PWM output in voltage is 5 V, the MOSFET turns on. 

It is similar to a closed switch. The current can flow from the supply voltage (4.8 V) to the ground via the motor. The motor turns on. 

When you want the motor to stop, you send a logic 0 ( 0 V) on the PWM output pin. The MOSFET turns off. Now, it is similar to an open switch.

Hence you break the connection between the motor and the ground. The motor stops running. 

You can also control the speed of the motor in the same way you can vary the brightness of the LED using PWM signals.

control the speed of the motor

If the duty cycle is low, the average voltage is low. Hence the motor runs at lower speed. If the duty cycle is higher, the average voltage will be higher. Hence the motor runs faster.

Notice that there is a diode connected across the motor. The purpose of the diode is to protect the MOSFET and the Arduino UNO.

Every motor acts like an inductor. The inductor doesn’t like a sudden change in the current. 

When you stop a motor suddenly, the inductance in the motor tries to keep the current going on. It can convert the stored magnetic field into a reverse voltage to keep the current going. 

In cases where you don’t have a diode, this high voltage can create an arc and spoil the connected MOSFET and other low-voltage devices.

In many instances, I have seen harming the microcontrollers, MOSFETs which are part of the driving circuitry. 

The advantage of the MOSFET based motor driving is that you only need a very few components.

It is easy to build and takes very little space.

Selecting a right MOSFET for your project

Let’s have a look at the datasheet for a generic motor. The motor operates with a voltage range of 3 V to 6 V. The current consumption is not more than 220 mA. 

You must find a generic MOSFET that you can use as a switch. The main parameter you should look out for is the current rating.

The MOSFET should be at least capable of handling 500 mA of current. 

In the next section, we will build the circuit using a MOSFET as a switch.

Step-By-Step Instructions To Connect The Water Motor To The Arduino UNO

In this section, we will build a project using an Arduino UNO based water motor project.

The FET we have chosen can handle the required motor current. You need to use a PWM compatible pin of the Arduino UNO.

I am using Pin 3 of the UNO since it is PWM compatible.

How To Connect The Water Pump To The Arduino UNO?

Below is the step-by-step guide to complete the hardware connections needed to connect the Arduino and the water motor together with the MOSFET.  

Step 1: Connect the Motor to the MOSFET

Connect the Motor to the MOSFET

Connect the ground cable of the motor to the drain pin of the MOSFET. 

Step 2: Connect the Ground Pin

Connect the Ground Pin

Connect the MOSFET’s source pin to the Ground.

Step 3: Connect the MOSFET’s gate pin

Connect the MOSFET’s gate pin

Connect the Arduino UNO’s pin 3 to the gate of the MOSFET.

Step 4: Connect the resistor between Gate and the ground

Connect the resistor between Gate and the ground

Choose a resistor value between 2 kOhms to 100 kOhms. I have connected a 10 kOhms resistor. 

Connecting the resistor between the ground and the GATE helps keep the MOSFET in OFF condition when the Arduino is not connected or accidentally the gate connection between the Arduino UNO and the GATE pin of the MOSFET opens. 

Step 5: Connect the diode across the motor cable

Connect the diode across the motor cable

Notice the diode connections. The anode of the diode goes to the negative terminal of the motor. 

The cathode of the diode goes to the positive terminal of the motor.

Connect the positive supply voltage to the DC motor’s positive cable (red).

Make sure the voltage rating matches the supply voltage. 

Step 6: Verify the complete connections

Verify the complete connections

Congratulations, you have completed the required connections, connecting the water motor and the MOSFET switch to the Arduino.

Next we will take a look at some example code you can use to bring the project to life.

Arduino Code Example For The Arduino And The Water Pump Project

This section will walk through the example Arduino code to test the water pump circuit. Be careful while working and take all precautions. 

Safety Warning: When you work with water, ensure you keep the electronics away from moisture and water 100% of the time.

Project 1: Motor ON OFF Code

The Below code is simple and straightforward to understand. You work with the MOSFET the same way you try to power on a LED.

When you want to turn on the motor, drive logic 1 (5 V0 to the MOSFET gate and vice versa.

const int RELAY_PIN = 3;  // the Arduino pin, which connects to the gate pin of MOSFET

void setup() {
  // initialize digital pin A5 as an output.
  pinMode(RELAY_PIN, OUTPUT);
}

void loop() {
  digitalWrite(RELAY_PIN, HIGH); // turn on pump 5 seconds
  delay(5000);
  digitalWrite(RELAY_PIN, LOW);  // turn off pump 5 seconds
  delay(5000);
}

Project 2: Automatic Water Level Controller

The below circuit connects Arduino UNO to the motor, a display unit, and a host of sensors. The Arduino will run the motor to fill the tank.

Analog pins are used to sense the water level.

A 16 x 2 LCD provides good options to display the controller’s status.

#include "LiquidCrystal.h"

int sump = A0;
int qut = A1;
int hlf = A2;
int thf = A3;
int ful = A4;
int motor = 8;
int buz = 7;
int s;
int q;
int h;
int t;
int f;
int i;     //motor status flag
int v = 100; //comparison variable(needs some adjustment)
int b = 0; //buzzer flag
int m = 0; //motor flag
int c = 0; //sump flag

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup()
{
  pinMode(qut, INPUT);
  pinMode(hlf, INPUT);
  pinMode(qut, INPUT);
  pinMode(ful, INPUT);
  pinMode(sump, INPUT);
  pinMode(motor, OUTPUT);
  pinMode(buz, OUTPUT);
  lcd.begin(16, 2);
  digitalWrite(buz, LOW);
}

void loop()
{
  i = digitalRead(motor);
  s = analogRead(sump);
  q = analogRead(qut);
  h = analogRead(hlf);
  t = analogRead(thf);
  f = analogRead(ful);
  lcd.clear();

  if (f > v && t > v && h > v && q > v )
  {
    lcd.setCursor(0, 0);
    lcd.print(char(219));
    lcd.print(char(219));
    lcd.print(char(219));
    lcd.print(char(219));
    lcd.setCursor(5, 0);
    lcd.print("FULL");
    m = 0;
    b = 0;
  }
  else
  {
    if (f < v && t > v && h > v && q > v)
    {
      lcd.setCursor(0, 0);
      lcd.print(char(219));
      lcd.print(char(219));
      lcd.print(char(219));
      lcd.print("_");
      lcd.setCursor(5, 0);
      lcd.print("3/4th");
      b = 0;
    }
    else
    {
      if (f < v && t < v && h > v && q > v)
      {
        lcd.setCursor(0, 0);
        lcd.print(char(219));
        lcd.print(char(219));
        lcd.print("_");
        lcd.print("_");
        lcd.setCursor(5, 0);
        lcd.print("HALF");
        m = 1;
        b = 0;
      }
      else if (f < v && t < v && h < v && q > v)
      {
        lcd.setCursor(0, 0);
        lcd.print(char(219));
        lcd.print("_");
        lcd.print("_");
        lcd.print("_");
        lcd.setCursor(5, 0);
        lcd.print("1/4th");
        b = 0;
      }
      else
      {
        if (f < v && t < v && h < v && q < v)
        {
          lcd.setCursor(0, 0);
          lcd.print("_");
          lcd.print("_");
          lcd.print("_");
          lcd.print("_");
          lcd.setCursor(5, 0);
          lcd.print("LOW");
          b = 0;
        }
        else
        {
          digitalWrite(motor, LOW);
          lcd.setCursor(0, 0);
          lcd.print("ERROR!");
          b = 1;
        }
      }
    }
  }
  if (i == HIGH)
  {
    lcd.setCursor(0, 1);
    lcd.print("Motor ON");
  }
  else
  {
    lcd.setCursor(0, 1);
    lcd.print("Motor OFF");
  }
  if (s > v && m == 1)
  {
    digitalWrite(motor, HIGH);
  }
  if (s < v)
  {
    digitalWrite(motor, LOW);
    lcd.setCursor(11, 0);
    lcd.print("Low");
    lcd.setCursor(11, 1);
    lcd.print("Sump");
    c = 1;
  }
  if (s > v)
  {
    c = 0;
  }
  if (m == 0)
  {
    digitalWrite(motor, LOW);
  }
  if (b == 1 || c == 1)
  {
    digitalWrite(buz, HIGH);
    delay(500);
    digitalWrite(buz, LOW);
  }
  else
  {
    digitalWrite(buz, LOW);
  }
  delay(100);
  lcd.clear();
}

FAQs About Arduino And Water Motor Control Projects

I have included a list of the most frequently asked questions about projects built using Arduino and the water pump controller.

If you have further questions, kindly post them in the comments section.

I will be glad to answer them. 

1. How many motors can an Arduino Control?

Arduino can control motors used for various applications. You can use motor controller ICs, which reduce the Arduino’s burden and provide multiple safety and valuable features.

This article taught us the easiest way to control the motor using a MOSFET as a switch. 

If you use an Arduino UNO to control the Motor, as we did in the article, you can control more than 15 motors.

Please ensure you select the proper power supply to power all the motors.

2. How does an Arduino control the direction of the Motor?

The Arduino can control the direction of the motor. If you are controlling a toy car using a DC motor, you can change the direction of the motor.

To change the direction of the motor, you have to use an H bridge.

An H bridge is a simple circuit you can build using 4 transistors. 

3. Can Arduino power a water pump?

Yes. Arduino can power a water pump. In this article, we powered a water pump to water the garden.

Usually, the water pumps will consume more power than the Arduino 5 V pin can supply.

If you carefully choose the proper power supply, you can power a water pump using Arduino. 

You can use dedicated motor control drives or a transistor as a switch to control the motor supplied by a separate power supply. 

4. How do you use a 12-volt water pump with Arduino?

You can use a 12 V water pump with Arduino. To power the motor, you can use a FET or a transistor as a switch.

12-volt water pump with Arduino

You can control the TIP102 BJT in the image above using a digital pin. In the figure STM32 Digital pin can be any Arduino pin as well.

The motor will turn on when you drive a logic 1 to the TIP 120 transistor. 

Conclusion

We learned how to control a water pump in this project. I hope you can follow the connection steps and complete the water pump control application.

The Arduino code presented is easy to straightforward to understand. 

You can use this experience to bring the Internet of Things to garden watering. 

You can schedule when to water the plants based on the data from the soil sensor and weather forecast!

Check out our project for an automated plant watering system using Arduino and IoT here.

Please post your questions on the motor control in the comments section.

Please let me know if you need help building the projects in the comments section.

I am always happy to answer them. 

If you have any feedback to improve the article, please share it in the comments section.

Your valuable input helps me to improve the article style and bring more helpful articles down the line. 

Please remember to share the article with your fellow Arduino enthusiasts.