Arduino Nano - Irrigation

This tutorial instructs you how to construct an automated irrigation system for your garden by using Arduino Nano, a soil moisture sensor, a relay, and a pump. Specifically:

Hardware Preparation

1×Arduino Nano
1×USB A to Mini-B USB cable
1×Capacitive Soil Moisture Sensor
1×Relay
1×12V Pump
1×Vinyl Tube
1×12V Power Adapter
1×DC Power Jack
1×Jumper Wires
1×Breadboard
1×(Recommended) Screw Terminal Expansion Board for Arduino Nano
1×(Recommended) Breakout Expansion Board for Arduino Nano
1×(Recommended) Power Splitter For Arduino Nano

Or you can buy the following sensor kits:

1×DIYables Sensor Kit (30 sensors/displays)
1×DIYables Sensor Kit (18 sensors/displays)
Disclosure: Some of the links provided in this section are Amazon affiliate links. We may receive a commission for any purchases made through these links at no additional cost to you.
Additionally, some of these links are for products from our own brand, DIYables.

Overview of soil moisture sensor and Pump

If you are unfamiliar with the pinout, functionality, and programming of a pump and soil moisture sensor, the following tutorials can help:

Wiring Diagram

The wiring diagram between Arduino Nano and soil moisture sensor Pump

This image is created using Fritzing. Click to enlarge image

Arduino Nano Code

/* * This Arduino Nano code was developed by newbiely.com * * This Arduino Nano code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-nano/arduino-nano-irrigation */ #define RELAY_PIN 2 // The Arduino Nano pin that connects to relay #define MOISTURE_PIN A6 // The Arduino Nano pin that connects to AOUT pin of moisture sensor #define THRESHOLD 530 // 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); }

Detailed Instructions

  • Calibrate the wet-dry THRESHOLD by following the instructions in Arduino Nano - Calibrates Soil Moisture Sensor.
  • Afterwards, update the calibrated THRESHOLD value in the code.
  • Open the Serial Monitor on the Arduino IDE and upload the code to the Arduino Nano.
  • Finally, view the result on the Serial Monitor.
COM6
Send
The soil is DRY => turn pump ON The soil is DRY => turn pump ON The soil is DRY => turn pump ON The soil is DRY => turn pump ON The soil is WET => turn pump OFF The soil is WET => turn pump OFF The soil is WET => turn pump OFF The soil is WET => turn pump OFF
Autoscroll Show timestamp
Clear output
9600 baud  
Newline  

Code Explanation

Check out the line-by-line explanation contained in the comments of the source code!

Video Tutorial

※ OUR MESSAGES

  • As freelancers, We are AVAILABLE for HIRE. See how to outsource your project to us
  • Please feel free to share the link of this tutorial. However, Please do not use our content on any other websites. We invested a lot of effort and time to create the content, please respect our work!