Arduino - Automatic Irrigation System

The automatic irrigation system is a part of the smart garden. In this tutorial, We are going to learn how to make an automatic irrigation system for the garden using Arduino, a soil moisture sensor, relay, and pump. In detail:

Hardware Required

1×Arduino UNO or Genuino UNO
1×USB 2.0 cable type A/B
1×Capacitive Soil Moisture Sensor
1×12V Pump
1×Vinyl Tube
1×12V Power Adapter
1×DC Power Jack
1×Jumper Wires
1×(Optional) 9V Power Adapter for Arduino
Please note: These are affiliate links. If you buy the components through these links, We may get a commission at no extra cost to you. We appreciate it.

About soil moisture sensor and Pump

If you do not know about pump and soil moisture sensor (pinout, how it works, how to program ...), learn about them in the following tutorials:

Wiring Diagram

Arduino soil moisture sensor Pump Wiring Diagram

This image is created using Fritzing. Click to enlarge image

Arduino Code

/* * Created by * * This example code is in the public domain * * Tutorial page: */ #define RELAY_PIN 2 // Arduino pin that connects to relay #define MOISTURE_PIN A0 // Arduino pin that connects to AOUT pin of moisture sensor #define THRESHOLD 100 // CHANGE YOUR THRESHOLD HERE void setup() { Serial.begin(9600); pinMode(RELAY_PIN, OUTPUT); } void loop() { int value = analogRead(MOISTURE_PIN); // read the analog value from sensor if (value < THRESHOLD) { Serial.print("The soil is DRY => turn pump ON"); digitalWrite(RELAY_PIN, HIGH); } else { Serial.print("The soil is WET => turn pump OFF"); digitalWrite(RELAY_PIN, LOW); } Serial.print(" ("); Serial.print(value); Serial.println(")"); delay(500); }

Quick Steps

  • Do calibration to determine the wet-dry THRESHOLD, see Arduino - Calibrates Soil Moisture Sensor
  • Update the calibrated THRESHOLD value in the code
  • Open Serial Monitor on Arduino IDE
  • Upload the code to Arduino
  • See the result on Serial Monitor.
The soil is DRY => turn pump ON (12) The soil is DRY => turn pump ON (21) The soil is DRY => turn pump ON (41) The soil is DRY => turn pump ON (64) The soil is WET => turn pump OFF (265) The soil is WET => turn pump OFF (311) The soil is WET => turn pump OFF (365) The soil is WET => turn pump OFF (375)
Autoscroll Show timestamp
Clear output
9600 baud  

Code Explanation

Read the line-by-line explanation in the comment lines of the source code!

Video Tutorial

We are considering to make the video tutorials. If you think the video tutorials are essential, please subscribe to our YouTube channel to give us motivation for making the videos.

The Best Arduino Starter Kit