Automatic Watering System for Plants using Arduino


After completing this tutorial you will be able to-
  • Connect Soil Moisture Sensor, Relay and water motor to Arduino Uno.
  • Connect relay to Arduino Uno.


Lets make an automatic watering system. This project is an extension of our prior experiment, where you learned how to connect moisture sensor to Arduino. This time we are also going to connect a relay and water motor to the Arduino. We will then write a program to take input from soil moisture sensor and switch on or switch off the water motor based on the data received from soil moisture sensor.

What will I learn from this video and post?
  1. Connect Soil Moisture Sensor, Relay and water motor to Arduino Uno.
  2. Write a program to accept input from soil moisture sensor and switch on or switch off water motor.
  3. Explain the source code.

What is Automatic Watering System for plants?

The automatic watering system helps you to water plants at your home, garden or farm in your absence. It uses technology to detect the moisture level of the soil and automatically water the plant when there is no moisture detected in the soil.

Can I make one myself?

Yes, this is what learn by watch do, helps you to learn to do things yourself. We have created a video and this post to show you the procedure to make it on your own. If you will follow both carefully you will be able to make it yourself. If you face any problem as in the comment. You can also ask us for the paid services.

How long does it take to make an automatic watering system myself?

It depends on your prior knowledge and experience with Arduino. If you are new to that and follow the video and instructions given in this post, you should be able to make it within a day. But if you are planning to showcase in some science exhibition, We recommend you to start at least one week prior to the deadline.

What are the required components?

The required components are given below. We have also provided links to buy the components from Amazon and Flipkart so you do not have to waste your time in search for the right component.

  1. Arduino Uno R3: |
  2. Soil moisture sensor: |
  3. Buzzer:
  4. 4 Channel Relay for Arduino: |
  5. Jumper wires: |

Source code

int ACWATERPUMP = 13; //You can remove this line, it has no use in the program.
int sensor = 8; //You can remove this line, it has no use in the program.
int val; //This variable stores the value received from Soil moisture sensor.
void setup() {
  pinMode(13,OUTPUT); //Set pin 13 as OUTPUT pin, to send signal to relay
  pinMode(8,INPUT); //Set pin 8 as input pin, to receive data from Soil moisture sensor.

void loop() { 
  val = digitalRead(8);  //Read data from soil moisture sensor  
  if(val == LOW) 
  digitalWrite(13,LOW); //if soil moisture sensor provides LOW value send LOW value to relay
  digitalWrite(13,HIGH); //if soil moisture sensor provides HIGH value send HIGH value to relay
  delay(400); //Wait for few second and then continue the loop.

Frequently Asked Questions

Why to use arduino?
“Connect sensor signal to relay module and finished… The code does only that thing anyway.”
The idea is to teach students how to make use of sensor data using Arduino. It will be useful to the students when they build something complex. We will also extend this project in our future videos.
Arduino was programmed or we have to programme it?
You have to program the Arduino and the programming (source code) is given in this post (see above). Also check: How to Connect an Arduino to PC or Laptop.
Error! it expected an initializer before WATER
First and second line are not being used in the program, so you can remove them. Also, there is an error in writing the variable name so replace AC WATER PUMP to ACWATERPUMP and it will work perfectly.
Which version of Arduino will work?
Since we are using only two pins, any Arduino will work for the project.
Which pump can I use, 12v or 5v?
We are using AC pump with the relay and recommend you for the same.
Can I make it for more than 1 plant?
Yes you can and we will show it in our next project.
Why did you killed the plant?
I am a plant lover, this is one of my hobby. So, you can’t expect me to kill a plant. The plant used in this video is safe and still at my home 🙂

Required Material to make it yourself

Pursuing Diploma in Electronics from RBS govt. polytechnic college, Bichpuri, Agra. He loves to play with electronics equipment. He makes electronics project for Learn By Watch and helps other electronics students to build electronics projects for science fairs and exhibition.


    • Hi, there was a problem in first line. Replace AC WATER PUMP with ACWATERPUMP and the program should work. Infact you can remove first two lines of the program and it should work perfectly.

  1. Hii sir actually we are doing a project similar to your’s. That we can water a plant at regular intervals of time including detection of moisture. briefly, if you have a habit of watering plants daily at 5 pm even in your absence the motor should on automatically and water the plants. The amount of water should be watered to the plants are based upon the moisture content in the soil. Please help us sir as early as possible.

    • A relay is an electromagnetic switch operated by a relatively small electric current that can turn on or off a much larger electric current. So, you need relay only if you want to operate AC devices. You can directly send the signal (current) to DC motor, you do not need relay for that.

      Let me know if this is helpful.

  2. sir actually we are doing an project similar to this but we want to know how to change the angle of the water pipe if we have 2 or more plants so that it can water the plant which has less moisture.

  3. sir, i followed your steps and connected all components and wrote program too..but it works opposite to what you have showed when i place soil moisture sensor in wet soil the motor is on and when i remove nothing happens plz help ..

  4. finally i solved my problem sir i just changed this values
    digitalWrite(13,HIGH); //if soil moisture sensor provides LOW value send LOW value to relay
    digitalWrite(13,LOW); //if soil moisture sensor provides HIGH value send HIGH value to relay
    compare this with original program
    this is working for me
    when i remove the sensor from the wet soil the motor is on state and off when i place it in wet soil
    anyway thx for program

  5. Instead of ac motor we use dc motor
    Is it working in automatic watering system for plants.
    When we don’t put soil sensor inside the soil water flow from pump but we put sensor inside the soil it will not work water is flowing continue instead of stoping
    Plz help me what can i do.

  6. Hi, I am receiving the reverse for the output…..when the soil moisture sensor is placed on dry soil then water is not flowing while water is flowing when the soil moisture sensor is placed in wet soil…How to overcome this?

  7. Hi, please help me. When I compile the program at the beginning there is no error but when I want to upload it to the board it says that it can not as if it did not detect it.
    Then, I got a 3-6 v motor and I connected it to a cell phone charger like in the tutorial but I checked all the connections and it does not work. I hope you can answer fast

  8. Hello
    I am trying to write a code for two soil sensors using python. i got it work for one sensors , but i could not do it for two sensors, so my question is there a specific loop for two sensors ??BTW, I am using Raspberry pi

  9. GPIO.setup(16, GPIO.IN)
    GPIO. setup(18, GPIO.OUT)

    GPIO.setup(7, GPIO.IN)
    GPIO.setup(7, GPIO.IN)

    while True:
    if GPIO.input(16)==1
    GPIO.ouput(18, True)

    if GPIO.input(7)==1
    GPIO.ouput(15, True)

    GPIO.setup(18, GPIO.OUT)

    GPIO.setup(15, GPIO.OUT)

  10. I have coded the arduino and done all the connections as shown in the video but the pump isn’t coming on.can I get some help on making it work

  11. Hi, I am a complete beginner. How to use this device for multiple plants at once? I mean if I use 2 motors and soil sensors, how to make it work for both?

  12. Hi
    I am Pratham
    The coding you gave in the videos not working can I ask for the correct coding I used 1 channel relay board instead of 4 channel relay board and other things are same
    Thank you

  13. The things working reversly the water is being pumped when there is moisture and not being pumped when no moisture..please help me regarding this…

  14. Good stuff ! I’m willing to do this project but I have small query. What if water from source get empty ? Because if there is no water to suck, the motor can fail or damage. How to overcome this small issue?

  15. Hi i am doing the project of automatic watering plants using arduino.
    I have done the connections according to the video given.
    I am sorry i did not understand the above codings posted in the above comments as i just have the very basic info. about coding done at school (c++).

    The problem is that when i give the power supply to both the arduino and the dc water pump, the pump starts working and also the sensor is dry. But now is the problem….

    The pump is running but according to the project the pump should stop when the sensor is dipped in water/wet soil. But that does not happen.

    When i take it out it stops. Again when i dip it in water and take it out it starts. This happens only a few times and then stops and nothing works.


    The pins for the coding is given below…
    The DO from the sensor – pin 9
    Pin 12 from arduino – IN1 of relay.

    Again please send me the correct coding and advice me if there is any problem.


Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.