How to make an automatic irrigation and plant watering system using Arduino and soil moisture sensor | Step by step instruction
Hello, welcome back. In this tutorial, I will show you how to make an automatic irrigation and plant watering system using Arduino and a soil moisture sensor. Also, we can control the water supply automatically through this system. This can be done in such a way that when the soil is dry, the motor automatically activates and when the soil gets wet, it becomes inactive again. Also, we can use this project for mainly Small gardens, flower gardens, or greenhouses. The soil moisture sensor is mainly used for this project. An LCD display is also used to monitor the soil moisture level. You can also connect a motor pump to the relay module.
The process of this irrigation system
Insert the soil moisture sensor probe into the soil while the system is operating. The moisture content will then be displayed on the LCD as Low, Medium, or High. The relay module will automatically activate when the moisture level is LOW and deactivate when it is MEDIUM or HIGH. If a water pump is connected to the relay module, it will automatically turn on and off based on the moisture levels.
So, let’s do this project step by step. The required components are given below.
- Arduino UNO board x 1 — Our Store / Amazon
- Soil moisture sensor x 1 — Our store / Amazon
- Relay module x 1 — Our Store / Amazon
- LCD display x 1 — Our Store / Amazon
- I2C module x 1 — Our Store / Amazon
- Battery holder x 1 — Our Store / Amazon
- Li-ion battery x 2 — Our store / Amazon
- Jumper wires — Our Store / Amazon
- Foamboard — Amazon
Disclosure: These Amazon links are Affiliate links. As an Amazon Associate, I earn from qualifying purchases.
Step 1
Firstly, identify these components.
Arduino UNO board
Soil moisture sensor
Relay module
LCD display
I2C module
Li-ion battery and Battery holder
Jumper wires
Foamboard
You can use foam board or cardboard.
Step 2
Second, cut the foam board pieces as follows.
Step 3
Thirdly, adjust the 1.5 x 3-inch piece to fit the Arduino board and glue it to the 3 x 4.5-inch piece.
Step 4
Now, glue the 1.5 x 4.5-inch piece to the base piece.
Step 5
Then, connect the relay module and soil moisture sensor to the Arduino board. For that, use the circuit diagram below.
Step 6
OK, now glue the Soil moisture sensor to the base piece. Then, take a 3 x 4.5-inch piece and attach the LCD to its center.
Step 7
Now, glue the 1.5 x 3-inch piece to the base foam board piece. Then, connect the LCD to the Arduino board.
Step 8
Next, attach the relay module as follows. Then, glue the 1.5 x 4.5-inch piece to the base foam board to fit the relay module.
Step 9
Now, glue the top lid on this project and connect this project to the computer.
Step 10
OK, let’s create the program for this project. It is as follows.
/*How to make an Irrigation system.
* This code creates by the SriTu Hobby team.
* https://srituhobby.com
*/
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C dis(0x27, 16, 2);
void setup() {
Serial.begin(9600);
dis.init();
dis.backlight();
dis.clear();
pinMode(2, OUTPUT);
digitalWrite(2, HIGH);
delay(1000);
dis.setCursor(0, 0);
dis.print("IRRIGATION");
dis.setCursor(0, 1);
dis.print("SYSTEM IS ON ");
for (int a = 12; a <= 15; a++) {
dis.setCursor(a, 1);
dis.print(".");
delay(1500);
}
dis.clear();
}
void loop() {
int value = analogRead(A0);
Serial.println(value);
if (value > 950) {
digitalWrite(2, LOW);
dis.setCursor(0, 0);
dis.print("MOTOR IS ON ");
} else {
digitalWrite(2, HIGH);
dis.setCursor(0, 0);
dis.print("MOTOR IS OFF");
}
if (value < 300) {
dis.setCursor(0, 1);
dis.print("MOISTURE : HIGH");
} else if (value > 300 && value < 950) {
dis.setCursor(0, 1);
dis.print("MOISTURE : MID ");
} else if (value > 950) {
dis.setCursor(0, 1);
dis.print("MOISTURE : LOW ");
}
}
Code explanation
First, the I2C library is included and creates the object for this library. It includes the I2C address and the LCD height and width.
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C dis(0x27, 16, 2);
In the setup function, the LCD is started and the relay module connected pin set as output. Also printed on the LCD as “IRRIGATION SYSTEM IS ON”.
void setup() {
Serial.begin(9600);
dis.init();
dis.backlight();
dis.clear();
pinMode(2, OUTPUT);
digitalWrite(2, HIGH);
delay(1000);
dis.setCursor(0, 0);
dis.print(“IRRIGATION”);
dis.setCursor(0, 1);
dis.print(“SYSTEM IS ON “);
for (int a = 12; a <= 15; a++) {
dis.setCursor(a, 1);
dis.print(“.”);
delay(1500);
}
dis.clear();
}
In the loop function, the sensor values are taken and inserted into the variable named “value”. Afterward, if these values are less than 300, they are printed as “HIGH” on the LCD, “MID” between 300 and 950, and “LOW” above 950. Also. If the value is greater than 950, the relay module is activated.
void loop() {
int value = analogRead(A0);
Serial.println(value);
if (value > 950) {
digitalWrite(2, LOW);
dis.setCursor(0, 0);
dis.print(“MOTOR IS ON “);
} else {
digitalWrite(2, HIGH);
dis.setCursor(0, 0);
dis.print(“MOTOR IS OFF”);
}
if (value < 300) {
dis.setCursor(0, 1);
dis.print(“MOISTURE : HIGH”);
} else if (value > 300 && value < 950) {
dis.setCursor(0, 1);
dis.print(“MOISTURE : MID “);
} else if (value > 950) {
dis.setCursor(0, 1);
dis.print(“MOISTURE : LOW “);
}
}
Step 11
OK, now select board and port. After, upload this code to the Arduino board.
Step 12
Lastly, install the battery holder on this project and connect it to the Arduino board. OK, enjoy this project. The full video guide is given below. So, we will meet in the next tutorial. Have a good day.
Enak main feel sama lihat history bang… biar menangnya konsisten.
Thank you
LCD display does not display anything, kindley help me.
Please check your jumper wires or LCD.
Is a nice project.
Can you a integratet DHT11 and a FAN please. This make it than compleet. Thanks friend
Ok sure
Thank you…
It’s working fine, can you please use esp8266 together with arduino and integrate DHT11 and Fan, rain sensor…..
This sounds great and I’m looking forward to making it for my plants. How would you add multiple sensors to the project so you can water more than a single plant? Thanks for the tutorial.
How would you add blynk app if you want to control it via device?
it showing this type pf error what should i do
C:\Users\aadi\Downloads\irrigation_system\irrigation_system.ino:1:9: fatal error: LiquidCrystal_I2C.h: No such file or directory
#include
^~~~~~~~~~~~~~~~~~~~~
compilation terminated.
exit status 1
Compilation error: LiquidCrystal_I2C.h: No such file or directory