How to make an irrigation monitoring system with Raspberry Pi board
Hello and welcome back. In this project, we will learn how to make an irrigation monitoring system with a Raspberry Pi board. For that, I mainly used a soil moisture sensor. Also, we can get the soil moisture values through this sensor and we can make a decision using these values. In this project, you can control a water pump using these values. For that, I added a relay module. (Remember to use a relay module that matches the amperage of the motor you are using) In this project, I used a 10A relay module and a small water pump for the example.
Also, we can see different types of soil moisture sensors in the market, but all these sensors work in the same way. So, I decided to use the following sensor. If you want to learn more about this sensor in deeply, please use this link. If you want to make a simple and low-cost irrigation monitoring system, this is the best solution for you.
- If you want to do this project with the ESP8266 board – Click me
OK, let’s do this project step by step. The required components are given below.
- Raspberry Pi board x 1 — 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
- Breadboard x 1 — Our Store / Amazon
- GPIO Extension board x 1 — Our Store / Amazon
- GPIO Ribbon cable x 1 — Our Store / Amazon
- Male to Female Jumper wires x 7 — Our Store / Amazon
- Male to Male jumper wires x 11 — Our Store / Amazon
- Mini water pump — Amazon
- Mini water pipe — Amazon
Disclosure: These Amazon links are Affiliate links. As an Amazon Associate, I earn from qualifying purchases.
Step 1
Firstly, identify these components.
Step 2
Secondly, place the GPIO extension board on the breadboard. And then, connect the GPIO ribbon cable to it. (if you are using a GPIO extension board and ribbon cable)
Step 3
Thirdly, connect the soil moisture sensor and push-button to the extension board. For that, use the circuit diagram below.
Step 4
And then, connect the LCD screen and relay module to the extension board. Please provide an external power supply to the relay module.
Step 5
Now, connect the water pump to the relay module and place the sensor probe on the soil.
Step 6
Next, connect the ribbon cable, mouse, keyboard, monitor, and SD card(OS installed) to the raspberry pi board. And then, provide a power supply to the Raspberry pi board.
Step 7
Next, enable I2C communication. For that, follow the instructions below.
- If you want to see the I2C address, run the following command on the terminal.
- i2cdetect -y 1
Step 8
OK, now let’s create the python script for this project. It’s as follows. You can copy and paste this script on the Thonny IDE.
- Full details of this project — Download
- The I2C library is included in this folder.
# Include the library files
import I2C_LCD_driver
from time import sleep
from smbus import SMBus
import RPi.GPIO as GPIO
bus = SMBus(1)
button = 17
relay = 27
motorstatus = True
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
# Set the button pin as Input pin
GPIO.setup(button,GPIO.IN,pull_up_down=GPIO.PUD_UP)
#Set the relay pin as output pin
GPIO.setup(relay,GPIO.OUT)
GPIO.output(relay,GPIO.HIGH) # Relay turns OFF
# Create a object for the LCD
lcd = I2C_LCD_driver.lcd()
# Starting text
lcd.lcd_display_string("System Loading",1,1)
for a in range (0,16):
lcd.lcd_display_string(".",2,a)
sleep(0.1)
lcd.lcd_clear()
lcd.lcd_display_string("Motor :OFF" ,2,0)
#Get the analog input values
def moistureValue():
bus.write_byte(0x4b,0x84)# A0
value = bus.read_byte(0x4b)
value = (value/255) * 100
value = (value - 100) * -1
value = int(value)
lcd.lcd_display_string("Moisture:" + str(value) + "% " ,1,0)
while True:
moistureValue()
if GPIO.input(button) == 0: # Get the button value
if motorstatus:
GPIO.output(relay,GPIO.LOW) # Relay turns ON
lcd.lcd_display_string("Motor :ON " ,2,0)
sleep(0.5)
motorstatus = False
elif motorstatus == False:
GPIO.output(relay,GPIO.HIGH) # Relay turns OFF
lcd.lcd_display_string("Motor :OFF" ,2,0)
sleep(0.5)
motorstatus = True
Step 9
Now, save this script on your computer and click the run button.
Now, you can test this project. The full video guide is below. So, see you in the next project or tutorial.
How to make an irrigation monitoring system with Raspberry Pi board