Sprinkler Project

Final received my first Raspberry Pi. I have had an idea for years about what I wanted to do with one. Automated sprinkler system. 2 summers in a row my lawn has burnt to a frazzle. I have dealt with automated sprinklers before so why not build my own system!

What is needed:

  1. RaspberryPi
  2. Relay Board
  3. Water Valve
  4. 24 V AC transformer
  5. 1 LED (Yellow)
  6. 1 Locking switch

In this project, I started off with a Cana-Kit Raspberry Pi Ultimate Starter Kit. My dad had a 4 channel relay board he purchased for an Arduino project he was going to build but never started. So I borrowed that from him. You can find one here.

I also purchased an Orbit water valve for an in-ground sprinkler system. I used this one right here. I also found some adapters to connect this valve to a regular garden hose as I will not be burring the water line.

For power, these water valves normally run on 24V AC. To get this project going, I purchased a simple doorbell transform although I would recommend getting the correct 24V AC sprinkler transformer. (I will explain why later)

Building

Because this was my first Raspberry Pi project, I started by wiring the breakout board to 4 LEDs instead of going directly to the relays. This posed a problem later on so I would suggest wiring directly to your relay board.

The relay board uses a positive voltage coming from the GPIO pins to keep the relay open. When the voltage is removed the relay will then close. This is backwards to what is required for the LEDs but because I was an n00b with this, I scratched my head for a while.

I added an LED for a status indicator. This flashes differently based on different triggers. For example: if the cancel button is pressed then flash the LED or if the rain sensor is tripped leave the LED on until the sensor is no longer wet. This also halts the main loop until these trips are cleared.

Here is how the GPIO is wired to the Raspberry Pi:

Description GPIO IN/OUT
Zone 1 (Relay) 17 Out
Zone 2 (Relay) 27 Out
Zone 3 (Relay) 22 Out
Zone 4 (Relay) 23 Out
Water Sensor 18 In
Cancel Button 4 In
Status LED 12 Out

I had a 2″ x 4″ lying around so I used that to screw all the components to for now. I added a 120V wall switch and outlet. The 24V transformer and the outlet are both wired to the switch. The Raspberry Pi is plugged into the outlet. I have a 3 conductor power cord so I used that to feed power to the switch. Be careful with 120V wiring. You can cause yourself and your project serious damage. Consult a professional if you are unsure.

The output of the transformer is wired to one side of the relay. I added a heavy gauge wire between the relays. I highly suggest you test the posts on the relays before connecting the 24V AC. The other side of the transformer can be connected to the Orbit valve. The second wire from the valve can be connected to the first zone. Please see the photo below.

The great part about this relay bank is the LED indicators. We can create the program without having all the water valves. I would also suggest leaving the 24v transformer off while developing the code.

Code

I decided to write the code in Python. I had some experience writing Python code before but it was a few years back. The basics of this program are straightforward. We want to water each zone individually for a set amount of time. In my area, I have low water pressure so I only want to water one zone at a time. There is also a bylaw only allowing homeowners to water on an odd or even day of the week.

I also wanted the ability to log when each zone is triggered, when the water sensor has tripped and when the cancel but has been pressed. For this, I decided to use a MySQL database. The reason I chose this is that I already have MySQL running on my server in the basement. It handles my home Kodi environment. Setting up the database was simple. Create a new database and then create the one table we need right now. We could always add more later. See the SQL commands below to create the table.

CREATE TABLE tblLogs (
logID int NOT NULL auto_increment,
zone varchar(25),
logTime datetime DEFAULT NOW(),
description varchar(200) NOT null,
PRIMARY KEY (logID)
);

I am currently not doing anything with the logged data but maybe someday we will have reports.

Here is the main Python code. The script runs when the Raspberry Pi boots. You can accomplish this with Cron.

GitHub Page

You will need to make changes to your setup. The database function may not be required for you. You can find that in the dbLog function. I would suggest if this is your first project build your code from scratch. It’s the only way to learn.

Conclusion

I haven’t added “water” to this project yet. I am hoping to find some cheap hose I can cut up and make a few short runs. Next year I may add another 3 watering zones.

One problem I did notice, using the doorbell transformer, is the amount of heat it generates. I do suggest getting the proper transformer for these Orbit valves. If you’re running multiple valves at the same time I would look at the Orbit transformer.

I will continue to create more Blog posts when I update this project. I am already starting to think about Christmas lights!

If you have any questions, please leave them below.

Apache2 Server Signature

The following tutorial will provide you with the steps required to disable server information on folder list pages and any of the error pages. The following screenshot shows what I am talking about.

Server Info

I will be showing how I did this on Ubuntu Server 14.04.4 LTS.

This information can provide a hacker with the versions of software installed on your server. Depending on your configuration, PHP information is shared as well. Lets go ahead and get this secured.

First we want to open the apache2.conf in our favorite text editor.

sudo nano /etc/apache2/apache2.conf

Next, we will add a few lines to the end of the config.

ServerSignature Off
ServerTokens Prod

We will now want to restart Apache.

sudo service apache2 restart

On a folder page or error code page you will see the version information is now gone. Unfortunately PHP still sends version information in the page header. To turn that off we need to edit one more config.

sudo nano /etc/php5/apache2/php.ini

Change the expose_php from “On” to “Off”. You will need to find the line in the php.ini file.

expose_php = Off

We can now save the file and restart Apache.

sudo service apache2 restart

We are done! Version numbers will no longer be view-able.
If you have any questions, please use the comments bellow!

Ubuntu Server static IP

Easy enough? By default, Ubuntu Server is configured with DHCP enabled but we need a static IP. The following tutorial will show you just how to do that!

Let’s open the interfaces configuration file.

sudo nano /etc/network/interfaces

It should look like the following.

auto eth0
iface eth0 inet dhcp

DHCP is currently set but we need a static IP. The following configuration will show what needs to be changed and add.

auto eth0
face eth0 inet static
        address 192.168.1.4
        netmask 255.255.255.0
        network 192.168.1.0
        broadcast 192.168.1.255
        gateway 192.168.1.1
        dns-nameserver 192.168.1.2 192.168.1.1

In previous version of Ubuntu you needed to edit the /etc/resolv.conf and add a line. This is no longer the case.

I hope this tutorial helped!

Audio Click Xubuntu 14.04.1 LTS

I had finally had enough of a very annoying clicking noise through the headphones on my HP Pavilion dm1 Netbook. I love this machine because of its compact size and long lasting battery. The system originally had Windows 7 witch was a struggle with just an Atom processor. I fell in love with Xubuntu on this machine immediately with one slight annoyance. Every 10 seconds there was a click in the audio. This only happened when there was no audio playing. It also went away when the audio mixer was open but why waste the ram keeping it open?

Solution was simple enough. Power save kept switching the Intel sound card on and off every 10 seconds causing the click. Solution? Turn it on and leave it on! Here are the steps.

First, open a terminal window.

sudo nano /usr/lib/pm-utils/power.d/intel-audio-powersave

Comment out the following line with a #.

# INTEL_AUDIO_POWERSAVE=${INTEL_AUDIO_POWERSAVE:-true}

And then add the following line below the pervious line.

INTEL_AUDIO_POWERSAVE=false

Save the file and reboot the computer. That is it, no more click!

TeamSpeak start up Ubuntu 14.04.1 LTS

This problem stumpt me for a while. I run a TeamSpeak damon on my VPS linux box. The issue with this application, is they do not create startup script in the /etc/init.d folder.

There are many TeamSpeak startup scripts but the following seems to work best for me.

#!/bin/sh
 
case "$1" in
start)
/etc/teamspeak3/ts3server_startscript.sh start
;;
stop)
/etc/teamspeak3/ts3server_startscript.sh stop
;;
status)
/etc/teamspeak3/ts3server_startscript.sh status
;;
*)
  echo "Usage: `basename $0` {start|stop|status}" >&2
  exit 1
  ;;
esac
exit 0

Now that the bash script has been created in the /ete/init.d directory we can now use “service teamspeak3 start” to start the damon but every time the server restarts we have to run this manually. We need to add Teamspeak to the system start up. The following command will add this.

update-rc.d teamspeak3 defaults

That is it. Next time your server reboots Teamspeak will start.