loading
We bought a home with a pool. The first couple of weeks we made several costly mistakes including using the heater to heat the entire pool over 90 degrees. I think we paid $250 for gas that month. We also accidentally drained the spa into the pool.

The solar water heater did have an automation system, and 1 actuator which would turn the solar heat on (start pumping water up to the roof) if the air temperature was 8 degrees warmer than the pool water. The pump was an old 1 hp single speed pump and it needed to be replaced. What I needed to solve for is:

The adults like to use the spa in the evening, while the kids play in the pool during the day. Switching from pool to spa requires rotating 2 values, setting the heater temperature and starting the heaterThe pump needs to run at a higher speed if the pool cleaner is runningThe pump needs to run at a higher speed if the solar heater is onThe pump needs to run at a lower speed when only in a filter/skimmer cycle

Step 1: Pump and Actuators

Installing the new pump should have been simple. Disconnect the old pump, put in the new, but no, new pump needed more clearance for the pump controller, had to reroute the plumbing from the pump to the filter.

I needed to add 3 new actuators:

  • Suction valve
  • Output valve
  • Cleaner/Skimmer valve

Installing the actuators

  1. Choose ideal alignment of the actuator
  2. Align the valve handle in the counter-clockwise position
  3. Remove the valve handle
  4. Remove the 4 screws that are required for the actuator to attach to the valve
  5. Install the 4 longer screws through the holes in the actuator
  6. Remove the cover from the actuator: 4 screws
  7. Move the lower cam to point at the left toggle switch, where it would close the circuit when the actuator rotates to that position
  8. Replace the handle by aligning the small slot on the handle with the small slot on the shaft
  9. Push the shaft in to disengage the gear train, rotate the shaft to the clockwise position
  10. Move the upper cam to point at the right toggle switch, where it would close the circuit when the actuator rotates to that position
  11. Remove the handle
  12. Replace the cover: 4 screws
  13. Replace the handle and the locking screw

Step 2: Pool Controller

  1. Solder the 'Arduino Stackable Header Kit - R3' and 3 rows, 16 each row of 'Break Away Headers - Straight' to the 'Mux Shield II' (Mux Shield). Put in the solder jumpers to make row 1 digital output, row 2 digital input, row 3 analog input
  2. Connect Mux Shield to the 'Arduino Uno - R3' (Arduino)
  3. Assemble the 'Raspberry Pi Complete Starter Kit -- [Model B - 512 MB]' (RPi) and make sure it boots. The wifi adapter doesn't have enough range to connect from outside, run '100' Blue Cat5e Patch Cable' (Network cable) to your router
  4. Get the RPi on the network and set a static IP address on your router
  5. sudo apt-get update

  6. Use 'Foam PCB Tape - 3M VHB Acrylic' (Foam tape) to attach the Arduino to the top of the RPi
  7. Connect a short USB cable from RPi to Arduino
  8. Use Foam Tape to attach the RPi to the off center left and top of the '125 Amp 4-Space 8-Circuit BR Type Mail Lug Loadcenter NEMA 3R' (Electrical box)
  9. Drill 3/8" holes in the corners of the 'Kootek 8 Channel DC 5V Relay Module for Arduino Raspberry Pi DSP AVR PIC ARM' (Relay board)
  10. Use Foam tape to hold relay board in place, fasten the relay board to the electrical box with a rivet

Step 3: Transformer and Terminal Blocks

  1. Drill 3/8" holes through the holes in the conduit strap and the electrical box spaced evenly at the top of the electrical box
  2. Use foam tape to hold 'Philmore 24VAC CT 1A Power Transformer' (Transformer) in place, off center right and top, on the electrical box
  3. Drill 3/8" holes through the holes in the transformer and the electrical box and fasten with rivets
  4. Use foam tape to hold 'CINCH TERMINAL BLOCKS. CINCH TERMINAL BLOCKS. #6-32 SCREW SIZE. 4-POSITION. 4-140-P' (4 pos terminal block) in place, couple inches from the bottom centered, on the electrical box
  5. Drill 1/2" holes through the holes in the 4 pos terminal block and the electrical box and bolt in place
  6. Use foam tape to hold the '2 Pcs 12 Position Covered Barrier Screw Terminal Block 600V 15A' (12 pos terminal block) (4 total) along the side rails
  7. Drill 1/2" holes through the 12 pos terminal blocks and bolt in place

Step 4: Thermistors

Can't find a product image of the 10k ohm resistor 5 pack, but I found it at Fry's. I wired for 4 thermistors, but, I'm only using 3. Find a better prototyping board.

Follow these steps for 4 resistors, 4x2 breakaway headers

  1. On a small prototyping board solder 10k ohm resistor to a grounded row (5 connected) and a row with 3 (minimum) through holes
  2. Solder 2 breakaway headers to connect with the 10k ohm resistor

Then

  1. Solder 1 breakaway header to the grounded row to connect to gnd
  2. Solder 5 breakaway headers to a single row all connected for 5v VCC

Set up the thermistor terminal block

  1. Get 4 black female jumper wires
  2. Get 4 red female jumper wires
  3. Cut off 1 end of each of the 8 jumper wires, strip 1/4" from the end and attach '22 - 16 AWG, #4 - 6 Stud Size Red Vinyl-Insulated Spade Terminals (75-Pack)' (red spade)
  4. Connect jumper wires to bottom of top left terminal block alternated red and black on positions 1,2,3,4,5,6,7 and 8
  5. Connect female end of red jumper wire to 4 of the 5v VCC breakaway headers on the prototyping board
  6. Connect female end of black jumper wire to one of the breakaway headers at each end of the 10k ohm resistor
  7. Get 4 yellow female jumper wires
  8. Connect yellow jumper wire to Mux Shield, analog in (row 3) position 0,1,2,3
  9. Get 1 red female/male jumper wire
  10. Connect red jumper wire from the last 5v VCC breakaway header to 5v on the Mux Shield
  11. Get 1 black female/male jumper wire
  12. Connect black jumper wire from the gnd breakaway header to the gnd on the MuxShield
  13. Hang extra wiring on conduit straps at the top of the electrical box

Step 5: Heater, Lights Internals

I have a dream of adding landscaping lighting to this system, so there are a couple of extra steps here, maybe you already have them.

Heater

I destroyed relay board position 1 when I drilled for the rivet in the corner, so these instructions start on position 2. If you start on position 1, you will have some small code changes at the end of the day.

  1. Get 4 white 14 guage wires
  2. Strip 1/4" from both sides of each wire
  3. Connect '16 - 14 AWG #4-6 Stud Size Blue Vinyl-Insulated Spade Terminals (75-Pack)' (blue spade) to 1 end of each of 4 wires
  4. Connect 4 blue spade ends to bottom left 12 pos terminal block positions 1,2,3,4
  5. Connect bare end of 4 wires to terminals on left relay board in positions 2 and 3

Water Lights

  1. Get 2 yellow 14 guage wires
  2. Get 2 green 14 guage wires
  3. Strip 1/4" from both sides of each wire

  4. Connect blue spade to 1 end of each of 4 wires

  5. Alternating green and yellow, attach blue spade ends to bottom left 12 pos terminal block positions 5,6 and 7,8
  6. Alternating green and yellow, Connect bare end of 4 wires to terminals on left relay board in positions 4 and 5

Yard Lights

  1. Get 2 yellow 18 guage wires
  2. Get 2 black 18 gauate wires (these need to be fairly long, they connect to transformer for 24v)
  3. Connect red spade to 1 end of each of 4 wires
  4. Get 2 green 18 guage wires (these need to be fairly long, they connect to transformer for 24v)

  5. In order black, yellow, black, yellow connect red spade ends to bottom left 12 pos terminal block positions 9,10,11,12

  6. In order green, yellow, green, yellow connect bare end of 4 wires to terminal on left relay board positions 6 and 7

  7. Run bare end of green and black wires to each red output wire on the transformer

Step 6: Actuators and Pump Internals

Actuators

  1. Get 4 red 18 guage wires
  2. Get 4 white 18 guage wires
  3. Get 4 black 18 guage wires
  4. Get 4 green 18 guage wires
  5. Strip 1/4" from both sides of each wire
  6. Connect red spade to 1 end of each of 12 red, white, black wires
  7. Alternating red, black and white, attach red spade ends to top right 12 pos terminal block positions 1,2,3,4,5,6,7,8,9,10,11,12
  8. Connect bare end of black wires to 1 end of transformer
  9. Connect bare end of green wires to other end of transformer
  10. Alternating red, green and white, connect bare end of 12 wires to terminals on right relay board in positions 1,2,3 and 4
  11. Hang extra wiring on conduit straps at the top of the electrical box

Pump

  1. Get 4 green 18 guage wires
  2. Get 4 yellow 18 guage wires
  3. Strip 1/4" from both sides of each wire
  4. Connect red spade to 1 end of each of 8 wires
  5. Alternating green and yellow, attach red spade ends to bottom right 12 pos terminal block positions 1,2,3,4,5,6,7,8
  6. Alternating green and yellow, connect bare end of 8 wires to terminals on right relay board in positions 5,6,7 and 8

Step 7: Power

System power
  1. Get a standard 110V outlet
  2. Get 14 guage black wire
  3. Get 14 guage white wire
  4. Get 14 guage green wire
  5. Attach '6 AWG, 3/8 in. Blue Vinyl-Insulated Ring Terminals (4-Pack)' (blue ring) to 1 end of each of 3 wires
  6. Attach blue spade to 1 end of each of 3 wires
  7. Connect blue spade end of black wire to outlet live/main connection
  8. Connect blue spade end of white wire to outlet neutral connection
  9. Connect blue spade end green wire to outlet ground connection
  10. Connect blue ring end of black wire to 4 pos terminal block at pos 2
  11. Connect blue ring end of white wire to 4 pos terminal block at pos 3
  12. Connect blue ring end of green wire to 4 pos terminal block at pos 4
  13. Cut a plug off of the end of an extension cord or something that you no longer need
  14. Connect black and white wires from this plug to transformer and secure with wire nuts
  15. Plug in this plug to the new internal outlet
  16. Plug in a wall wart (had to find a smaller one than the one that came with the RPi) to the new internal outlet
  17. Plug in the usb cable to the wall wart
  18. Plug in the usb cable to the RPi

Heater power

  1. Get 2 14 guage white wires
  2. Attach blue ring to 1 end of each of 2 wires
  3. Attach blue spade to 1 end of each of 2 wires
  4. Connect blue ring ends to 4 pos terminal block at pos 1 and 2
  5. Connect blue spade ends to top side of the bottom left 12 pos terminal block at pos 2 and 4

Step 8: Water Lights

  1. Shut off the breaker for the pool and spa light switches
  2. At the top of the light switch box, there should be some sort of electrical connection box. Open this box
  3. Get 2 14 guage yellow wires (long enough to go from light switch into electrical box)
  4. Get 2 14 guage blue wires (long enough to go from light switch into electrical box)
  5. Get conduit, and liquid tight connectors (long enough to go from light switch into electrical box)
  6. Disconnect the black wire (main/load) from each switch, note which black connects to which switch

  7. Connect yellow wire to breaker side of each switch attach with orange wire nut

  8. Connect blue wire to switch side of the main/load connection, attach with orange wire nut

  9. Run all 4 wires through knock out of electrical box, then through Liquid Tight connector, and through conduit

  10. Screw liquid tight connector through knock out on electrical box

  11. Push conduit into liquid tight connector and screw down

  12. Close the electrical box

Step 9: Get the Externals in Place

  1. Run thermistor wires through a knock out hole on the electrical box (found plastic pass-throughs at home depot, but can't find them online)
  2. Connect thermistors to top side of the top left 12 pos terminal block positions 1,2,3,4,5 and 6
  3. Run heater wires through a (should be in a conduit with liquid tight connector already) knock out hole on the electrical box
  4. Connect 2 red wires to top side of bottom left 12 pos terminal block positions 1 and 3
  5. Run water light wires through a liquid tight connector and knock out hole on the electrical box
  6. Connect spa light wires to top side of bottom left 12 pos terminal block positions 5 and 6
  7. Connect pool light wires to top side of bottom left 12 pos terminal block positions 7 and 8
  8. Run actuator wires through a knock out hole on the electrical box
  9. Connect actuator wires to top side of the top right 12 pos terminal block positions 1,2,3,4,5,6,7,8,9,10,11 and 12
  10. Run pump relay wires through 90 degree slip liquid tight connector
  11. Run pump relay wires through conduit, push conduit on to liquid tight connector and lock in place
  12. Attach liquid tight connector to knock out on electrical box, run pump relay wires through
  13. Push conduit on to liquid tight connector and lock in place
  14. Connect pump relay wires to top side of the bottom right 12 pos terminal block positions 1,2,3,4,5,6,7 and 8

Step 10: LCD Display

  1. Get 1 red 18 guage male/bare jumper wire. This needs to be very long, ~2'
  2. Get 1 black 18 guage male/bare jumper wire. This needs to be very long, ~2'
  3. Get 1 yellow 18 guage male/bare jumper wire. This needs to be very long, ~2'
  4. Connect the bare end of the red wire to the 'Serial Enabled 16x2 LCD - White on Black 5V' (LCD display) at the VDD position
  5. Connect the bare end of the black wire to the LCD display at the GND position
  6. Connect the bare end of the yellow wire to the LCD display at the RX position
  7. Connect the male end of the red wire to the
  8. Connect the male end of the black wire to a gnd connection on the Arduino
  9. Connect the male end of the yellow wire to the Arduino on digital input pin 3

Step 11: Arduino Sketch

The sketch was getting very long and confusing, so I broke it out into a bunch of libraries.

MyRelay - Use to set the state of a relay

MyButton - Use to get the state of a button. Includes debounce code

MyThermistor - Use to get the temperature

MyControl - Each device uses this library to get the next control code if a button is pressed and holds the variable whether the user has pressed a button, or serial control code has been sent

There are then libraries for each control type (Flow, Pump, Heat, Cleaning, Water Lights, Yard Lights, Temperatures)

Lastly, the sketch itself which reads serial input, reads user button presses, waits a couple of seconds, and does whatever the user has requested and controls the LCD.

Now you can test your sketch from the Arduino IDE's Serial Monitor by sending commands like '0700' to get the air temperature

Step 12: Command Server

Raspberry Pi and Arduino talk over serial, but every serial connection restarts the Arduino. So, I wrote a Serial command server that starts at RPi boot. It starts at boot, but I'll check its status every minute via cron. The command server only answers localhost, so it shouldn't be hackable. This step requires installation of pySerial.

https://pypi.python.org/pypi/pyserial

Download, unzip, cd pyserial*, exec `sudo python setup.py install`

  1. Put command_server in /etc/init.d/
  2. Put command_server.py in /usr/local/bin/
  3. Put test_server.py in /home/pi/
  4. sudo chmod 755 /etc/init.d/command_server
  5. sudo chmod 755 /usr/local/bin/command_server.py
  6. sudo chmod 755 /home/pi/test_server.py
  7. sudo update-rc.d command_server defaults
  8. cd ~
  9. ./test_server.py
  10. Command To Send: 0700
  11. You should see the air temperature

Step 13: Set Status From Schedule and Persistent Command Storage

I ran into too many failures with the Arduino. It holds state, but the state on digital out is not readable. My concern was what could happen if a scheduled update is missed, so every minute I am pushing what the Arduino should be doing.

Step 14: Delete

<p>Greetings! Awesome build! I am about 95% finished with this. I seem to be running into an issue downloading the command_server file (the one with no extension). Do you happen to have this file avaliable still?</p>
This file is a run control script. The tabs didn't paist very well, but it should still work. Let me know how it goes.
<p>That Worked. Are you using cron to handle the scheduling?</p>
<p>Have you made any progress? I would love to hear if you are successful. I have made a bunch of changes to the pool sketch, but I'm not sure they are compatible with the way I posted this instructable. I would love to get you the latest and hear if it works for you. The last thing I need to do and maybe you can help I need to build an API that I can call from AWS lambda function.</p>
<p>I have(Sorry for the delay)! I got the code working but had to remove quite a bit and write bit more. I wanted to use MQTT to handle the message transport rather than serial, and OpenHab2 to be the head unit/visual. I have finally got all the pieces in place and tested(It's been sitting next to my desk running for a couple weeks now), just waiting for a DC/DC Buck converter so I can run the relays and the controllers off the same 24V transformer without cooking the arduino boards. I also added a weather controller into the mix so that I have tracking in OpenHab of the outside conditions(Rain/Wind/Temp). Setup rules that monitor the temperatures to make sure the pumps don't freeze.</p>
Im using cron to run 'regular.py'. Theres so much more going on... i have an alexa skill to turn on the spa and the furnace.. too much for here.
#!/bin/bash<br>#/etc/init.d/command_server<br><br>### BEGIN INIT INFO<br># Provides: command_server<br># Required-Start: $remote_fs $syslog<br># Required-Stop: $remote_fs $syslog<br># Default-Start: 2 3 4 5<br># Default-Stop: 0 1 6<br># Short-Description: Starts a server to talk to arduino over /dev/ttyACM0<br># Description: /usr/bin/command_server.py is started and runs in the background.<br># This keeps the serial port open so Arduino doesn't restart every<br># command you send it.<br>### END INIT INFO<br><br># Carry out specific functions when asked to by the system<br>case &quot;$1&quot; in<br> start)<br> echo &quot;Starting command_server&quot;<br> # run application you want to start<br> /usr/local/bin/command_server.py &amp;<br> ;;<br> stop)<br> echo &quot;Stopping command_server&quot;<br> # kill application you want to stop<br> killall command_server.py<br> ;;<br> *)<br> echo &quot;Usage: /etc/init.d/command_server {start|stop}&quot;<br> exit 1<br> ;;<br>esac<br><br>exit 0<br>

About This Instructable

48,623views

63favorites

License:

More by kenrumer:Custom Pool Controller - Arduino and Raspberry Pi 
Add instructable to: