Automatic Plant Watering System with PIR Sensor

Project Overview

This project creates a smart plant watering system that reminds you to water your plants when motion is detected nearby, or automatically waters based on soil moisture. It is perfect for indoor plants that are easily forgotten.

Difficulty: Beginner/Intermediate
Estimated time: 2-3 hours
Estimated cost: $20-30

How It Works

A PIR sensor detects when someone approaches the plant. When motion is detected, a soil moisture sensor checks if watering is needed. If the soil is dry, a water pump is activated for a set duration. An LCD or LED indicates the plant’s status. Optionally, the system can water automatically on a schedule regardless of motion.

Materials Needed

  • Arduino Uno or ESP32 (1)
  • HC-SR501 PIR sensor (1)
  • Capacitive soil moisture sensor (1)
  • Submersible water pump (5V)
  • MOSFET or relay module
  • Water reservoir (container)
  • Plastic tubing
  • LCD 16×2 with I2C (optional)
  • Buzzer (optional)
  • LED for status
  • 220Ω resistor
  • Jumper wires
  • Power supply (5V 2A)

Circuit Diagram

Connection Table

VCC

5V

GND

GND

OUT

Digital Pin 2

VCC

5V

GND

GND

AO

Analog Pin A0

IN

Digital Pin 3

SDA

A4

SCL

A5

Positive

Digital Pin 8

Anode

Digital Pin 13 (via 220Ω)

Arduino Code

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 16, 2);

const int pirPin = 2;
const int pumpPin = 3;
const int moisturePin = A0;
const int buzzerPin = 8;
const int ledPin = 13;

const int dryThreshold = 500;
const int wetThreshold = 800;

unsigned long lastMotionTime = 0;
const unsigned long cooldownPeriod = 3600000;
bool wateredRecently = false;

void setup() {
  Serial.begin(9600);
  
  pinMode(pirPin, INPUT);
  pinMode(pumpPin, OUTPUT);
  pinMode(buzzerPin, OUTPUT);
  pinMode(ledPin, OUTPUT);
  
  digitalWrite(pumpPin, LOW);
  digitalWrite(ledPin, LOW);
  
  lcd.init();
  lcd.backlight();
  lcd.print("Plant Watering");
  lcd.setCursor(0, 1);
  lcd.print("System Ready");
  
  delay(60000);
}

int readMoisture() {
  int value = analogRead(moisturePin);
  return value;
}

bool needsWater() {
  int moisture = readMoisture();
  return moisture < dryThreshold;
}

void waterPlant() {
  digitalWrite(buzzerPin, HIGH);
  delay(200);
  digitalWrite(buzzerPin, LOW);
  
  digitalWrite(pumpPin, HIGH);
  digitalWrite(ledPin, HIGH);
  delay(5000);
  digitalWrite(pumpPin, LOW);
  digitalWrite(ledPin, LOW);
  
  digitalWrite(buzzerPin, HIGH);
  delay(200);
  digitalWrite(buzzerPin, LOW);
  delay(200);
  digitalWrite(buzzerPin, HIGH);
  delay(200);
  digitalWrite(buzzerPin, LOW);
  
  wateredRecently = true;
  lastMotionTime = millis();
}

void checkAndWater() {
  if (needsWater()) {
    if (!wateredRecently || (millis() - lastMotionTime > cooldownPeriod)) {
      waterPlant();
    } else {
      digitalWrite(buzzerPin, HIGH);
      delay(100);
      digitalWrite(buzzerPin, LOW);
      delay(100);
    }
  }
}

void displayStatus() {
  int moisture = readMoisture();
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Moisture: ");
  lcd.print(moisture);
  lcd.setCursor(0, 1);
  if (moisture < dryThreshold) {
    lcd.print("DRY - Water soon");
  } else if (moisture < wetThreshold) {
    lcd.print("OK");
  } else {
    lcd.print("WET");
  }
}

void loop() {
  bool motionDetected = digitalRead(pirPin) == HIGH;
  
  if (motionDetected) {
    digitalWrite(ledPin, HIGH);
    delay(500);
    digitalWrite(ledPin, LOW);
    checkAndWater();
  } else {
    static unsigned long lastDisplay = 0;
    if (millis() - lastDisplay > 10000) {
      displayStatus();
      lastDisplay = millis();
    }
  }
  
  delay(100);
}

Installation Steps

  1. Assemble electronics on breadboard and test
  2. Calibrate soil sensor in dry and wet soil to set thresholds
  3. Test pump to verify water movement
  4. Insert soil moisture sensor into plant pot
  5. Mount PIR sensor to detect approach
  6. Place Arduino and power supply in safe location away from water
  7. Trigger PIR and verify watering occurs when soil is dry

Project Extensions

  • Add float switch to detect when reservoir is low
  • Add additional soil sensors for multi-plant watering
  • Use ESP32 to send soil moisture data to phone
  • Add rain sensor for outdoor plants
  • Add second pump for liquid fertilizer

Conclusion

This smart plant watering system takes the guesswork out of plant care. It reminds you to water when you are near the plant and only waters when needed, preventing both under-watering and over-watering.

Leave a Reply

Your email address will not be published. Required fields are marked *

Component Pin Arduino Pin
PIR Sensor PIR Sensor PIR Sensor Soil Moisture Sensor Soil Moisture Sensor Soil Moisture Sensor Relay Module LCD I2C LCD I2C Buzzer Status LED