Automated Irrigation System using Arduino
An automated irrigation system is a great first project for anyone who wants to build something useful. It checks how wet the soil is with a soil moisture sensor, shows the reading on a screen, and switches on a small water pump by itself when the soil gets dry. In this guide you will build one using an Arduino Uno, a soil moisture sensor, an I2C LCD display and a relay module.
You get the full parts list, wiring tables, ready-to-upload code, troubleshooting tips and upgrade ideas. New to Arduino? Read our essential Arduino sensors guide first, or browse more Arduino mini projects.
How an automated irrigation system works
The system repeats three steps again and again:
1. Sense
The soil moisture sensor gives an analog value that changes with how wet the soil is. The Arduino reads it on pin A0.
2. Think
The Arduino turns the reading into a percentage and compares it with a threshold, for example 60%.
3. Act
If the soil is dry, the relay switches the pump ON. When the soil is wet enough, the relay switches it OFF. The LCD shows both values.
Components required
Arduino Uno or compatible board
The brain of the system. It reads the sensor, drives the LCD and controls the relay.
Soil moisture sensor module
The probe goes into the soil and the module sends an analog signal to the Arduino.
16x2 I2C LCD display
Shows the moisture percentage and the pump status. The I2C backpack needs only four wires.
5V relay module
The Arduino cannot power a pump directly. The relay switches the pump circuit for it.
Water pump (DC motor)
A small submersible pump that waters the plant when the relay turns on.
Male to female jumper wires (10)
Connect the sensor, LCD and relay to the Arduino pins.
Female to female jumper wires (4)
Used for the I2C LCD connections to the Arduino header pins.
Wiring: pin connections
Use these pins so the code below works without changes. The pump circuit is switched by the relay, so it stays separate from the Arduino side.
Circuit diagram: Arduino, soil moisture sensor, I2C LCD, relay, pump and 9V battery. The diagram uses a generic Arduino board symbol, so wire to an Arduino Uno as in the tables below.
Soil moisture sensor to Arduino
| Sensor pin | Arduino pin |
|---|---|
| VCC | 5V |
| GND | GND |
| AO | A0 |
I2C LCD to Arduino
| LCD pin | Arduino pin |
|---|---|
| VCC | 5V |
| GND | GND |
| SDA | A4 (SDA) |
| SCL | A5 (SCL) |
Relay module to Arduino
| Relay pin | Arduino pin |
|---|---|
| VCC | 5V |
| GND | GND |
| IN | D2 |
Pump and battery
| Connection | Goes to |
|---|---|
| Relay COM | 9V battery negative (−) |
| Relay NO | Pump (motor) negative (−) |
| Pump (motor) positive (+) | 9V battery positive (+) |
Keep the Arduino, LCD and relay away from water. Only the probe and the pump go near the plant. Wiring problems cause most failures, so see wrong sensor connections and incorrect power supply if something does not work.
Moisture level and pump control
| Moisture level | Soil condition | Relay | Pump |
|---|---|---|---|
| 0 – 30% | Dry | ON | ON |
| 31 – 60% | Normal | ON | ON |
| 61 – 100% | Wet | OFF | OFF |
In the code the threshold is 60%: the pump runs while the reading is 60% or lower and stops above it. Change MOISTURE_THRESHOLD to suit your plant and soil.
Step-by-step assembly
Prepare the plant pot
Place the plant in a pot with a tray or a small container of water for the pump. Push the sensor probe into the soil near the roots.
Wire the LCD
Connect VCC, GND, SDA and SCL of the I2C LCD to 5V, GND, A4 and A5.
Wire the soil sensor
Connect VCC and GND to 5V and GND, and the AO pin to A0.
Wire the relay and pump
Connect the relay VCC, GND and IN to 5V, GND and D2. Then wire COM, NO and the pump as shown in the pump and battery table.
Add power
Power the Arduino from USB or an adapter and connect the 9V battery to the pump circuit. Keep the pump out of the water until you have tested.
Upload and calibrate
Upload the code, then follow the calibration steps below so the percentage matches your sensor.
Arduino code
Open the Arduino IDE and install the library LiquidCrystal I2C (by Frank de Brabander) from Sketch > Include Library > Manage Libraries. Then paste the code, select your board and port, and click Upload.
Automated irrigation system
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2); // try 0x3F if the LCD stays blank
const int SENSOR_PIN = A0;
const int RELAY_PIN = 2;
const int DRY_VALUE = 1023; // reading with the sensor in dry air
const int WET_VALUE = 300; // reading with the sensor in water
const int MOISTURE_THRESHOLD = 60; // pump ON at or below this %
const bool RELAY_ACTIVE_LOW = true; // most relay modules switch ON with LOW
void setRelay(bool on) {
digitalWrite(RELAY_PIN, (on == RELAY_ACTIVE_LOW) ? LOW : HIGH);
}
int readMoisture() {
long total = 0;
for (int i = 0; i < 10; i++) {
total += analogRead(SENSOR_PIN);
delay(10);
}
int raw = total / 10;
int percent = map(raw, DRY_VALUE, WET_VALUE, 0, 100);
return constrain(percent, 0, 100);
}
void setup() {
setRelay(false); // keep the pump OFF at start
pinMode(RELAY_PIN, OUTPUT);
setRelay(false);
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Auto Irrigation");
lcd.setCursor(0, 1);
lcd.print("System Ready");
delay(2000);
lcd.clear();
}
void loop() {
int moisture = readMoisture();
bool pumpOn = (moisture <= MOISTURE_THRESHOLD);
setRelay(pumpOn);
lcd.setCursor(0, 0);
lcd.print("MOISTURE: ");
lcd.print(moisture);
lcd.print("% ");
lcd.setCursor(0, 1);
lcd.print("PUMP: ");
lcd.print(pumpOn ? "ON " : "OFF");
lcd.print(" ");
delay(500);
}
How the code works
- readMoisture() averages ten readings from A0 and converts them to a 0 to 100% value with map().
- setRelay() switches the relay ON or OFF, and handles relay modules that work with a LOW or a HIGH signal.
- loop() turns the pump ON when the moisture is at or below the threshold, then updates both lines of the LCD every half second.
- DRY_VALUE and WET_VALUE are the two calibration numbers for your own sensor.
Calibrate and tune your system
analogRead(A0) to the Serial Monitor with the probe in dry air and note the number.Troubleshooting
| Problem | What to check |
|---|---|
| The LCD is blank or shows blocks | Turn the contrast screw on the I2C backpack, or change the address from 0x27 to 0x3F. |
| The pump runs when the soil is wet | Your relay is active HIGH. Set RELAY_ACTIVE_LOW to false. |
| Moisture stays at 0% or 100% | Check the AO to A0 wire and recalibrate DRY_VALUE and WET_VALUE. |
| The relay clicks but the pump does not run | Check the COM, NO and pump wires and the 9V battery. |
| Readings jump around | Push the probe fully into the soil and keep the sensor wires short. |
| The probe corrodes quickly | Resistive probes wear out in wet soil. Do not keep them powered when not needed. |
Upgrade ideas
More ideas: see our Top 20 STEM projects and 20 Arduino mini projects.
Frequently asked questions
What is an automated irrigation system?
It is a system that waters plants on its own. A sensor checks the soil, a controller such as an Arduino decides when water is needed, and a pump delivers it, so nobody has to water by hand.
Can I use an ESP32 instead of an Arduino Uno?
Yes. Use a sensor that works at 3.3 V, change the pin numbers in the code and use the ESP32 I2C pins for the LCD.
Why do I need a relay for the pump?
An Arduino pin cannot supply the current a pump needs. The relay lets a small signal from D2 switch the separate 9V pump circuit.
Can I water more than one plant?
Yes. Add one sensor on A1, A2 and so on, and one relay and pump for each plant.
Is the soil moisture sensor reading accurate?
Resistive sensors give a good guide, not a lab measurement. Calibrate with dry air and water, and replace the probe when it corrodes.
Electronics learning with Robopro.in
At Robopro.in, students and makers can find Arduino boards, sensors, relays, pumps and displays for building practical projects.
Ready to build your automated irrigation system?
Get every part for this project in one place. Schools and STEM labs can also order in bulk.
Shop agricultural sensors Bulk orders for schools Contact usConclusion
An automated irrigation system teaches sensing, decision making and output control in one simple project. Once it works, you can add Wi-Fi, a buzzer alert or a water level sensor and keep learning.