Automatic Plant Watering with Arduino

Difficulty
Moderate
Steps
19

Want to keep your plants watered while away on vacation? Build your own automatic self-watering system using our Automatic Plant Watering Kit and an Arduino!

In this guide, you will learn to connect the kit to the Arduino or as a standalone, then program it to monitor soil moisture levels; when soil moisture level goes below the set threshold level, the plant will be automatically watered.

Complete this guide to get started with building your own automatic plant watering system! 

Step 1  Use as standalone or with Arduino

Our Auto Plant Watering kit comes with: 

  • 5V Relay Module
  • Soil moisture probe + comparison module
  • Small submersible pump 
  • 50cm tube 
  • Battery pack enclosure 
  • USB power line
  • Jumper wires

It can be used as a standalone, or together with the Arduino. Please jump to Step 17 if you would like to connect the components as a standalone.

Step 2  Connect VCC to 5V

Connect VCC on the relay to 5V pin on Arduino

Step 3  Connect GND to negative power rail

Connect GND on the relay to negative power rail of breadboard

Step 4  Connect IN to Pin 3

Connect IN on relay to Pin 3 on Arduino

Step 5  Insert batteries into battery holder

  • The battery holder enclosure contained in the kit will fit 4 x AA batteries.
  • Insert 4 X AA batteries into the case. Make sure that the '+' side of a battery cell is connected to the '+' side of the battery enclosure, and '-' of a battery cell to '-' of enclosure.
  • There is a switch on the battery enclosure, to turn it 'ON' and 'OFF'

Step 6  Connect black wire (battery holder) to negative power rail

Connect the '-' black wire from battery pack to the negative power rail on the breadboard

Step 7  Connect black wire of pump to negative power rail

Next, connect the black wire of pump to negative power rail

Step 8  Connect soil moisture sensor to module

Connect two F-F jumper wires from the soil moisture sensor probe to the comparison module included in the kit.

Step 9  Connect AO to A0

Connect a F-M jumper wire from AO on the module to A0 on Arduino

Step 10  Connect GND (on module) to GND

Connect a F-M jumper wire from GND on the module to GND on Arduino

Step 11  Connect VCC (on module) to 3.3V

Connect a F-M jumper wire from VCC on the module to 3.3V on the Arduino

Step 12  Connect red wire of pump to NC

  • Connect red wire of pump to NC.
  • You may need to use a small jewelers phillips screwdriver to loosen the holding before plugging in the wire, and then tightening it again.

Step 13  Connect red wire (battery holder) to COM

  • Connect the '+' red wire from battery holder to COM on the relay.
  • You may need to use a small jewelers phillips screwdriver to loosen the holding before plugging in the wire, and then tightening it again.

Step 14  Connect negative power rail to GND

Connect a M-M wire from the negative power rail of breadboard, to GND pin on Arduino

Next, we will get started with programming the Arduino, so connect it to a computer with the Arduino IDE installed.

Step 15  The code


              int motorPin = 3; // pin that turns on the motor
int blinkPin = 13; // pin that turns on the LED
int watertime = 5; // how long it will be watering (in seconds)
int waittime = 1; // how long to wait between watering (in minutes)

void setup()
{
  pinMode(motorPin, OUTPUT); // set Pin 3 to an output
  pinMode(blinkPin, OUTPUT); // set pin 13 to an output
  Serial.begin(9600);
}

void loop()
{
  int moisturePin = analogRead(A0); //read analog value of moisture sensor
  int moisture = ( 100 - ( (moisturePin / 1023.00) * 100 ) ); //convert analog value to percentage
  Serial.println(moisture);
  if (moisture < 40) { //change the moisture threshold level based on your calibration values
    digitalWrite(motorPin, HIGH); // turn on the motor
    digitalWrite(blinkPin, HIGH); // turn on the LED
    delay(watertime * 1000);      // multiply by 1000 to translate seconds to milliseconds
  }
  else {
    digitalWrite(motorPin, LOW);  // turn off the motor
    digitalWrite(blinkPin, LOW);  // turn off the LED
    delay(waittime * 60000);      // multiply by 60000 to translate minutes to milliseconds
  }

}
            

Upload this code to the Arduino!

To adjust how long it will be watering each time, simply change :
int watertime = 5;

To adjust the wait time between watering, simply change:

 int waittime = 1;

To adjust the moisture threshold level, change the conditional statement:

  if (moisture < 40)

Save this sketch. Then go to the next step to calibrate your soil moisture sensor. This is an important next step that we recommend as different soil types will yield different measurements. 

Step 16  Code to calibrate soil moisture sensor


              void setup() {
  Serial.begin(9600); // initialize serial communication 
}

void loop() {
  int moistureVal = analogRead(A0);  // read the input on analog pin 0:
  Serial.println(moistureVal); // print out the analog val 
  delay(30);       
}
            

Now that you have connected the kit with an Arduino, the 'moisture' threshold value found in the sketch above may need to be modified based on what values your sensor outputs when the sensor is completely dry, compared to when the sensor is completely submerged in water.

  • Copy this code and upload it to your Arduino to get analog readings for calibration.
  • Conduct a test using a bowl of water. Make note of the analog value when the probes are not in water. Submerge it in a shallow glass of water, and watch the analog value drop.
  • Conduct another test, this time using soil. Get measurements when the soil is completely dry. 
  • Do the same when the soil has been watered, but be careful not to over-water it.
  • View the readings in the Serial Monitor in the Arduino IDE by clicking on Tools > Serial Monitor
  • Note: The more water content in the soil, the lower the analog measurements will be.


Step 17  Stand-alone circuit

Follow these steps to connect the automatic plant watering kit without an Arduino:

  • First, connect 2x F-F jumper wires from the soil moisture sensor probe to its comparison module
  • Next, connect DO pin on the comparison module to IN pin on relay
  • Connect VCC pin on comparison module to breadboard's positive power rail. Use a M-F jumper wire.
  • Connect GND pin on comparison module to breadboard's negative power rail. Use another M-F jumper wire.
  • For the battery enclosure, connect its black wire to breadboard's negative power rail
  • Connect red wire of battery enclosure to breadboard's positive power rail
  • For the relay, connect VCC pin to breadboard's positive power rail
  • Connect GND pin on relay to breadboard's negative power rail
  • Connect the relay's COM pin to positive power rail on the breadboard. 
    • You may need to use a screwdriver to loosen the holding before plugging in the wire, and then tightening it again.
  • The mini water pump has two wires, connect its red wire to NC on relay
    • Likewise, you may need to use a screwdriver to insert the wire
  • Connect the mini water pump's black wire to negative power rail on breadboard.

Step 18  Soil moisture calibration (standalone)

Finally, to get useful measurements from the soil moisture sensor, you can calibrate it. We recommend calibrating it as different types of soil can affect the sensor readings differently.  

  • If you have connected the kit as a stand-alone without an Arduino, you can calibrate the soil moisture sensor by turning the potentiometer found on the comparison module. Use a small jewelers phillips screwdriver.

    • Turn it clockwise to increase sensitivity,
    • Turn it counterclockwise to decrease the sensitivity.

Step 19  How it might look like

Connect the tube to the submersible water pump as shown in the diagram. 

Place the pump in a container of water. 

Insert the soil moisture sensor probe into your potted plant.

Power up the circuit. After which, when the soil moisture level goes below the set threshold moisture level, it will be automatically watered!

 You may want to go one step further: move the circuit from the breadboard to a more permanent set-up by using a perma-protoboard or perfboard.