Automatic Irrigation System using Soil Moisture Sensor

Share This

Hello friends! Welcome back to ElectroDuino. This blog is based on the Automatic Irrigation System using Soil Moisture Sensor and Arduino. Here we will discuss the Introduction to Automatic Irrigation System using Soil Moisture Sensor, Project Concept, Block Diagram, Components Required, Circuit Diagram, Working Principle, and Arduino Code.

Introduction

Trees are performed a very important role in our life, they produce oxygen for us. Almost all of us love to plant trees in our garden, rooftop garden, and house (Indoor plants). It is not only necessary to plant trees, but also to take proper care of them, and water should be given regular basis. But in this busy life sometimes we forgot to water the plants, which damages our plants. To overcome this problem here we will be going to build an Automatic Plant watering system that automatically waters the plants without any human effort. This system continuously senses the moisture levels of the plant soil. When the soil moisture levels will decrease this device automatically water the plants. This system not only saves your time, it also saves the waste of water. This system is also known as the Automatic Plant Irrigation System.

This project is sponsored by PCBWay.com. It’s a Professional grate PCB prototype service company. They are providing you 10 high-quality PCBs at only 5$. At first register on the website, then fill in all the specifications like Dimensions, Layers, Thickness, color, and Quantity. In the last upload your Gerber files and place your Order Now. After completing all the processes, they produce your PCB prototype within 24 hours.
So, order now to get a high-quality PCB prototype quickly from PCBWay.com

PCBWay PCB Prototype the Easy Way Full feature custom PCB prototype service.
PCBWay PCB Prototype the Easy Way

Project Concept of Automatic Irrigation System using Soil Moisture Sensor and Arduino

This project is not that much of complex, few components are needed to build it. The key components of this project are Arduino Nano, Soil moisture sensor, DS18B20 Temperature sensor, Relay Module, 16×2 LCD Display, LED, and Water Pump. The Arduino nano is used as the main microcontroller of this system, where it is used to control the whole system. The Soil moisture sensor is used to sense the moisture levels of the plant soil. This sensor senses the soil moisture levels and produces output. When the Arduino detected the low moisture level in the soil by the sensor, then the Arduino gives the signal to the Relay module to turn on the Pump for automatically watering the plant. When there will enough water in the soil, the Arduino again sends a signal to the relay to stop the pump. The DS18B20 Temperature Sensor is used to measure the temperature of the soil. The LCD display shows the soil moisture levels, soil temperature, and pump status (on/off). The LEDs also used to indicate the pump status.

Block Diagram of Automatic Irrigation System using Soil Moisture Sensor and Arduino

Block Diagram of Automatic Irrigation System using Soil Moisture Sensor and Arduino, Introduction to Automatic Irrigation System using Soil Moisture Sensor, Project Concept, Block Diagram, Components Required, Circuit Diagram, Working Principle, and Arduino Code.
Block Diagram of Automatic Irrigation System using Soil Moisture Sensor and Arduino

For this project you should know:

Components Required

Components NameQuantity 
Arduino NANO (you can use other types of Arduino like Arduino UNO, MEGA, Pro mini, etc)1
Soil Moisture Sensor 1
DS18B20 Waterproof Temperature Sensor 1
1 Channel Relay Module 1
16×2 LCD Display Module1
220 ohm Resistor (R1, R2, R3)3
4.7K ohm Resistor (R4)1
10K ohm Potentiometer (VR1)1
Red LED (D1)1
Green LED (D2)1
DC Water Pump 1
9v Power Supply1
12v Power Supply1
Slide Switch 1
PCB board1
Connecting wiresAs required in the circuit diagram

 

Tools Required

Tools NameQuantity
Soldering Iron1
Soldering wire1
Soldering flux1
Soldering stand1
Multimeter1
Desoldering pump1
Wirecutter1

 

Software Required

Arduino IDE (Integrated Development Environment)

Arduino IDE (Integrated Development Environment)

 

Required Library

We need to add 2 libraries in Arduino IDE software. These are:

  • DallasTemperature library
  • OneWire library

*Click here to learn How to Download and install the DallasTemperature library and OneWire library 

Circuit Diagram/Schematic of Automatic Irrigation System using Soil Moisture Sensor and Arduino

Circuit Diagram/Schematic of Automatic Irrigation System using Soil Moisture Sensor and Arduino, Introduction to Automatic Irrigation System using Soil Moisture Sensor, Project Concept, Block Diagram, Components Required, Circuit Diagram, Working Principle, and Arduino Code.
Circuit Diagram/Schematic of Automatic Irrigation System using Soil Moisture Sensor and Arduino,

Working Principle of Automatic Irrigation System using Soil Moisture Sensor

After connecting all the components according to the circuit diagram, now we need to bury the soil moisture sensor probes (A and B) into the soil at the base of the plant. The sensor sends voltage by probe A and receives this voltage by Probe B through the soil and determines the resistivity of the soil and products Output values (0-1023). Arduino read these Output values from the Sensor pin, then Calculates the moisture levels (0-100%) and shows this data on the LCD display.

When the soil will dry, then its resistivity is high, and less current can pass between probes A & B through the soil. In this condition, the sensor produces High Analog Output values from its Analog output pin. This time Arduino calculate the moisture percentage using this output and logically understood that the soil is dry. When the Arduino calculates the moisture levels under 50%, Then the Arduino grounded (LOW) the input pin of the relay module to activate the relay. Now the relay module acts as a closed switch, that turned on the Pump to water the plants. At this time the RED LED is also turned ON, which indicates the soil is dry and the “Pump is ON” message is showing on LCD Display. The pump will run until the soil at the base of the plant is properly wetted.

 

When the Arduino detect the moisture percentage above the 50%, this time the Arduino gives +5V (HOGH) to the input pin of the relay module which deactivate the relay. As a result, the relay module acts as a open switch, that turns OFF the Pump. Now the Green LED starts glowing, which indicates that there is enough water in the soil.

During all these processes the DS18B20 Temperature Sensor continuously measure the soil temperature and print the temperature values on the LCD Display in Degree Celsius (°C) format.

 

Arduino Code for Automatic Plant Irrigation System

/* Automatic Irrigation System using Soil Moisture Sensor
More info: https://www.electroduino.com */

//Include librarie for LCD Display
#include <LiquidCrystal.h>
// Include librarie for DS18B20 Temperature Sensor
#include <OneWire.h>
#include <DallasTemperature.h>

// Define LCD display pins
const int RS = 3, EN = 4, D4 = 5, D5 = 6, D6 = 7, D7 = 8;
LiquidCrystal lcd (RS, EN, D4, D5, D6, D7);
// Define which pin of the Arduino is connected to DS18B20 Temperature Sensor
#define ONE_WIRE_BUS 9
// Define the Arduino pin which is connected to the Soil Moisture Sensor
const int sensorPin = A3;
// Define the Arduino pin which is connected to the relay Module
const int relayPin = 12;
// Define the Arduino pin which is connected to the Red LED
const int RED_LED_Pin = 11;
// Define the Arduino pin which is connected to the Green LED
const int GREEN_LED_Pin = 10;

// Create a new instance of the oneWire class to communicate with any OneWire device:
OneWire oneWire(ONE_WIRE_BUS);
// Pass the oneWire reference to DallasTemperature library:
DallasTemperature sensors(&oneWire);

void setup() 
 {
  // Begin serial communication at a baud rate of 9600
  Serial.begin(9600);
  // initialize LCD and set up the number of columns and rows
  lcd.begin(16, 2);

  // Start up the library:
  sensors.begin();

  // Set Arduino Pin as Input Pin 
  pinMode(sensorPin, INPUT);
  // Set Arduino Pin as Output Pin 
  pinMode(relayPin, OUTPUT);
  pinMode(RED_LED_Pin, OUTPUT);
  pinMode(GREEN_LED_Pin, OUTPUT);
  
  // Print Beginning Message on LCD Display
  lcd.setCursor(0,0);
  lcd.print("Automatic Plant");
  lcd.setCursor(0,1);
  lcd.print("Irrigation System");
  // Wait 2 second:
  delay(2000);
 }

void loop() 
 {
  // Send the command for all devices on the bus to perform a temperature conversion:
  sensors.requestTemperatures();

  // Fetch the temperature in degrees Celsius for device index:
  float tempC = sensors.getTempCByIndex(0); // the index 0 refers to the first device
  // Print the temperature in Celsius in the Serial Monitor:
  Serial.print("Temperature: ");
  Serial.print(tempC);
  Serial.print((char)223); // shows degree symbol
  Serial.print("C ");

  // Read Output Value from Soil Moisture Sensor
  int sensorValue = analogRead(sensorPin);
  // Print Output Value on the Serial Monitor:
  Serial.print("Soil Sensor Output Value:");
  Serial.print(sensorValue); 

  // Calculate moisture Percentage
  float moisture_Percentage;
  moisture_Percentage=  ( 100 - ( (sensorValue/1023.00) * 100 ) );
  Serial.print("Moisture Percentage = ");
  Serial.print(moisture_Percentage);
  Serial.println("%\n");
  
// When moisture Percentage is less equal to 30%. It means Soil is Dry
if(moisture_Percentage<=30)
 {
  digitalWrite (relayPin,LOW);      // Relay ON
  digitalWrite (RED_LED_Pin, HIGH); // RED LED ON
  digitalWrite (GREEN_LED_Pin, LOW);// GREEN LED OFF

  // Clear LCD Display
  lcd.clear();
  //Print the Soil Moisture Percentage on LCD Display
  lcd.setCursor(0, 0);  // Set the Message Position at the First Row
  lcd.print("Moisture: ");
  lcd.print(moisture_Percentage);
  lcd.print("%");

  //Print the temperature in Celsius on LCD Display
  lcd.setCursor(0, 1);  // Set the Message Position at the First Row
  lcd.print("Temp: ");
  lcd.print(tempC);     // Print the Temperature in Celsius
  lcd.print((char)223); // Print ° character
  lcd.print("C");
  delay(1000);

  // Clear LCD Display
  lcd.clear();
  
  //Print the Soil Moisture Percentage on LCD Display
  lcd.setCursor(0, 0);  // Set the Message Position at the First Row
  lcd.print("Moisture: ");
  lcd.print(moisture_Percentage);
  lcd.print("%");
  
  //Print Pump ON Messge on LCD Display
  lcd.setCursor(0, 1);  // Set the Message Position at the First Row
  lcd.print("Pump is ON "); 
  // Wait 1 second:
  delay(1000);
}
// When moisture Percentage is greater than 30%.
 else 
 {
  digitalWrite (relayPin, HIGH); // Relay OFF
  digitalWrite (RED_LED_Pin, LOW); // RED LED OFF
  digitalWrite (GREEN_LED_Pin, HIGH); // GREEN LED ON

  // Clear LCD Display
  lcd.clear();
  //Print the Soil Moisture Percentage on LCD Display
  lcd.setCursor(0, 0);  // Set the Message Position at the First Row
  lcd.print("Moisture: ");
  lcd.print(moisture_Percentage);
  lcd.print("%");

  //Print the temperature in Celsius on LCD Display
  lcd.setCursor(0, 1);  // Set the Message Position at the First Row
  lcd.print("Temp: ");
  lcd.print(tempC);     // Print the Temperature in Celsius
  lcd.print((char)223); // Print ° character
  lcd.print("C");
  delay(1000);
  }
}

 

Share This

Leave a Reply

Your email address will not be published. Required fields are marked *