Home automation

Swapnil Bhoite
4 min readSep 21, 2019

Water your plants at home from anywhere in the world!

The gist of this post here.

The idea

When I got my plants for the first time, it kept me thinking what I’m going to when I’ll be gone for long vacations, for a month or so. So I thought of this automation idea. At first, it could seem too much to do but as my collection of plants grew then I thought let’s just do it. I’m sure that a lot of people face this same issue, so I hope this guide would help out some of the geeks out there. I’ll try to get in details as much as possible but won’t get in-depth for topics out of scope like networking etc.

Prerequisites

Components

You can get them from anywhere you want, I’ll just put where I got them from.

Drip irrigation stuff (The Home Depot):

Electronics (most of them from Amazon):

  • 12V DC Water pump and power supply adapter for the same
  • DC 5V Relay Module This relay even can control the AC water pump as well!
  • Few jumper wires
  • Raspberry Pi setup, get a kit if you are a beginner
  • Some long wires which would go from the place where you are going to keep raspberry to the water pump. I would recommend keeping Raspberry Pi in cool, indoor place and water pump near to plants and water container.

Let’s do it!

The irrigation set up

  • First thing you should do is set up the drip irrigation. Spread the drip irrigation tube across all your planters, cut the pipe and install inline drippers appropriately. Connect the drip irrigation tube to the outlet of water pump using manifold and barb adapter. Once this is set up, test it by turning the water pump on. Make sure that there’s even flow to all planters.
  • Make sure that your water container is below the planters otherwise all water would drain automatically.
  • Make sure that the water pump is below or at least at the bottom level of the water container because most of these 12V pumps do not pump the water if all the water from the inlet is gone or there is an air gap in the inlet pipe. Some of the pumps are waterproof, so if yours is, you can just put it in the container at the bottom.

Automation (via ssh)

Once you know that the drip irrigation set up is working properly, now it’s time to do the automation!

Set up the Raspberry Pi:

  • Follow these instructions to get started with Raspberry Pi and get it up and running.
  • Set up SSH to access your Raspberry Pi on the internet. For this, you’ll need to forward a port on your router. Google the instructions to do so depending on the what router you have. After you do this, consider adding some security measures to prevent unauthorized access to your Raspberry Pi. You can do this later after the project is complete. I’m using MFA. (This is a bit tricky, let me know in comments if you run into any problems)

Connections

  • The Raspberry Pi operates on 5V whereas our water pump operates on 12V hence we need a relay (or some other motor driver). This relay takes a digital input 0 or 1 and would turn the water pump on or off.
  • Follow these instructions for the connections.
  • Raspberry Pi GPIO: https://pinout.xyz/
  • I have connected GPIO17 to the relay input.

Coding

  • SSH to your PI
  • Optionally create a directory to work in
mkdir Work cd Work
  • Create a file, say test.py. I'm using vim as my editor, you can use editor of your choice
sudo apt update
sudo apt install vim
touch test.py
  • The relay I’m using operates on low, meaning it connects the channel (turns the water pump ON) when digital 0 is put on the input and turns it off when digital 1 is present. Simple python code to turn the water pump ON for 10 seconds and then turning it OFF:
from gpiozero import LED
from time import sleep
led = LED(17)led.off()
sleep(10)
led.on()
  • Not that led.off() would make the water pump ON because like I mentioned, this relay operates on digital low.
  • If everything is working as expected, congratulations we are done! Adjust the sleep(<time>) as needed depending on how many planters you have.
  • A little bit fancy script that I run which prints the time as well:
from gpiozero import LED
from time import sleep
gnd = LED(17)
gnd.on()
def job():
total = 180
i = 0
print('Turning the pump ON!')
gnd.off()
while i < total:
print('Time: {}/{}'.format(i + 1, total))
sleep(1) i += 1
print('Turning the pump OFF!')
gnd.on()
job()

What next?

  • You can automate the task by running it automatically at some time in the day using schedule in python.
  • You can integrate this with smart assistants like Google Assistant/Amazon Alexa etc. (I’m currently halfway through this)

Thank you :)
Swapnil http://swapnilbhoite.dev

Let me know in comments if you get stuck on something.

--

--