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:
- Raspberry Pi B+ ( Any Rpi should work)
- 3-6V Submersible Mini water pump
- Wifi Adapter (You can skip this if you have a LAN cable long enough to reach your garden)
- Transistor Bs550
- 5V Relay
- 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 192.168.0.26 #your static IP network 192.168.0.0 broadcast 192.168.0.255 gateway 192.168.0.1 #your gateway IP netmask 255.255.255.0 allow-hotplug wlan0 auto wlan0 iface wlan0 inet static address 192.168.0.25 #your static IP network 192.168.0.0 broadcast 192.168.0.255 gateway 192.168.0.1 #your gateway IP netmask 255.255.255.0 wpa-ssid "SSID of Your Wifi Network" wpa-psk "password of your Wifi Network"
Here I have configured the static IP of 192.168.0.26 for LAN connection on Rpi and 192.168.0.25 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 http://www.google.com
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
192.168.0.0 0.0.0.0 255.255.255.0 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 192.168.0.1
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: http://webiopi.trouch.com/INSTALL.html
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
...
[HTTP]
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" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Garden Manager</title> /webiopi.js webiopi().ready(function() { webiopi().setFunction(3,"OUT"); webiopi().setFunction(2,"IN"); // Create a "Pump" labeled button for GPIO 3 var button = webiopi().createGPIOButton(3,"Pump"); // Append button to HTML element with ID="controls" using jQuery $("#controls").append(button); // Refresh GPIO buttons // pass true to refresh repeatedly of false to refresh once webiopi().refreshGPIO(true); }); <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; } </style> </head> <body> 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 http://192.168.0.25:8000
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.