User login

You are here

Pool Control Phase I: Electrical Control

Phase I: Electrical control

This is really the meat and potatoes part of the mission. The original reason I was able to justify this project was due to a broken timer, thus the very first thing to get to work is electronic timing of pool controls. In order to do that you need at a minimum, a properly programmed arduino, a properly developed protoshield, and the contactors properly wired to your pool equipment. The reader here is expected to improvise some things and understand everything enough to purchase what is necessary for their particular implementation. I'm going to describe my implementation and steps of completion.

The very first thing you should do is buy a Linksys NSLU2. I got mine from an eBay seller. This device is more or less a PDA with no screen, arm processor which runs linux. It has 2 USB 2.0 high speed ports as well as an ethernet port. That is IT. This device is very special. There are not a lot of other cheap full scale Linux computers available. Even the gumstix devices cost a lot more and offer less function. We don't need something small, we just need something cheap and reliable with no moving parts. The maximum operational temp of the NSLU2 is rated at 104F but I've had it to 130F on hot days without any issues.

When you get the device, the first thing you should do is configure it to a static IP using the included software. Choose an IP range not on your home network. For instance if your home network is 192.168.1.* use 192.168.0.2 for the NSLU2. Use a crossover cable between your computer and the NSLU2 to do all further communication. Once you have that you should flash it to Openslug. There is a variety of available firmwares for it but I've found openslug to match the needs of a pool controller the best. NOTE: Linked above is openslugbe. The ARM processor in the slug is capable of running in either big endian mode or little endian. Big endian mode is the "native" endianness of the arm processor and what people tend to run. Little endian is the endianness of the x86 processor most PC's use. Well written software will build and run on each. The WUSB54G driver apparently is not well written. Make sure to install openslugle if you want to use it and expect it to build. In practice I've found no problems or deficiencies in running in little endian mode.

NOTE: Make SURE to not fill your 8MB flash filesystem of the NSLU2. It will crash and stop responding. Your only out is to reflash. Not fun. You cannot install much of ANYTHING without a USB flash key.

NOTE: I talked to a lot of very well educated people who highly recommended against stringing an ethernet cable between your home and pool equipment area, even underground. The voltage potential between inside and outside is far too high and even remotely close lightning strikes will cause surges that will destroy connected equipment.

- Format and partition your flash key
- Mount your flash key (I have mine mounted to /media/sda1) and make sure it automounts in your fstab. Reboot to check
- Add the new root to your /etc/ipkg.conf file (add "dest sda1 /media/sda1" to the bottom
- Now you can run ipkg update to download the most recent package lists.
- You must be very careful what you install. Packages are temporarily downloaded to /var/volatile which is on your flash filesystem before installation. If the package you are downloading has a large dependency list, you may want to relocate /var/volatile to your flash key as well.
- The WUSB54G uses the rt2570 chipset. Unluckily a package is not already built for the rt2570 driver. Luckily the openembedded environment has a build recipe for the rt2570 driver. Download the openslug SDK which is a snapshot of openembedded. Building the wireless driver is as simple as following the docs and typing "bitbake rt2570-k2wrlz". Note the k2wrlz version is the only one that seems to work with WPA. You should use WPA for wireless security rather than WEP.
- The RT2570 ipk that I built is available here.
- Install wireless-tools package
- Install the kernel-module-ftdi-sio package (arduino communication)
- Your NSLU2 should at this point be connected directly to another machine via crossover cable. The reason is so that now you can enable the wireless on your real network without interference. This is how I configured my wireless. I put these commands under the "start" section of /etc/init.d/networking

/sbin/modprobe rt2570
/sbin/modprobe ftdi_sio
/sbin/ifconfig rausb0 192.168.100.13 netmask 255.255.255.0 broadcast 192.168.100.255 up
/sbin/iwconfig rausb0 essid mywirelessnetwork
/sbin/iwpriv rausb0 auth 3
/sbin/iwpriv rausb0 enc 3
/sbin/iwpriv rausb0 wpapsk "mysharedkey"
/sbin/route add default gw 192.168.100.1

If you reboot the NSLU2 it should now be accessible at that address on your regular network. Unplug the crossover cable and access it wirelessly from now on.

Ok, so now that you have your NSLU2 all configured, you need to get your arduino setup. Use your PC and the arduino software to download sample programs to your decimilla to make sure that it is working. Once you've done that you'll want to build your protoshield. If like mine, it came unassembled. Find the instructions on the website to assemble it and follow them.

The general idea here is a sort of ladder system. When you're controlling something as powerful as a 240volt pool pump from something as tiny as an arduino digital output, you need to do it in stages. The first stage is the arduino digital output. This goes to a leg of the TIP102 transistor. This allows a much higher current 5 volt supply to flow to the relay coil. The relay energizes. The relay can handle a much higher voltage and current through it's mechanical contacts. The 24 volts AC flows through the closed relay and is enough power to energize the large contactor contacts. This connects the 240 volt power for the pump.

The TIP102 transistors and relays are on the arduino protoshield. The contactors and 24 volt supply will sit in your mains electrical box. Start by assembling your protoshield kit according to the instructions online on the arduino website. Once you have it assembled You want to solder in the relays and transistors. I soldered the relays across the center voltage rails and the TIP102 transistors off to the edge. Follow this guide for how to wire everything up.

When you get all your hardware right, you can check out my arduino code.

Here are the packages needed to build the adaemon package I am including.

adaemon package list
binutils
cron
gcc
gdb
glibc-extra-nss
kernel-module-ftdi-sio
kernel-module-usbserial
libc6-dev
libexpat1
libgcc-s-dev
libmysqlclient-dev
libmysqlclient14
libssl0.9.7
libstdc++-dev
libstdc++6
libthread-db1
libz-dev
linux-libc-headers-dev
minicom
mysql-client
ncurses-dev
ncurses
ntpdate
screen
ssmtp
tzdata-americas
update-rc.d-dev

Here is the current daemon code that runs on the NSLU2. This is HIGHLY UNFINISHED and will need to be customized for your needs. It also contains utilities to talk to your programmed arduino from the slug.

Since this is a work in progress I won't document adaemon much but you should be able to use ./compile_me to build it.

Basically the idea is to program the arduino with the right digital outputs. Then run the adaemon program which will connect to your database server and read whether or not outputs should be on or off.

Once you wire everything up, modify my arduino program to the proper outputs and use test commands (A1 and A0 over the arduino serial monitor in order to verify your relays are wired up right). When you issue an A1, B1 or C1 you should hear a relay click on. A0, B0, or C0 you should hear that respective relay click off. You're off to a great start if you get here.

Once you are sure everything is right you need to run some bellwire between your terminal block to the center pin of the relays (see datasheet on mouser.com). This is your 24VAC source line which will go through both terminal blocks all the way to 1 leg of the 24vac transformer. Then run 3 more wires from each relay's normally open point back to the terminal blocks. These will run all the way to one coil side of the contactors. These are your 24VAC switched lines that go back through conduit to your contactors.

Note in the following pic, the pressure sensors were later removed from the board. Do not put your pressure sensors inside the controller case! A leak will cause water to penetrate your case!

Here is some images of my contactor wiring in a test fashion.


Controller Box
There isn't a whole lot of modifications to do to the controller box. All of the components are held with stick on velcro and a large (1/2 or 3/4" spade bit was used to cut the holes for the conduits.

From there you want to layout your components in a logical accessible fashion. This is the layout I chose.


Contactor Wiring
When wiring and testing the contactors you will be using household current to supply power to the 24 volt transformer to test. Household current is dangerous. If crossed with the 24 volt side you will fry the contactors. If touched to yourself you could be hurt or killed. You will have 3 contactors with spade terminals on each side. You will have a 24 volt transformer with 2 24VAC outputs. You will have a terminal block for the mains box side and a terminal block for the controller box side. The first thing you must understand is that you are attempting to complete a 24 volt circuit through the coil in the contactor to energize it. If you can understand this, wiring everything up is super easy. First thing you'd do is hook up one leg of your 24volt transformer to one spade terminal of each contactor. The other side will go to the terminal block, through the conduit and will connect to the center pin of each relay. From the output of each relay you would fly 3 wires back through the conduit and connect the other end (through the terminal blocks) to the respective spade terminals on the other side of the contactors.

Once you get everything configured in a test fashion and all of your contactors are working then you can start to think about relocating the whole setup outdoors and connecting the contactors to your mains wiring.

Electrical box wiring
I am not a licensed electrician and thus you should take what I say here with a grain of salt. 240 volt ac current is DANGEROUS and you could EASILY BE KILLED if you don't know what you're doing. I WILL NOT BE HELD LIABLE! You've been warned!

The basic idea is that your 2 pole contactors have 4 large screws. One side is the input side and one is the output side. Which those are is your choice. At this point I should remind you that this whole setup should have been successfully tested INDOORS away from 240 volt current and you should be highly comfortable with what you are doing before proceeding.

1. Turn off the breaker on your main panel that leads to your pool panel. Turn a light on or pump on to make sure you have the right one.
2. Use a volt meter to confirm no voltage. In theory the white neutral lines shouldn't hurt you even though they remain connected when the breaker is tripped off.
3. Disconnect and remove your timer. Your timer will have 2 hot lines coming in from a bonded paired breaker (240 volts AC is really just 2 branches of 120 volts AC). It will have 2 hot lines going out through a conduit to your pool pump. It will have one neutral line (most likely). The neutral line is just to power your timer. It could also be a 240volt timer motor in which case there will be no neutral. Either way you want to dispose of the neutral (think wire clippers near the neutral block) or remove the wire by unscrewing from the neutral block.
4. Attach the 2 hot lines from the bonded 240v breaker to one side of your pump contactor.
5. Attach the 2 hot lines going to the pump to the other side of the contactor. It looks something like this:

This image really shows it all. You have another contactor but you're only using 1 pole to power the pool light. I simply took the lines from the switch on your left there and hooked them up to the contactor. Done. I bought an extension cord plug kit and wired the lines to the back of the ac receptacle. That way the door to the box can close while the arduino 5volt power supply is plugged in. The 24 volt transformer is also wired up to this 120 volt supply but my particular 24 volt transformer can take 120 volts, 240 volts or a number of input voltages.

You can also see all of the low voltage lines going from the spade terminals on the contactors to the terminal block, then from the other side of the terminal block through conduit to the controller.

While my particular setup is fairly messy compared to some rather beautiful electrical installations I've seen, I do believe it to be safe from fire and shorts. It, however, is NOT safe from prying fingers. It might be wise to devise a way to cover up the exposed 240 volt sections like it comes standard and like a main breaker box comes standard.

At this point you can switch your pool pump/light on and off by sending commands wirelessly to an NSLU2. Phase I is done. Congrats!

You can use cron and the pump_on/pump_off scripts in the adaemon archive to control pump on and off times until you are ready to use the real adaemon.

Article Type: