IOT Water Pistol/plant Waterer

Introduction: IOT Water Pistol/plant Waterer

This is a fun project that uses the Google Home or any phone with Google assistant on it to spray water at someone or water some plants. It also has a lot of potential application for other uses such as lights, heating, fans e.t.c. If you like this then please vote for this projects in the IOT competition. Thanks.

Step 1: Resources Needed

You will need the following:

  • A raspberry pi(any model that has access to the internet)
  • A 12v water pump(This is the one I used)
  • A 12v power supply(Use this one or one lying around)
  • A 5v 2 channel relay(This is the type that I used)
  • Some female to female jumper leads
  • A plastic box to hold water
  • Some way for the water to be squirted out of the pump(I bent a plastic tube but you could just use a straw)

We used relays as it allows to remotely turn it on with the raspberry pi rather than having to physically be there to turn on it on as you would if it was just a switch.

Step 2: Google Assistant

Make sure you have some way of accessing Google assistant. You could use a google home or a phone.

Step 3: Cutting Wires

Use wire cutters to cut and then strip the ends off your 12v supply and pump so they can be attached to the relay. Make sure to strip enough of the sheath to allow a solid connection.

Step 4: Attach Pump to Relay

  1. Unscrew the middle terminal on both relays
  2. Insert wires from the water pump
  3. Screw in again

Step 5: Attaching Power Supply to Relay

  1. Unscrew terminals
  2. put wires from the 12v power supply in
  3. Screw them back into place

Step 6: Connecting Raspberry Pi to Relay

Connect raspberry pi to relay as shown in the diagram above. You will need to connect the relay to ground, 5v, and 2 GPIO pins.

Step 7: Securing the Pump

Use either blu-tack or duct tape to secure the pump into a plastic container.

Step 8: Directing Water

If you want the water to squirt someone in the face it needs to be directed. To do this I used a heat gun to bend a plastic tube into the shape shown above. I then taped a pen lid onto the top. Alternatively, you could use a straw.

If you want to water some plants you could add a plastic tube or the inside of a pen.

Step 9: Putting Everything Together

I added another plastic box and put the raspberry pi and relay into it to stop it getting wet.

I have included a circuit diagram above to make the circuitry a little clearer.

Step 10: Testing Hardware Works

To test the pump works run the following code on the raspberry pi. This should turn the pump off and then on(or the other way round).

from gpiozero import LED
import time
#this will import the relevant modules we need for this code

relay = LED(14)
relay2 = LED(15)
#assigning the relays an LED

while True:
	#you guessed it… turning the relay on
	#you guessed it… turning the relay off
	#sleeping for 1 second
	#relay on
	#relay off

Step 11: Importing Flask

The easiest way for the google assistant to control the raspberry pi is by getting it to host a web server. We can then get Google to visit a page on that server whenever you say something and code the raspberry pi to turn the relay on and off when the server is visited. If you want a more in-depth tutorial of flask then: visit this tutorial by raspberry pi.

On your raspberry pi import the flask module on python.

  1. Make sure you are connected to the internet
  2. Open up a terminal
  3. Type in:
sudo pip3 install flask

If this does not work:

Step 12: Create a Folder for Our Program and Go Into It

Do this by opening a terminal and typing in:

mkdir webapp

cd webapp

Step 13: Coding Web Server

  1. Open idle 3
  2. File > Create new
  3. Save it in the web app folder you just created
  4. Insert this code
from flask import Flask
from gpiozero import LED
import time
#these are importing modules required for this project

relay = LED(14)
relay2 = LED(15)
#assigning the relays an LED

app = Flask(__name__)
#assigning Flask a variable name so that it is easier to run code with it in later on

#doing a GET on the web page

"""this function will return what is displayed on the main page"""
def index():
    return 'Main page'

#turning on the relays through the function below

"""turning on the relays and printing hi to check the function is working properly"""
def on():
    return 'on'

#shutting off the relays through the function below
"""turning off the relays and printing hi to check the function is working properly"""
def off():
    return 'off'

#running the function go

"""this function turns on the relays so it sprays water"""
def go():
    return ('go')

"""accessing the web page through the relevant port (8000 is usually home) and host"""
if __name__ == '__main__':, port = 8000 , host='')

The comments explain what is going on in the code

Step 14: Testing Code Works

Open your web browser and enter the URL

You should see a white screen but you should be able to hear the click of the relay going on or if the pump is plugged in, it should go on.

To turn the pump off go to

Note: means ‘home’, i.e. this computer :5000 means ‘port 5000’, which is the port the web server is running on.

If this works then you can take it a step further by:

1. Finding out your raspberry pis ip address by typing in:

hostname -I

2. On any computer connected to the same wifi as your pi visiting the pisipadress/on

This should turn the relay on.

This shows how you can control your raspberry pi from any computer connected to the same wifi as your raspberry pi.

Step 15: Tunneling

So the Google Home can visit this website you will need to create a tunnel so computers that are not connected to the same ip address as you can still turn the relay off and on. You can do this with ngrok. This is a program that you can install on the raspberry pi that will allow you to visit the flask website from any computer.

Visit their website for more info:

Step 16: Installing Ngrok

Enter this link on your raspberry pi: and follow the instructions to download and setup ngrok.

Step 17: Testing Ngrok

Make sure your flask server is running.

Open another terminal and type in cd webapp

Then start ngrok by typing in

./ngrok http 5000

This should show you a URL which you should be able to go to on any device. Copy this and email it to yourself for the next step

If this does not work:

  1. Make sure flask is running
  2. Make sure you are running ngrok in the same folder as the flask program
  3. Make sure you copied the right link(it changes every time you restart the program)

Step 18: IFFF

IFFF: If This Then That is a free program that can be used to make your google home visit a web server when say something to it,

To set this up follow these steps:

  1. Either visit or download the app
  2. Create an account
  3. Click create new applet(sometimes under my applets)
  4. Click this
  5. Search google and select google assistant
  6. Click say a simple phrase
  7. Under what you want to say put "activate water pistol" or anything you want
  8. Click create trigger
  9. Click that
  10. Search web
  11. Click webnooks
  12. Click Make a web request
  13. Under URL enter the URL ngrok gave you earlier/go
  14. Under Method select GET
  15. Under Content select text/plain
  16. Click Create
  17. Click finish

Step 19: Done!

Now when you say hey google (insert the phrase you chose), the pump should turn on.

If this is not working(it took me about 15 tries to get it working):

  1. Make sure all programs are running
  2. Make sure all Leads are connected
  3. Make sure the URL you entered into IFTT is the latest one
  4. Make sure raspberry pi is connected to the internet

Step 20: IOT Competition

If you liked this tutorial then please vote for us in the IOT competition. Thank you so much.

IoT Challenge

Participated in the
IoT Challenge

Be the First to Share


    • Puzzles Speed Challenge

      Puzzles Speed Challenge
    • "Can't Touch This" Family Contest

      "Can't Touch This" Family Contest
    • CNC Contest 2020

      CNC Contest 2020