Skip to content

Smart Plant Watering System

Build an Arduino-based automatic irrigation system with moisture sensors and a water pump for efficient plant care.

  • Arduino
  • Intermediate
  • 60–90 minutes
  • 5 steps

Shop this project

Cart

Prices from vilros.com. Tax and shipping at checkout.

Before you start, you'll need

  • Arduino Uno
  • Soil moisture sensor (waterproof recommended)
  • Water pump (12V recommended)
  • Relay module
  • Flexible tubing
  • Power supply (12V for pump)
  • Breadboard
  • Jumper wires
  • Water reservoir

Connect the moisture sensor

About 10 minutes

Wire the soil moisture sensor to Arduino.

  1. Connect the moisture sensor VCC to Arduino 5V.
  2. Connect the moisture sensor GND to Arduino GND.
  3. Connect the moisture sensor analog output to Arduino A0.
  4. Insert the sensor probes into the soil of your plant.

You should see

The moisture sensor is wired and inserted into the soil.

Set up the water pump with relay

About 15 minutes

Wire the relay module to control the water pump safely.

  1. Connect the relay module VCC to Arduino 5V.
  2. Connect the relay module GND to Arduino GND.
  3. Connect the relay IN pin to Arduino digital pin 7.
  4. Connect the water pump positive wire to the relay NO (Normally Open) terminal.
  5. Connect the relay COM (Common) terminal to the positive terminal of your 12V power supply.
  6. Connect the water pump negative wire to the power supply GND.
  7. Connect the Arduino GND to the power supply GND (common ground).

You should see

The relay and pump are wired correctly. The relay module LED should be off (pump is off).

It didn't work
  • Relay always stays on or off.

    Check the IN pin connection to pin 7. Verify you're using the correct relay terminal (NO, not NC). Test the relay with a simple digitalWrite(7, HIGH) command.

Set up water delivery

About 10 minutes

Connect tubing from pump to plants.

  1. Place the water pump in your reservoir (bucket or tank).
  2. Attach flexible tubing to the pump output.
  3. Route the tubing to your plant(s).
  4. Test manually by powering the pump briefly to check for leaks.

You should see

Water flows from the reservoir through the tubing when the pump is powered.

Upload the irrigation sketch

About 20 minutes

Program the Arduino to water when soil is dry.

  1. Open Arduino IDE and copy the complete irrigation sketch below.
  2. Adjust the DRY_THRESHOLD value based on your sensor readings (lower = drier soil).
  3. Upload to your Arduino.
  4. Open Serial Monitor (9600 baud) to see moisture readings and pump status.
cpp
const int moisturePin = A0;
const int pumpPin = 7;

const int DRY_THRESHOLD = 400;
const int WATERING_TIME = 5000;

unsigned long lastWatering = 0;
const unsigned long WATERING_INTERVAL = 3600000;

void setup() {
  pinMode(pumpPin, OUTPUT);
  digitalWrite(pumpPin, LOW);
  
  Serial.begin(9600);
  Serial.println("Smart Watering System Starting...");
}

void loop() {
  int moistureLevel = analogRead(moisturePin);
  
  Serial.print("Moisture Level: ");
  Serial.println(moistureLevel);
  
  unsigned long currentTime = millis();
  
  if (moistureLevel < DRY_THRESHOLD && 
      (currentTime - lastWatering > WATERING_INTERVAL)) {
    
    Serial.println("Soil is dry. Watering now...");
    digitalWrite(pumpPin, HIGH);
    delay(WATERING_TIME);
    digitalWrite(pumpPin, LOW);
    
    lastWatering = currentTime;
    Serial.println("Watering complete.");
  } else {
    Serial.println("Soil moisture OK.");
  }
  
  delay(60000);
}

DRY_THRESHOLD varies by sensor and soil type. Test with dry and wet soil to calibrate. WATERING_TIME is in milliseconds (5000 = 5 seconds).

You should see

The sketch uploads successfully. Serial Monitor shows moisture readings.

Calibrate and test

About 15 minutes

Fine-tune moisture threshold and watering duration.

  1. Open Serial Monitor and observe moisture readings.
  2. Note the reading when soil is completely dry.
  3. Note the reading after watering.
  4. Adjust DRY_THRESHOLD in the code to trigger watering at your desired moisture level.
  5. Adjust WATERING_TIME based on how much water your plant needs.
  6. Monitor for 24 hours to ensure the system waters at the right times.

You should see

The system waters the plant when soil is dry and stops when soil is moist.

It didn't work
  • Pump runs constantly.

    The threshold may be set too high. Lower the DRY_THRESHOLD value. Check that the sensor is properly inserted in soil and reading correctly.

  • System never waters.

    The threshold may be too low. Raise the DRY_THRESHOLD value. Verify the sensor is working by checking Serial Monitor readings.

What to do next

Stuck? Contact Vilros Support with your board model and what you see on screen.