This is a cool example that teaches you how to use a Raspberry Pi, a PiFace and Ubidots to water your garden from far away. You'll be able to control an electro-valve remotely to water your plants from any place, just using your phone.

Step 1: What Do You Need?

Well you'll need some materials:

1. Raspberry Pi Model B

2. A PiFace Digital

3. A Water Valve - 12V

4. A Flexible Wire (1Amp)

5. A DC Jack

6. Power adapter (12V-DC 1000mA)

7. 3/4" PVC threaded coupling

8. Teflon tape

9. Hose

10. Sprinkler

Step 2: Wiring Things Up

1. Connect the PiFace to the RaspberryPi without plugging in the power adapter.

2. Follow the picture above; White wire is ground (GND) and it's connected to the common terminal of the relay Switch of the PiFace, while the red wire is connected to the NO pin (Normally Open).

Note: As for the hydraulic connections, make sure to use teflon tape on every union to prevent the water from leaking.

Step 3: Create a New Data Source in Ubidots

If you're new to Ubidots, go to www.ubidots.com and create an account. Navigate to the "Sources" tab and click on "Add new Data Source".

Step 4: Select Raspberry Pi As Your New Data Source

Select the Raspberry Pi Icon and continue

Step 5: Create Two New Variables

Click on your data source and create two new variables: "valve" and "relay_state".

Step 6:

Step 7: Take Note of Your Variables' IDs

We'll need the id's of the variables for our Raspberry Pi program . We'll also need you account's API Key.

Step 8: Add Widgets to Your Dashboard

Click on the "Dashboard" tab and click on "Add New widget"

Step 9: Select the Switch Widget

Select a Switch Widget and bind it to the variable "valve". This widget will write "1" or "0" to the "valve" variable, which we'll poll later from our Raspberry Pi.

Step 10: Create an Indicator Widget

Now add another widget, select the "indicator" widget type and choose the variable "valve_state"

Step 11: Done!

Now we have a cool dashboard, let's continue with the code.

Step 12: Coding Your Raspberry Pi

We'll assume you have a working Raspberry Pi that in connected to the Internet. If not, check this blog post about setting up WiFi in Raspberry Pi. Then login through a terminal into your Raspberry Pi and set up the SPI module to communicate with the PiFace Digital:

sudo nano /etc/modprobe.d/raspi-blacklist.conf

Add a "#" character before the line spi-bcm2708, then press CTRL-X, type Y and Enter. This enables SPI from boot. Now let's install and setup the PiFace Digital library:

sudo apt-get updatesudo apt-get install python3-pifacedigitalio python-pifacedigitalio

Restart your Pi:

sudo reboot

Great! we are ready to start coding our project. Create a new file called "valve.py" (by typing "nano valve.py") and paste the following code into it:

import pifacedigitalio 					#Library for pifacedigitalio	 from ubidots import ApiClient				#Library for Ubidots
pifacedigital = pifacedigitalio.PiFaceDigital() 	#Declare piface object
	api = ApiClient("1fc7a56bf4b539725ace7a3f4aa623e9e9620612") #Don't forget to put your own Apikey
	valve = api.get_variable('53cd4cb07625425b70f5c21e') 		  #Put here your valve ID's 
	valveState = api.get_variable("53ce95547625420403d81468")	  #Put here your realy state ID's
	print("cant connect") 	#Check your Apikey, variable's ID and internet connectionwhile(True):
	lastValue = valve.get_values(1) 				#Get the last value of valve from Ubidots 
	rele = pifacedigital.relays[0].value 				#Save relay state
	valveState.save_value({'value':rele})			#Send relay state to Ubidots
	for a in lastValue: 										
		print a['value']
		if(a['value']):							#Turn on or off the relay 

Step 13: Wrapping Up

Done! Now you have a remotely activated system to water your plants from any place just using your phone or any web browser!

<p>Can i use this to call a python script on the raspberry pi?</p>
<p>Interesting. Thanks for sharing this.</p>

About This Instructable



Bio: Community manager @Ubidots, a startup empowering makers and hardware engineers to create applications for the Internet of Things #IoT
More by UbiMaker:SONOFF Dual Tutorial: Control Your Electrical Appliances Remotely Using MQTT and Ubidots How to build a parking sensor to solve the pain of finding a free spot Building a Cross-Platform System Monitor with Ubidots 
Add instructable to: