Smart Home Gardening System Using Raspberry Pi

Detects if there is a need to water the plants and if so, the water will be sprinkled onto the plants automatically without human help.

The Problem

In today’s era everyone wishes to live in a green environment, and hence wishes to have at least a small garden in their home. Even if they don’t have a place for gardening in their plot, they wish to have a terrace garden. Many people invest in a garden, but they fail to maintain it when they go for a vacation or often forget to water the plants. Plants will shrivel up and die. To prevent plants from being shriveled and dead, in our project we are building a system that detects if there is a need for watering the plants and if so, the water will be sprinkled onto the plants automatically without the need of human assistance.

The Solution

The system is built using a soil moisture sensor and a Raspberry Pi-controlled water pump. The soil moisture sensors measure the amount of water in the soil to maintain consistent and ideal soil conditions for plants. In this project, the soil moisture sensor interfaces with the Raspberry Pi, which then detects the dryness in the soil; if the moisture level is very low, this implies there is a need for watering the plants. It signals the Raspberry Pi about the moisture level being too low. The Raspberry Pi turns on the water pump to start watering the plants until the soil achieves a sufficient moisture level and then turns off the water pump.

The benefit of using smart home gardening is that it prevents our plants from getting too dry. The moisture is kept at the perfect level for our plants and we end up using less water!

Schematics

Code

#!/usr/bin/env python
# encoding: utf-8


import os
import smtplib
from email import encoders
from email.mime.base import MIMEBase
from email.mime.multipart import MIMEMultipart
import RPi.GPIO as GPIO
from time import sleep

COMMASPACE = ', '

def SendEMail():
    sender = '[email protected]'
    gmail_password = '9620955777'
    recipients = ['[email protected]']
    
    # Create the enclosing (outer) message
    outer = MIMEMultipart()
    outer['Subject'] = 'Soil is about to dry and water will be poured'
    outer['To'] = COMMASPACE.join(recipients)
    outer['From'] = sender
    outer.preamble = 'You will not see this in a MIME-aware mail reader.\n'

   

    composed = outer.as_string()

    # Send the email
    try:
        with smtplib.SMTP('smtp.gmail.com', 587) as s:
            s.ehlo()
            s.starttls()
            s.ehlo()
            s.login(sender, gmail_password)
            s.sendmail(sender, recipients, composed)
            s.close()
        print("Email sent!")
    except:
        print("Unable to send the email. Error: ", sys.exc_info()[0])
        raise


GPIO.setmode(GPIO.BCM)

GPIO.setup(17, GPIO.IN)

GPIO.setup(23, GPIO.OUT)


GPIO.output(23, GPIO.HIGH)



while (True):
    
    if GPIO.input(17):
        print("Need to Water The Garden and Water Pump will be Switched On")
        SendEMail()
        GPIO.output(23, GPIO.LOW)
        while (True):
            if not GPIO.input(17):
                GPIO.output(23, GPIO.HIGH)
                break
    else:
        print("Soil has enough Moisture")

Source: Smart Home Gardening System Using Raspberry Pi

Scroll to Top
Read previous post:
GOOGLE CORAL – AN I.MX8M DEV BOARD WITH EDGE TPU AI CHIP
GOOGLE CORAL – AN I.MX8M DEV BOARD WITH EDGE TPU AI CHIP

Single board computers are not a new wonder anymore and the market has already experienced so many different devices based...

Close