The Garden Pi

This is a small project that will introduce you to IoT and on how to use WebIOPi and Raspberry Pi to create a small and cool project.

These are the components that you will require for this project:

  1. Raspberry Pi B+ ( Any Rpi should work)
  2. 3-6V Submersible Mini water pump
  3. Wifi Adapter  (You can skip this if you have a LAN cable long enough to reach your garden)
  4. Transistor Bs550
  5. 5V Relay
  6. Tube to supply water from the pump to the flower pots.

Setting Up the Wifi Adapter

As mentioned earlier if the LAN cable is long enough to reach your garden then you can skip this stage.

Make sure the Wifi adapter you have is compatible with the Raspberry Pi you have. I have used an Edimax Wifi usb adapter.

Insert the adapter into the Rpi USB slot and power up your Rpi.

At the command prompt type in the command lsusb


From the output of this command we get to know if the Wifi adapter was detected or not. In my case the last line shows my Wifi adapter.

The next task will be to edit the /etc/network/interfaces file. Type the command

sudo nano /etc/network/interfaces . This should open up the file and the contents should be edited as shown below:

# The loopback interface
 auto lo
 iface lo inet loopback
auto eth0
 iface eth0 inet static
 address   #your static IP
 gateway     #your gateway IP

allow-hotplug wlan0
auto wlan0
iface wlan0 inet static
 address   #your static IP
 gateway   #your gateway IP
 wpa-ssid "SSID of Your Wifi Network"
 wpa-psk "password of your Wifi Network"

Here I have configured the static IP of for LAN connection on Rpi and for Wifi on RPi.

Type ifconfig at the comamnd prompt and make sure the IP address of the Wifi (or LAN) is assigned correctly. If not reboot your Rpi.

Once this is done try pinging your Rpi from within the same network. Use the IP address of LAN or the Wifi adapter based on how your Rpi is connected to the network.

Now on your Rpi try pinging some external website like

If the ping is successful all is fine. If not don’t worry there is a fix to it.

Type in route -n

Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface   U         0 0          0 wlan0

If this is the output then notice that the gateway has not been set properly. All you have to do is execute the command given below.

sudo route add default gw

Now the you should be able to ping external websites. It would be a good idea to add this line to the ~/.bashrc file so that every time your Rpi starts up this get done automatically.

Once the wifi is setup you are ready to move on to the next section.

Installing WebIOPi

Since the WebIOPi has a pretty neat tutorial on how to setup WebIOPi, I will redirect you to that:

If you have both eth0(LAN)  and Wifi(wlan0) configured you may run into and issue where weaved is not able to access your WebIOPi server.

In that case type in sudo ifconfig eth0 down and that should do the trick. If it does consider adding this also to the ~/.bashrc file.

Setting Up the Garden Pi Web Page

For this project all you have to do is to write a single index.html file.

so create a project directory structure as shown below:

mkdir ~/gardenpi/html


edit the /etc/webiopi/config file

  • Locate [HTTP] section, add following line to tell WebIOPi where to find your HTML resources
doc-root = /home/pi/gardenpi/html

More details about the config file can be found here

Now create the file ~/gardenpi/html/index.html

Add the following content into it:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">
 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 <title>Garden Manager</title>
 webiopi().ready(function() {
 // Create a "Pump" labeled button for GPIO 3
 var button = webiopi().createGPIOButton(3,"Pump");
 // Append button to HTML element with ID="controls" using jQuery

 // Refresh GPIO buttons
 // pass true to refresh repeatedly of false to refresh once
 <style type="text/css">
 button {
 display: block;
 margin: 5px 5px 5px 5px;
 width: 160px;
 height: 45px;
 font-size: 24pt;
 font-weight: bold;
 color: white;

 #gpio3.LOW {
 background-color: Black;

 #gpio3.HIGH {
 background-color: Blue;

Turn on the pump by clicking the button below
</body> </html>

Once the file is created connect and LED between the GPIO3 and Ground of the RPi.

Open up a browser in your PC or mobile and go to

and ensure that the LED turns on and off at the click of the button. All you have to do now is to connect the pump instead of the LED.

Since the pump draws more current than compared to what the Rpi can supply we will be using a relay.

Wire up your components as shown in the diagram below:


This is my Rig, you may not be able to make much from the picture:


Hope you guys ill enjoy doing this project.



About vineethkartha

Hi, I am Vineeth Kartha, I hold a Masters degree in Embedded Systems from BITS Pilani, Goa Campus. I currently work as a Software Developer. I am A free software promoter and electronics hobbyist. In my free time I do a little bit of birding and Wildlife photography. I love travelling, reading and blogging.

Posted on December 31, 2016, in Technical. Bookmark the permalink. Leave a comment.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: