Automatic Plant Watering System

Arduino Project – Automatic Plant Watering System

In this post, we will learn how to make an automatic plant watering system using a capacitive soil moisture sensor.

The capacitive soil moisture sensor is widely used for measuring the volumetric water content of soil. Unlike traditional resistive sensors, which rely on electrical resistance and are prone to corrosion over time, the capacitive sensor operates on the principle of capacitance, offering better durability, stability, and accuracy in long-term soil monitoring applications.

Hardware Required

  • Arduino UNO
Arduino UNO

For more information, visit Getting to Know Your Arduino Uno: A Beginner’s Guide to Its Components.

Capacitive soil moisture sensor
Relay
Water Pump
LCD Module with I2c Interface
  • 9V Battery
9V Battery Connector with DC Plug
  • 5V USB Power Supply

Visit Tutorial | How to Make your own 5v USB power supply CABLE.

  • Jumper Wires
Jumper Wires

Working Principle

Capacitive Soil Moisture Sensor

A capacitive soil moisture sensor measures the volumetric water content of soil using the dielectric properties of the soil.

The sensor circuit is typically built around a 555 timer IC, which is used to monitor how fast a capacitor charges through a resistor. The sensing element comprises two PCB traces acting as capacitor plates, with their capacitance varying according to the moisture content in the surrounding soil.

Capacitive soil moisture sensor v2.0

When the sensor is inserted into the soil, the moisture content alters the dielectric constant, which in turn changes the capacitance. This affects the oscillation frequency generated by the 555 timer. The frequency shift is then converted into an analog voltage, typically ranging from 1 to 3 volts, which can be read by a microcontroller such as an Arduino. The drier the soil, the higher the output voltage, and vice versa.

The Arduino’s analog input pin is connected to its built-in ADC. The ADC takes the continuous analog voltage from the sensor and converts it into a digital integer value.

  • In open air: approximately 590
  • Dry soil that needs watering: approximately 380
  • Ideal soil moisture: between 277 and 380
  • Soil that has just been watered: approximately 277
  • In cup of water: approximately 273
Relay Module

Relays are used to control high-power devices with low-power signals, often from a microcontroller like an Arduino or Raspberry Pi. Trigger level refers to the logic voltage level (HIGH or LOW) required to activate the relay. You can determine the trigger type by checking the relay module’s datasheet or documentation.

  • Low-Level Trigger Relay: A LOW signal (0V) from the microcontroller turns the relay ON; a HIGH signal (5V) turns it OFF.
  • High-Level Trigger Relay: A HIGH signal (5V) from the microcontroller turns the relay ON; a LOW signal (0V) turns it OFF.

For further information, visit An Essential Introduction to DC Relays in Arduino Projects: What They Are and How They Work.

In this project, we use a LOW-level trigger relay in normally open (NO) mode. By default, the circuit remains open. When the control pin receives a LOW signal (0V), the relay is activated, closing the NO contact and turning on the water pump.

Step-by-Step Process

1. Sensor Reads Moisture

The soil moisture sensor is placed in the soil near the plant roots. It measures the analog voltage that corresponds to how dry or wet the soil is.

  • Dry soil → Higher analog value
  • Wet soil → Lower analog value

2. Arduino Processes Data

The Arduino reads the analog signal from the sensor. The ADC takes the continuous analog voltage from the sensor and converts it into a digital integer value. If the value is above the threshold (dry), it means the plant needs water.

3. Pump is Activated

If the soil is dry, Arduino sends a signal to the relay. In this project, a LOW signal is sent to the relay. The relay turns on the water pump. The pump draws water from the reservoir and delivers it to the plant.

4. Pump is Turned Off

When moisture reaches the desired level, Arduino turns off the pump.

Diagram

Automatic Plant Water System Diagram

Setup

Automatic Plant Water System
1. Connect the Moisture Sensor to the Arduino
Moisture SensorArduinoBreadboard
GND
VCC+
AUOTA0
Automatic Plant Watering System
2. Connect the LCD Module to the Arduino
LCDArduinoBreadboard
GND
VCC+
SDAA4
SCLA5
Automatic Plant Watering System

A4/SDA and A5/SCL are Arduino I2C Pins. The I2C protocol uses two lines to send and receive data: a serial data (SDA) line and a serial clock (SCL) line. With I2C, we can connect multiple devices only using two wires. SCL is used to synchronously clock data. SDA is used to transmit data to or from target devices. The clock signal acts as a metronome. It synchronizes the transfer of serial data, indicating to the devices the correct time to capture each bit. Visit Inter-Integrated Circuit (I2C) Protocol for more information.

3. Connect the Relay to the Water Pump and the USB adapter

Connect the tube to the water pump.

The USB adapter supplies power to the water pump. The ground wire (black) from the USB cable and the negative wire (black) from the water pump are connected together. The pump’s positive wire (red) is connected to the NO (Normally Open) terminal of the relay, while the power wire (red) from the USB cable is connected to the COM (Common) terminal.

4. Connect the Relay to the Arduino
RelayArduinoBreadboard
GND
VCC+
IND2
5. Connect the Arduino to the Breadboard
ArduinoBreadboard
GND
5V+
6. Upload the program

Connect the Arduino to your computer using a USB cable. Upload the program to the Arduino through the Arduino IDE software. Visit Getting Started with Arduino IDE: A Beginner’s Guide to Coding and Creating for more information.

7. Set Up the Plant Water System
  • Insert the soil moisture sensor into the plant’s soil.
  • Place the water pump into the water container.
  • Position the water tube so that it leads into the plant pot.
  • Disconnect the USB cable and connect the 9V battery to the Arduino.
  • Plug the USB adapter into the outlet.
Automatic Plant Watering System

Code

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

//Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27, 16, 2);

#define relayPin 2  //Digital pin connected to the relay
#define sensorPin A0  //Analog pin connected to the moisture sensor

int value;
int pct;

void setup() {
  Serial.begin(9600);

  //Initialize the LCD
  lcd.init();
  // Turn on the backlight
  lcd.backlight();

  pinMode(relayPin, OUTPUT);  //Relay is an output device
  pinMode(sensorPin, INPUT);  //Moisture sensor is an input device

  delay(2000);
}

void loop() {
  value = analogRead(sensorPin); //Read value from moisture sensor
  pct = map(value, 275, 590, 100, 0); //Map value to percentage (0-100%)
  Serial.print("value:");
  Serial.print(value);
  Serial.print("\t | ");

  if(value>380){
    //Relay is low level trigger relay so we need to write LOW to turn the pump on.
    digitalWrite(relayPin, LOW); 
    Serial.println("No moisture, Soil is dry");
    lcd.setCursor(0, 0);
    lcd.print("Moisture: ");
    lcd.print(pct);
    lcd.print("%");
    lcd.setCursor(0, 1);
    lcd.print("Soil is dry.");
  }
  else{
    digitalWrite(relayPin, HIGH);
    Serial.println("Soil is wet");
    lcd.setCursor(0, 0);
    lcd.print("Moisture: ");
    lcd.print(pct);
    lcd.print("%");
    lcd.setCursor(0, 1);
    lcd.print("Soil is wet.");
  }
  delay(1000);
}