Summary
Efficient water management is an important part of plant care, but fixed watering schedules do not always reflect actual soil conditions. Soil moisture can change throughout the day due to sunlight, temperature, and plant water consumption. This often results in plants receiving either too much or too little water.
In this project, we will build a Smart Irrigation System using Arduino Uno that automatically waters plants based on soil moisture levels. Using a soil moisture sensor, relay module, water pump, and LCD display, the system continuously monitors the soil and activates irrigation only when it is needed.

A smart irrigation system using Arduino Uno automatically waters plants when the soil becomes too dry. It uses a soil moisture sensor to measure the soil condition, an Arduino Uno to process the sensor reading, a relay module to switch a water pump, and a 12V DC mini submersible pump to deliver water to the plant.
This project is suitable for home gardens, potted plants, school science exhibitions and beginner electronics projects. With a capacitive soil moisture sensor, a 1-channel relay and a 12V pump, you can build an automatic plant watering system without needing to switch the pump on manually every time the soil dries out.
In this guide, you will learn how the system works, which components you need, how to connect the sensor and pump to an Arduino Uno, and how to calibrate the moisture threshold. You will also learn how to prevent excessive watering and upgrade the project with an ESP32 or rain sensor.
What Is a Smart Irrigation System?
A smart irrigation system monitors soil moisture and waters plants when the moisture level falls below a selected threshold. Unlike a basic timer-based watering system, a soil moisture-based system responds to the condition of the soil.
For this project, the Arduino Uno reads a capacitive soil moisture sensor. When the soil becomes too dry, the Arduino activates a relay that switches on a 12V DC mini submersible water pump. When the soil reaches the desired moisture level, the Arduino switches the pump off.
The main components are:
-
Arduino Uno: Reads the sensor and controls the pump.
-
Capacitive soil moisture sensor: Measures changes associated with soil moisture.
-
1-channel relay module: Switches the pump's power supply.
-
12V DC mini submersible pump: Moves water from a reservoir to the plant.
-
12V power supply: Powers the pump.
-
Jumper wires and a suitable container: Connect the electronics and hold the water.
The goal is to keep the soil within a useful moisture range, not to keep it continuously wet. The correct threshold depends on the sensor, soil type, plant and sensor placement.
Components and Supplies
Components Required for the Arduino Irrigation Project
The following components are enough to build a basic automatic plant watering system.
|
Component |
Purpose |
|---|---|
|
Arduino Uno |
Reads soil moisture and controls watering |
|
Capacitive soil moisture sensor |
Detects changes in soil moisture |
|
1-channel 5V relay module |
Switches the pump supply |
|
Pumps water from a reservoir |
|
|
12V DC power supply |
Powers the pump |
|
Jumper wires |
Connects the sensor, Arduino and relay |
|
Water reservoir and tubing |
Stores and delivers water |
|
Breadboard or suitable wiring terminals |
Helps connect the low-voltage electronics |
The linked Robocraze pump is listed as a 12V, 8W model with a maximum flow rate of 10 litres per minute. Actual flow depends on the lift height, tubing and outlet restrictions. This is a relatively high flow rate for watering a small pot, so use short pump run times and test the amount of water delivered before leaving the system unattended.
A capacitive moisture sensor is preferable to many basic resistive probes for projects that stay in soil for extended periods. However, it still needs calibration and should not be left immersed in water unless its manufacturer explicitly permits that use.
How the Smart Irrigation System Works
The system follows a simple control cycle:
-
The soil moisture sensor measures the condition of the soil.
-
The Arduino reads the sensor's analog output.
-
The reading is compared with a threshold selected during calibration.
-
If the soil is dry, the Arduino activates the relay.
-
The relay switches on the 12V pump, delivering water to the plant.
-
When the target moisture level is reached, the Arduino switches the pump off.
The pump should not be powered from an Arduino GPIO pin. The GPIO pin sends a control signal to the relay module, while a separate 12V supply provides power to the pump.
The code should also limit how long the pump can run in one watering cycle. This reduces the chance of flooding if the sensor becomes disconnected or the moisture reading does not change as expected.
Wiring the Soil Moisture Sensor, Relay and 12V Pump
Before wiring, check the pin labels and voltage requirements of your particular sensor and relay board. The connections below assume a capacitive sensor with VCC, GND and AO pins, a 5V relay module, and a 12V DC pump.
1. Connect the capacitive soil moisture sensor
|
Sensor pin |
Arduino Uno connection |
|---|---|
|
VCC |
5V, if supported by the sensor |
|
GND |
GND |
|
AO |
Analog pin A0 |
The sensor's analog output changes with soil moisture. The direction and range of the readings depend on the sensor, so do not assume a universal dry or wet value.
2. Connect the relay module
|
Relay pin |
Arduino Uno connection |
|---|---|
|
VCC |
5V, if supported by the relay board |
|
GND |
GND |
|
IN |
Digital pin 7 |
Many relay modules are active LOW, meaning the relay switches on when the control input is LOW. Others are active HIGH. Check the module documentation and test its behaviour before connecting the pump.
3. Connect the 12V pump through the relay contacts
Use the relay's contact terminals to switch the pump's 12V supply. For a typical arrangement using normally open contacts:
|
Connection |
Wiring |
|---|---|
|
12V supply positive |
Relay COM |
|
Relay NO |
Pump positive |
|
Pump negative |
12V supply negative |
With this arrangement, the pump receives power only when the relay energises and closes the COM to NO connection. The pump's 12V supply does not connect to an Arduino digital pin.
Use a relay whose contact rating is suitable for the pump's DC voltage and starting current. A motor can draw more current when starting than it draws while running. If you use a MOSFET driver instead, choose one designed for the pump's current and provide appropriate protection against motor switching transients.
Keep water away from the Arduino, relay contacts, connectors and power supply. Secure the reservoir and tubing to prevent leaks from reaching the electronics. Use a suitable enclosure and keep all electrical connections dry.
Arduino Code for Automatic Plant Watering
This sketch reads the capacitive soil moisture sensor and switches the relay when the soil is dry. It also limits each pump run to a maximum of five seconds, then pauses to let the water spread through the soil before taking another reading.
The example assumes the sensor's reading is higher when dry and lower when wet, which is common for many capacitive sensors. Verify this with your own sensor before using the code. It also assumes an active LOW relay module. If your relay is active HIGH, change the relay logic accordingly.
const int moisturePin = A0;
const int relayPin = 7;
// Example starting threshold only.
// Calibrate these values for your sensor and soil.
const int dryThreshold = 600;
const int wetThreshold = 450;
const unsigned long maxPumpTime = 5000;
const unsigned long soakTime = 10000;
bool pumpRunning = false;
bool waitingForSoak = false;
unsigned long pumpStartTime = 0;
unsigned long soakStartTime = 0;
int readMoisture() {
long total = 0;
for (int i = 0; i < 10; i++) {
total += analogRead(moisturePin);
delay(10);
}
return total / 10;
}
void pumpOn() {
digitalWrite(relayPin, LOW); // Active LOW relay
pumpRunning = true;
pumpStartTime = millis();
Serial.println("Pump ON");
}
void pumpOff() {
digitalWrite(relayPin, HIGH); // Active LOW relay
pumpRunning = false;
waitingForSoak = true;
soakStartTime = millis();
Serial.println("Pump OFF");
}
void setup() {
Serial.begin(9600);
digitalWrite(relayPin, HIGH);
pinMode(relayPin, OUTPUT);
pumpOff();
Serial.println("Smart irrigation system ready");
}
void loop() {
int moisture = readMoisture();
Serial.print("Moisture reading: ");
Serial.println(moisture);
if (pumpRunning) {
if (millis() - pumpStartTime >= maxPumpTime) {
pumpOff();
}
} else if (waitingForSoak) {
if (millis() - soakStartTime >= soakTime) {
waitingForSoak = false;
}
} else if (moisture >= dryThreshold) {
pumpOn();
} else if (moisture <= wetThreshold) {
Serial.println("Soil moisture is sufficient");
}
delay(200);
}
How the code works
-
moisturePinreads the sensor through A0. -
readMoisture()averages ten readings to reduce small fluctuations. -
dryThresholdsets the reading at which watering starts. -
wetThresholdprovides a lower stopping threshold, reducing rapid switching near the threshold. -
maxPumpTimelimits each pump run to five seconds. -
soakTimepauses watering so water can spread before the next decision. -
pumpOn()andpumpOff()control the relay.
The threshold values of 600 and 450 are examples, not universal calibration values. If your sensor produces lower readings when dry, reverse the comparison logic and choose thresholds based on your measurements.
Code note: The five-second run limit is a safeguard for a beginner prototype, not a guarantee against overwatering. Test the water volume delivered during five seconds and adjust the run time to suit the plant, pot and pump. For a more robust design, add a sensor fault check, a manual override and a longer lockout if the moisture reading fails to change.
Calibrating the Soil Moisture Sensor
Calibration is necessary because capacitive soil moisture sensors can produce different readings depending on their design, supply voltage, soil type and placement.
Step 1: Read the sensor in dry soil
Upload a simple analog-reading sketch or use the main project code. Place the sensor in the soil you intend to use, keeping the sensing area at a consistent depth. Record the reading when the soil is dry enough to need watering.
Do not assume that a reading of 600 always means dry soil. It is only an example threshold.
Step 2: Record the reading in moist soil
Water the soil and wait for the moisture to distribute. Record the sensor value again. Repeat the measurement at different moisture levels to understand how the readings change.
Step 3: Set the thresholds
Choose a dry threshold that starts watering and a separate wet threshold that stops the pump or prevents another watering cycle. The gap between the thresholds helps prevent rapid switching when readings fluctuate slightly.
For example, if your readings are around 700 in dry soil and 400 in moist soil, you could begin testing with a dry threshold near 650 and a wet threshold near 450. These values are illustrative. Confirm the correct thresholds with your own sensor and soil.
Step 4: Test the amount of water delivered
Run the pump for a short, measured interval and observe how much water reaches the plant. If the pot becomes saturated quickly, reduce the run time. If the water does not reach the root zone, check the tubing, pump lift and sensor location.
Place the sensor away from the immediate water outlet so it measures the broader soil condition rather than a small, freshly watered patch.
Pump vs Solenoid Valve for Irrigation
A pump and a solenoid valve perform different jobs. A pump moves water, while a solenoid valve opens or closes a water path.
|
Feature |
12V submersible pump |
Solenoid valve |
|---|---|---|
|
Main function |
Moves water from a reservoir |
Controls flow through a pipe |
|
Requires a water source |
Yes |
Yes, plus sufficient pressure or flow |
|
Best for |
Tank-based watering and small reservoirs |
Systems with an existing pressurised or gravity-fed supply |
|
Arduino control |
Relay or suitable MOSFET driver |
Relay or suitable driver matched to the valve |
|
Main consideration |
Flow rate, lift height and pump current |
Valve voltage, pressure rating and whether it is normally open or normally closed |
For a potted plant supplied from a bucket or tank, a submersible pump is often the straightforward choice. If water is already available through a pipe, a suitable solenoid valve may be more appropriate.
Do not connect a 230V AC solenoid valve directly to an Arduino. Use an appropriately rated switching device, enclosure and safe mains wiring, or choose a compatible low-voltage valve for a beginner project.
Upgrading the Project with ESP32 and Rain Detection
Once the basic Arduino system works, you can add features to make watering more convenient.
ESP32 monitoring: An ESP32 can connect the irrigation system to Wi-Fi, allowing you to view sensor readings or send status updates through a suitable application or web interface. The pump still needs a properly rated driver and a suitable power supply.
Rain detection: A rain sensor can help prevent unnecessary watering during rainfall. A simple rain sensor detects water on its surface, but it does not measure how much rain has reached the soil. Use it as an additional input rather than the only condition for deciding whether a plant needs water.
Manual override: Add a button or switch so you can start or stop watering when needed. Include a maximum run time even in manual mode.
Low-water protection: A float switch in the reservoir can prevent the pump from running when the water level is too low. This is particularly useful when the pump must remain submerged during operation.
Watering schedule: A time-based restriction can prevent repeated watering during a short period. For example, the system can require a waiting period after a watering cycle before it considers another cycle.
For a beginner build, start with one sensor and one pump. Add features only after the sensor thresholds, pump run time and relay operation are working reliably.
Troubleshooting Common Irrigation Problems
The pump does not turn on. Check the relay's power, input pin and contact wiring. Confirm that the pump has a suitable 12V supply and that the Arduino's dry-soil threshold is being reached. Test the relay without the pump first.
The pump runs continuously. Your sensor may be disconnected, incorrectly calibrated or producing readings that remain above the dry threshold. Check the serial readings and confirm that the relay's active HIGH or active LOW logic matches the code.
The pump switches on and off too frequently. Use separate dry and wet thresholds, average sensor readings, and add a pause between watering cycles. Check that water is not reaching the sensor immediately and causing misleading readings.
The soil becomes too wet. Reduce the pump run time, measure the delivered water volume and reposition the sensor if necessary. A maximum run time and a low-water switch can improve protection, but they do not replace testing.
The sensor readings are unstable. Check the power and ground connections, keep sensor wiring away from pump wiring, and secure the sensor in the soil. Averaging readings can help with small fluctuations, but it will not correct a damaged sensor or a poor installation.
Conclusion
An Arduino Uno smart irrigation system can water plants automatically by combining a capacitive soil moisture sensor, a relay module and a 12V DC mini submersible pump. The Arduino reads the sensor, compares its output with calibrated thresholds and switches the pump when watering is needed.
For reliable operation, calibrate the sensor in your actual soil, limit pump run time, and allow water to spread before checking the moisture level again. Power the pump from a suitable 12V supply through a correctly rated relay or driver, never directly from an Arduino pin.
Start with a single potted plant, test the amount of water delivered, and adjust the thresholds before expanding the system. You can later add an ESP32, rain detection, manual control or a reservoir-level switch.
For your build, consider the 12V mini submersible water pump and a compatible 5V relay module. Check the pump's current requirements, the relay contact ratings and the sensor pinout before connecting the system.






