Arduino Automatic Plant Watering System using Soil Moisture Sensor and Relay

Introduction

Keeping your plants healthy often requires regular watering — but what if you could automate it?
In this project, we’ll create a smart plant watering system using Arduino, a soil moisture sensor, a relay module, and a mini water pump.
The system monitors the soil’s moisture level in real-time. When the soil becomes dry, Arduino automatically turns ON the pump to water the plant. Once the soil reaches an adequate moisture level, it automatically switches OFF the pump.
It’s one of the most practical and beginner-friendly Arduino automation projects, combining sensor reading, relay control, and environmental awareness.
Table of Contents
- Components Required
- Circuit Diagram & Connections
- Arduino Code
- Working Explanation
- Calibration Tips
- Applications
- FAQs
- Conclusion
- Similar Projects
Components Required
| Component | Quantity | Description |
| Arduino Uno / Nano | 1 | Controls the entire system |
| Soil Moisture Sensor (with Module) | 1 | Detects soil wetness level |
| Relay Module (5V) | 1 | Controls the water pump ON/OFF |
| Mini Water Pump | 1 | Waters the plant automatically |
| Connecting Wires | — | For circuit connections |
| Breadboard / PCB | 1 | For prototyping |
| 12V Power Supply / Adapter | 1 | Powers the pump |
| 5V Power (USB or adapter) | 1 | Powers Arduino |
⚙️ Circuit Connections
| Component | Arduino Pin | Description |
| Soil Moisture Sensor (AO) | A0 | Reads analog moisture data |
| Relay IN Pin | D7 | Controls pump switching |
| VCC & GND (Sensor + Relay) | 5V & GND | Common power lines |
| Pump | Connected to relay’s NO terminal | Switched by relay |
| Relay COM | 12V Power Supply | Common input for relay |
Working Flow:
- When the soil is dry, sensor output gives LOW moisture value, and Arduino activates the relay (pump ON).
- When the soil becomes wet, the sensor value increases, and Arduino turns OFF the relay (pump OFF).
💻 Arduino Code for Automatic Plant Watering System
// ------------------------------------------------------------
// Project: Automatic Plant Watering System
// Author: Abdulla | Alpha DigitAll
// ------------------------------------------------------------
const int sensorPin = A0; // Soil moisture sensor analog pin
const int relayPin = 7; // Relay module control pin
int sensorValue = 0; // To store sensor reading
int threshold = 500; // Adjust based on calibration
void setup() {
Serial.begin(9600);
pinMode(relayPin, OUTPUT);
digitalWrite(relayPin, HIGH); // Relay off initially
Serial.println("Automatic Plant Watering System Initialized");
}
void loop() {
sensorValue = analogRead(sensorPin);
Serial.print("Soil Moisture Value: ");
Serial.println(sensorValue);
if (sensorValue > threshold) {
// Soil is dry → Turn ON the pump
digitalWrite(relayPin, LOW); // Active LOW relay
Serial.println("Soil Dry - Pump ON 💧");
} else {
// Soil is wet → Turn OFF the pump
digitalWrite(relayPin, HIGH);
Serial.println("Soil Moist - Pump OFF 🌿");
}
delay(2000); // Delay before next reading
}
🔍 How It Works
- Sensor Input:
The Soil Moisture Sensor measures the soil’s resistance — dry soil gives higher resistance, hence a higher analog value. - Arduino Logic:
The Arduino continuously reads the sensor’s analog value. If it crosses the threshold (indicating dryness), it sends a signal to the relay module. - Relay Activation:
The relay module acts as a switch — it turns the pump ON when the soil is dry and OFF when it becomes moist again. - Pump Operation:
The pump irrigates the soil until the required moisture is reached, after which the relay deactivates the pump.
🔧 Calibration Tips
- You can determine the threshold value by printing raw sensor readings:
- Insert the sensor in dry soil → note value.
- Insert in wet soil → note value.
- Set threshold roughly halfway between these two.
- Example: Dry soil = 750, Wet soil = 350 → Threshold ≈ 550.
- Adjust threshold in code accordingly.
🧠 Applications
- Home garden or indoor plant care
- Greenhouse irrigation systems
- Smart agriculture setups
- IoT-based soil monitoring
- Educational electronics projects
#Arduino Projects#DIY Arduino Tutorial#Embedded Systems#Plant Watering Automation#Relay Module#Smart Garden Project#Smart Irrigation#Soil Moisture Sensor