Replace Your Pool and Spa Controller With Raspberry Pi, Arduino, Node Red

9,218

73

21

In this Instructable I will describe how to build a pool and spa controller that controls a pump motor, multiple electric valve actuators, lights, a cleaner, air blower, and heater. It also measures the water and air temperatures. I built this to replace an old Compool pool controller which broke. The Compool model I had is obsolete and replacing it with a new controller and associated parts would cost around $800. I built this replacement for about $75 (using some parts I already had - buying all new will run about $100).

This pool controller uses Node Red on a Raspberry Pi to provide a web interface for controlling the various devices and displaying the temperatures. The Raspberry Pi has the high level logic to do things like determine whether to turn on the heater based on a temperature setting and the current water temperature and ensure that only valid combinations of devices can be operated at the same time. An Arduino Nano has the low level logic to turn on and off a set of relays which in turn control various motors and valves. The Arduino also reads the temperature sensors. The Raspberry Pi is inside my house and the Arduino is outside by the pool equipment; they communicate over a USB cable.

Rather than provide just a step by step listing of how I built this controller, I will also explain how the various controlled devices work. With that knowledge, you could easily build a controller for a brand new system rather than replace the controller for an existing system like mine.

This project requires some knowledge of electronics because you will assemble and solder various components together to build the controller. It will be helpful to understand the basics of reading a schematic because I provide two, one that describes the whole device and another that describes the power supplies. They are very helpful in understanding the controller as well as fixing any issues that might arise.

Let's get started!

Step 1: How Motors, Actuators and Heater Work

Each controlled device has its own method of operating. They require different voltages, some are AC and some are DC, etc. All of the devices connected to my controller fall into four categories: motors and lights, valve actuators, heater, thermistors.

Motors and Lights

My system has a single 240V, 2HP electric motor. It is turned on by switching a heavy duty double pole relay which switches both lines of the 240V. The blower motor and lights operate on 120V electricity and use the same type of relay to operate (see picture). The relay is labeled "24VDC". I tested it and it requires only about 12-13VDC to activate and will stay activated until the applied voltage drops below about 3VDC. These are expensive relays, about $80 each, so I reused them. Feel free to substitute a different, cheaper brand if you are starting from scratch.

Valve Actuators

My pool has three valve actuators, i.e., electric motors that turn valves to make the water flow through different pipes. One is for the intake water - intake from pool or intake from spa. Another is for the return water - return to pool and spa or return to spa only. The third is for the automatic cleaner which operates with pressurized water diverted from the pump's output.

Valve actuators operate on 24VAC. They have three wires, typically black, red and white. Black is connected to the first leg of the 24VAC. To operate the actuator in one direction, you apply the second 24VAC leg to the red wire; to operate the actuator in the other direction, you apply the second 24VAC leg to the white wire. There are switches inside the actuator that stop it once it has reached its limit, i.e., you do not have to disconnect the power, you can just apply the power for the direction you want it to turn and leave it applied rather than having to somehow figure when it's gone far enough and cut the power. Also, the actuators have a three position switch (see picture of bottom of actuator). It turns the actuator off in the middle position, the other positions choose which direction it will turn - if you have it in one position, then applying power to red will operate it clockwise and applying power to white will operate it counterclockwise. If you have it in the other position, then applying power to red will operate it counterclockwise and applying power to white will operate it clockwise. This means that if you wire red and white backwards, all you have to do is flip this switch to the other direction to make it work properly. Sometimes you get lucky and mistakes don't matter!

Heater

My heater is a Hayward and it has a lot of complicated electronics inside as well as a ton of safety features that prevent it from running if water is not flowing, the temperature gets too hot, the gas supply falls below pressure and more. It sounds complicated, but the good news is that you don't have to worry about any of that. All it requires is two wires that either have 24VAC or 0VAC. It turns on when at 0VAC, off at 24VAC.

A heater will typically have two electrical connections, one for high voltage (120 or 240VAC) power and one for low voltage control power (24VAC). On my Hayward heater, both the low and high voltage could be connected on either the left or right side of the heater. There is a small panel on each side you can remove to get access to the connections. If you are replacing a controller, the high voltage line should not require any changes. The Hayward heater that I have can use either a two or three wire remote. A three wire remote just tells the heater whether to operate in pool or spa mode and the heater itself determines when to turn on and off based on its temperature settings for the pool and spa temperature (which are set on the heater's control panel). A two wire remote is basically just an on/off switch; whatever it is connected to determines when to turn the heater on or off. In this project, we are using the Raspberry Pi to check the temperature of the water and the pool and spa settings and turn on the heater if necessary, so we are using a two wire remote. This allows us to set the pool and spa temperature in the web interface rather than having to set those on the heater. The two connections used are the ones labeled POOL and 24V.

Thermistors

Thermistors are the devices that measure temperature. They are resistors whose resistance varies with temperature. Their resistance is about 10K. One of the thermistors I bought was made for pool use with a base and rubber O-ring so that it could be mounted in a hole drilled in a pipe carrying water to measure the water temperature. The other was a generic thermistor that I used for the air temperature; I bought a pack of five for less than ten dollars and that gave me extras to use for testing.

Step 2: Controller Design

I will describe how the controller works conceptually before we dive into how each of the pieces works.

A web interface has user controls to choose between everything off, pool or spa mode. It has switches to turn on the pool cleaner, lights, air blower for the spa, and to enable the heater. It has temperature gauges for the water and it allows you to set the temperature of the pool and spa so that when they are on, the heater will bring the water up to temperature and then turn off. It has a second temperature gauge for the outside air temperature.

The web interface is written in Node Red and runs on a Raspberry Pi which is inside my house. There is an Arduino Nano which is outside the house near the pool equipment. The Raspberry Pi monitors all the user controls and temperature settings and periodically communicates with the Arduino over a USB cable to tell it what to do with each of the various devices that the controller controls. The Arduino also measures the water and air temperature and sends that information back to the Raspberry Pi.

The Arduino controls the devices via a set of relays that switch various voltages either on and off, or from one connection to another to operate them. There are three small power supplies that provide three different DC voltages for various purposes.

The schematic shows the Arduino, relay board and power supplies. Even if you don't have much experience with schematics, It will be well worth your while to take some time to understand it - it does not have a lot of electronics mumbo-jumbo and is basically just a picture of how things fit together.

Step 3: Lexan Base

I used a piece of Lexan plastic as the base to mount all the circuitry for this controller. There were several different components (Arduino, relay board, etc.) and by mounting them all on one board, you can assemble it inside and mount it as a unit in the box outside next to the pool equipment. If you make sure every connection to something on that board is detachable, then you can remove it as needed to do repairs and upgrades.

I used 4-40 spacers, nuts and bolts to mount the various components to the Lexan and I used 8-32 machine screws to mount the Lexan base to the metal cabinet outside that used to house the old controller.

Step 4: Power

Above I mentioned that you need 24VAC for the heater and valve actuators as well as DC voltage of at least 12-13 volts for the heavy duty relays. My Compool controller had a transformer that provided 24VAC, 18VAC and 10VAC. I used the 24VAC directly for the valve actuators and heater. Later, you will see that in addition to DC power for the 24VDC relays, you also need 9VDC to power the Arduino and 5VDC to power the relay board. To create these three DC voltages, you need to build three little power supplies, all identical but set to the different voltages.

Take a look at the power supply circuit. It is a full wave bridge rectifier feeding into a smoothing capacitor which in turn feeds into a buck converter. The type I used is called the XM1584, it can handle input voltages up to 28VDC and will output up to 3A. See the attached pictures of a bare XM1584 next to a paper clip, which shows how tiny it is, and the completed circuit board with three power supplies. There is a small screw that you turn to set the output voltage. The output voltage must be less than the input voltage, so I set the three to 5VDC, 9VDC and 20VDC for the "24VDC" relays that actually require less than 24VDC to operate. The XM1584 buck converters are less than a dollar each from China and because they are switching power supplies, they do not get hot (unlike linear regulators). There are other models, e.g., LM2596, than would probably work just as well. I used a 1mF (1000 microfarad) electrolytic capacitor on the 5VDC and 9VDC power supplies and a 2.2mF capacitor for the 20VDC power supply.

I soldered all three power supplies on a single circuit board that is located near the top of unit because that is where the existing transformer leads are located. See the picture for the finished set of power supplies.

Step 5: The Relay Board

There are three motors and lights, three valve actuators and a heater. That is seven devices that need to be operated by routing power appropriately. This controller uses a relay board with eight relays. Each relay has one normally open contact and one normally closed. When looking at the relay, there is a little diagram that shows the center connection in contact with one of the other connections. That is the normally closed connection; the other is the normally open connection. The center pin will be connected to one or the other of the other two connections.

Each relay is operated by 5VDC which happens to be the output voltage of an Arduino pin. A nice feature of these boards is that the Arduino connections are isolated from the relay coil power, so there is essentially no possibility that voltage spikes from the relays will harm the Arduino. In order to take advantage of that, use a 5VDC power supply that is not connected to the Arduino (this is the purpose of the 5VDC power supply described in the prior step).

There are two headers on the relay board, a ten pin header and a three pin header. The three pin header is for the relay coil power (i.e., the 5VDC mentioned above). Make sure to remove the jumper and connect positive to the JD-VCC pin and negative to the GND pin. The ten pin header controls the relays. Connect the VCC connection to the 5V pin on the Arduino and the GND connection to the GND pin on the Arduino that is next to pin D2. The other eight pins control the eight relays. The relay is off when the pin is high (5V) and the relay is on when the pin is low (0V).

In order to connect the actuators, heater and other relays to the relay board, I salvaged the various connectors from the old controller board and soldered them to a small circuit board which I then connected to the relays on the relay board.

The first three relays on the relay board are used to turn on the heavy duty relays for the pump, lights and blower respectively. Each of those requires 20VDC, so wire the positive connection of the 20VDC power supply to the center connection and run a wire from the normally open connection to either wire of the heavy duty relay. Connect the negative connection of the 20VDC power supply to the other connection of the heavy duty relay.

The next three relays on the relay board are used to make the actuators go in one direction or another. Connect one leg of 24VAC to the black wire of each actuator. Connect the other leg of 24VAC to the center connection of the three relays. Connect the normally closed connection of the relay to the red wire of the actuator and connect the normally open connection of the relay to the white wire of the actuator (remember, it's not critical, but just being systematic here).

The seventh relay is used for the heater. The heater requires 24VAC to be off and 0VAC to be on. Connect the first leg of 24VAC to one wire of the heater and to the normally open connection of the relay. Connect the second leg of the 24VAC to the normally closed connection of the relay. Connect the second wire of the heater to the center connection of the relay. This means the when the relay is off, one wire of the heater is connected to the first leg of the 24VAc and the other wire is connected to the second leg of the 24VAC, so the heater gets 24VAC. When the relay is on, both wires of the heater are connected to the first leg of the 24VAC, so the heater sees a 0VAC potential difference and turns on.

Step 6: Arduino and Thermistors

Solder an IC socket to a small circuit board so you can easily remove the Arduino for programming. Solder headers to the circuit board and connect them to the pins of the IC socket so you can use jumper wires to make connections to the relay board and other places. Use a ribbon cable with header connectors on the ends to connect the Arduino to the relay board. Connect pin D11 on the Arduino to relay 0, pin D10 to relay 1, etc.

Get or make two wires that have a female header connector at one end and bare wires on the other end. Solder them to the positive and negative connections of the 9VDC power supply and connect the header connectors to the Arduino VIN and GND pins.

Create the voltage dividers with the thermistors. Connect 5VDC from the Arduino to one end of a resistor. Connect GND from the Arduino to one wire of the thermistor. You now have one unattached wire of the thermistor and one unattached end of the resistor. Connect these together along with a connection to an analog pin on the Arduino (pin A0 for the water temperature thermistor and pin A1 for the air temperature thermistor). As you can see in the picture of the full controller, I used a separate circuit board for the thermistor connectors, but if you can fit them on the same circuit board as the Arduino, that would be better.

The Arduino communicates with the Raspberry over a serial connection, i.e., a USB cable plugged into the USB connector. The Arduino writes the values of the water and air temperature to the serial port and it reads the desired state of the relays from the serial port. The attached sketch implements that. Setting the relay pins is just a digitalWrite() function call, while reading the temperature involves reading the raw voltage and then applying a standard formula (which you can find on Wikipedia) to convert that to degrees Fahrenheit (simple change to make it Celsius).

If you have never programmed an Arduino before, It is not difficult. There are many sources that describe how to do it, like this Instructables class. Upload the attached sketch to your Arduino. Then plug it into the IC socket on the circuit board - make sure the pins are lined up properly!

The Arduino has to do two things: respond to commands from the Raspberry Pi to set the relays, and read the water and air temperatures and send them to the Raspberry Pi. It uses serial communication for this.

When a serial message is received on the serial port, the function serialEvent() is called. The format of the relay setting is a single byte where each of the eight bits in the byte corresponds to one of the eight relays. Having the entire message in one byte means there is no need to worry about where the message starts and ends - every byte is a complete message. The byte is decomposed and the bits used to set the relays. It does this every time for all bits, even if the state of the bit has not changed. This is very simple and reliable; there is very little logic in the Arduino code which minimizes the chances of a bug in that code.

The main loop() function of the Arduino calls the function getTemp() twice - once to get the water temperature and once to get the air temperature. The function itself implements a formula you can find on Wikipedia or other places which converts the resistance of the thermistor to a temperature. The temperatures are sent in strings to the Raspberry Pi. Future upgrades (the subject of a future Instructable!) will likely require more than one byte of data, so in this case a string is used with a keyword for the type of data followed by the data itself. The loop has a delay of 2 seconds (2000 milliseconds) because there is no need to send the temperature any more frequently.

That's all the Arduino has to do, set relays and read temperatures. The Raspberry Pi handles everything else.

Step 7: Raspberry Pi and Node Red

The pool controller logic is implemented in Node Red on a Raspberry Pi. Node Red is a system that allows you to create logic flows graphically. The graphical representation makes it easy to understand the flow. You have to do a bit of programming in the nodes but that is not hard.

The UI is implemented with a set of Node Red nodes called the Node Red Dashboard. These nodes provide the dropdown that lets you choose pool, spa or off, the switches to turn on the cleaner, blower, lights and heater, the gauges to show water and air temperature, and the numeric input that lets you set the pool and spa temperatures. It automatically formats the various controls so it looks nice and works properly on a desktop computer web browser or on a smartphone browser.

The model for this flow is that inputs that come in via the serial port from the Arduino and from the various Node Red Dashboard controls set the state of the system. Periodically, a separate process reads the current state of the system, figures out what needs to be set on the Arduino and sends the appropriate commands as a serial message to the Arduino.

For example, there is a switch in the UI called Cleaner. When that switch is turned on, it sets a variable called CleanerSetting to true. There is a node called PoolControlHearbeat that reads the value of CleanerSetting. If it is true, it sends a message to the Arduino to turn on the relay for the cleaner.

If you have not used a Raspberry Pi before, there are many sources that describe how to get one up and running, like this Instructables class. You need to install Raspbian with the desktop so that you can perform the following steps and you will need to connect it to a monitor, keyboard and mouse to set this up, but after it is all set up you will not need the monitor, keyboard or mouse. You probably also want to set it to have a static IP so that you can access it from other devices in your home easily, and if you are going to run it headless, i.e., without monitor, keyboard or mouse, then you will need to enable ssh access (select Raspberry Pi config from the main menu to find these options) so you can access it if you ever need to power it down cleanly (it's not a good idea to just pull the power plug on a Raspberry Pi). For security reasons, I set mine up so that it is only accessible from my home intranet (not from the outside internet). Also, use Raspberry Pi config to ensure logins over the serial port are disabled (for two reasons: you will be using it to communicate with the Arduino so you do not want it to be sending login prompts to the serial port, and so that someone cannot unplug the USB cable and login to it from outside your house).

Lastly, install the Chromium browser and use that for Node Red; as of this writing, Chromium works best with Node Red. After you have set everything up and are logged in, check the main menu - Node Red should be an option on the Programming menu. Select that and let it start to make sure it works. You will need to perform a step to make Node Red start when the Raspberry Pi is booted (so you will not need to start it from the menu every time you restart the Raspberry Pi). Execute the following command in a Terminal window:

sudo systemctl enable node-red.service

Then, reboot. (Note: you need to start it as a service before you import the flow below, otherwise it will not find the flow you imported, so enable it as a service as just described before continuing.) Open the Chromium browser and connect to the address http://localhost:1880. That will open the Node Red workspace in your browser. Check if Node Red Dashboard is installed because it might not be installed by default. Open the menu (hamburger icon at the upper right), then select Manage Palette. Under Nodes, search for node-red-dashboard. If it is not there, go to Install, search for and install it. Once it is installed, you will see a set of nodes under the category dashboard with names like button, switch, gauge, chart.

You can now import the entire flow shown graphically in the attached picture by importing the file attached to this Instructable is called PoolControlFlow.txt. Download it and put it on a USB drive that you insert into your Raspberry Pi. Go to the Node Red menu on the browser page and choose Import. Navigate to the PoolControlFlow.txt file and select it. That will import the entire flow that runs this pool controller, so you don't have to program it all yourself.

Test that you can access the UI is accessible from the browser, too. Open the URL http://localhost:1880/ui. If you set a static IP, try accessing the UI from another computer or smartphone by substituting the IP address for the word localhost in the URL. If you have an Arduino on a breadboard for testing as described earlier, then you can connect it with a USB cable and try the various controls to see the LEDs go on and off (note that and LED on corresponds to the relay being off, and vice versa - that's how the relay board works). You can also connect a couple of spare thermistors for testing that the temperature gauges work.

Node Red Flow Description

If all is working, then you don't need to read this section, but if you are interested, this explains how the various parts of the Node Red flow work.

The ArduinoSerialGet node listens on the serial port for messages from the Arduino. Those messages have a keyword, one of H2O or AIR, followed by a colon and a number that is the value. The SerialMsgRouter node routes the message to one of two nodes corresponding to the keyword. The string is converted to a value that is sent to a gauge on the UI and a node that sets the value of a variable, H2OTemp or AIRTemp.

There are two nodes that set the default temperature settings for the pool, DefaultPoolTemperature (set in the node to 82) and DefaultSpaTemperature (set in the node to 100). Those values feed into the numeric controls on the UI so they have an initial value and also into the PoolTempSetter and the SpaTempSetter which set variables with the values. These are like thermostat settings, they are the temperature you want the pool water to be, while the H2OTemp is the temperature that the pool water is. The RelaySetter (described below) uses these to decide when to turn on the heater.

The Light switch turns the lights in the pool and spa on or off. The can be turned on whether the pool or spa is running or not.

The HeaterEnable switch does not directly turn on the heater. If it is off, then heater will not turn on in any situation. If it is on, then the heater will turn on if needed (see below). This allows you to maintain your temperature settings but not heat the pool until you decide to enable the heater.

The Cleaner switch turns on the automatic cleaner which is driven by a water line from the pump. That is controlled by a valve actuator.

The Blower switch turns on the air blower which adds bubbles to the spa. The blower is an electric motor.

The dropdown Off/Pool/Spa can be set to one of three values: Off, Pool or Spa. This sets a variable, PoolSpaMode to one of those values. This mode is also part of what is used in the RelaySetter to determine when to turn on the heater. The mode also enables or disables certain controls. If the pool is on, then you do not want the air blower for the spa to be turned on. Conversely, if the spa is on, then you do not want the cleaner to be turned on. So, whenever the pool is turned on, it turns off the blower switch and disables it, and also enables the cleaner switch. Whenever the spa is turned on, it turns off the cleaner and disables it, and also enables the air blower. Whenever the Off setting is chosen, it turns off both the cleaner and blower.

The PoolControlHeartbeat periodically sends a message to the RelaySetter which triggers it to check the settings of the cleaner, blower, lights and send the corresponding relay settings to the Arduino. The RelaySetter turns on the pump relay if the mode is Pool or Spa and turns it off if the mode is Off. The RelaySetter also turns on the heater if necessary. It does this by first checking to see if the HeaterSetting is on, i.e., if the heater is enabled. If the heater is enabled, then it determines what is the appropriate temperature setting - if the mode is Pool, then it uses the PoolTempSetting value; if the mode is Spa, then it uses the SpaTempSetting value. It compares that value to the H2OTemp value, i.e., the current water temperature. If the current water temperature is below the setting, then it turns on the relay for the heater, otherwise it turns it off. Lastly, the RelaySetter sets the intake and return valve actuator relays to off if the mode is Pool and on if the mode is Spa.

Once all relay values are known, a single byte is created where each bit corresponds to a relay and where the bit is set (value 1) to turn on the relay and the bit is unset (value 0) to turn off the relay. This byte is sent as a serial message to the Arduino by the ArduinoSerialSet node.

Step 8: Put All the Pieces Together

At this point, you have power supplies, a relay board, a curcuit board with a socket for the Arduino and the thermistors, and a circuit board with sockets for the devices controlled by the relays. Now you need to put all those pieces together. The pictures show two views without some of the cables so you can see how I laid out the components and another with the cables so you can see how it looks completely assembled. Refer to the schematic in the Controller Design section as well.

Drill holes on the Lexan backer to mount the relay board and other circuit boards. Use 4-40 spacers to mount the boards.

The positive output from the 24VDC power supply goes to the middle terminal of each of the relays #1, 2, 3. Daisy chain the connections, i.e., use one wire from the 24VDC power supply to the first relay, then a short piece of wire from the first relay to the second, and again to the third. The normally open (NO) terminals of those relays go to the corresponding connector for the heavy duty relays. The negative output from the 24VDC power supply goes to the second connection for each of the heavy duty relays. There is no connection to the normally closed (NC) terminals of the first three relays.

The positive output from the 9VDC power supply goes to the VIN pin of the Arduino and the negative output from the 9VDC power supply goes to the GND pin of the Arduino. The easiest way to make the wires you need is to get two jumpers with a female header connector on one end and cut off whatever is on the other end and strip the wire.

The 5VDC power supply must only be used for relay board power to achieve the isolation of the inputs from the switched relay connections. Remove the jumper on the three pin header. Connect the positive output to the JD-VCC pin and the negative output to the GND pin.

Connect leg one of 24VAC to the middle terminal of relays #4, 5, 6. Connect the NC terminal to the red wire of each valve actuator and the NO terminal to the white wire of each valve actuator. Connect leg two of 24VAC to the black wire of each valve actuator.

Connect leg one of 24VAC to the NC terminal of relay #7. Connect leg two of 24VAC to the NO terminal of the relay and one side of the heater connection. Connect the middle terminal of relay #7 to the other side of the heater connection. This ensures it is never floating, it is at 24VAC when the relay is off and at 0VAC when the relay is on.

Jumper wires often come in strips of multiple wires fastened together. If you have some like this, peel off a set of ten. Connect one end to the ten pin header on the relay board. Connect the other end of the GND wire to the Arduino Nano GND at the pin next to the RST pin. The other end of the VCC wire has to be connected to the 5V pin on the Arduino, but that is also required for the thermistors, so solder to the same board as the thermistors or add a header pin to that board and plug in the jumper.

Connect the first seven relay inputs to pins D11 through D5 on the Arduino (relay #8 is not used, so I deliberately left it unconnected so it cannot activate the relay).

I salvaged a number of two and three pin PCB headers and corresponding plugs from the old controller by desoldering them. You can do that or buy similar connectors and a crimping tool to make your own. Or, you can buy terminal blocks that you can solder to the circuit boards so all you have to do is strip the wires to be connected. The key thing is that while it is fine to solder connections between circuit boards on the Lexan backer, you want everything that connects something external to the Lexan backer to be a plug and socket so you can easily remove the Lexan backer with all of the circuit boards, relay board and power supplies and work on it in a more convenient location if necessary. I made a couple of mistakes where I had to rewire and resolder certain parts and it was easy since I could just remove the whole panel and bring it to where I had the solder iron and other tools. Label the various plugs and sockets to make it easier to reconnect everything. Put all the two and three pin headers on a separate circuit board next to the outputs of the relays since that is where they all need to be connected.

Add a power connector for the power supply input. I also salvaged that from the old controller so that it would fit the plug that was already fitted to the transformer output.

Step 9: Optional: Test Setup

It is handy to test the controller without having to connect it to the actual pool equipment. You can do this with a breadboard, two spare thermistors, two 10K resistors, seven LEDs, seven 100 or 220 ohm resistors and some jumpers. Create a voltage divider just like the main unit with the thermistors and and 10K resistors and connect the midpoint to pins A0 and A1. Connect each of the pins D5-D11 to one end of a 100 or 220 ohm resistor, then connect the other end of the resistor to the positive lead of the LED, then connect the negative lead of the LED to the ground bus. Connect the power and ground buses to the 5V and GND pins of the Arduino. Connect the USB connector to the Raspberry Pi and boot up the Raspberry Pi. It will power the Arduino via the USB cable.

In the Off setting of the interface, all of the LEDs should light (counterintuitive, yes, but recall that the relays are off when their inputs are high and on when low). As you try the different settings of pool, spa, blower, cleaner and heater, the LEDs should turn on and off appropriately.

The Node Red interface should show the air and water temperatures which you can test by dunking in hot or cold water.

You can test the heater by setting the pool or spa temperature above and below the water temperature shown on the gauge and watching the heater relay LED (pin D5) turn on when the settting is below the water temperature and turn off when the setting is above the water temperature.

Step 10: Install

Now that you have completed the controller unit, you need to mount it by your pool.

Note: the voltages involved with pools include 24VAC, 120VAC and 240VAC, easily enough to kill you if you touch the wrong wires or wire something incorrectly. If you are not experienced with electrical work like this, get an expert to set that up and do just the low voltage part yourself.

Drill holes for 8-32 machine screws in the enclosure that has the power and transformers supplying AC and mount the Lexan to it. Or, if not replacing a unit like I was, create an enclosure with appropriate power supplies. (If you are starting from scratch, you don't have to have three different AC inputs, you can pick whatever is available and cheap for the transformer, as long as it can supply 24VAC and the three DC power supplies.)

Run a USB cable from the enclosure at the pool into your house for the Arduino to Raspberry Pi connection. If you are replacing a controller, there will already be a cable routed between the two locations. Attach the USB cable to that and pull it through. NB: You might ask why not just put the Raspberry Pi outside the house in the pool enclosure as well? That would certainly work and avoid running cables into your house, but keep in mind that the Raspberry Pi has a direct connection to your home network via wifi, including the wifi password, so if it is outside, anyone can get to it and gain physical access to your home network.

The water temperature thermistor needs to be mounted in the water pipe. My old controller's thermistor was mounted in the PVC pipe just downstream of the pump. The new thermistor was slightly larger, so I had to drill the hole out a bit. Run the wire into the enclosure and put the appropriate connector on the end for attachment to the connector on the circuit board. The generic thermistors I bought already had a two pin connector, so it fit into a two pin connector that I salvaged. Place the generic thermistor inside the enclosure with the controller board, that will be the air temperature it measures.

Mount the Raspberry Pi somehow and run power to it. I initially intended to run 5VDC from the controller to the Raspberry Pi so that I would not need a separate power cord, but after reading more about it, decided it was better to power it the normal way, i.e., with a 5VDC power supply inside the house connected to the micro USB connector.

Connect all the controlled devices first, then the USB cable to the Raspberry Pi, then connect power to the unit and turn on the circuit breaker. Nothing should happen except a light glowing on the Arduino since the default is for everything to be off. Start the Raspberry Pi (which should automatically start Node Red if you followed the earlier instructions). Bring up the interface on a web browser and turn on the pool. Check the water and air temperature gauges to make sure they make sense. Test all the other functions to ensure they work. Check that the valve actuators turn in the proper direction; if not, just set the switch on the actuator to its opposite setting.

After you test that all is working, you can run the Raspberry Pi in headless mode. Power it down, disconnect the display and keyboard, then power it back up and test you can still access the web interface and can ssh to the Raspberry Pi.

You're done! Enjoy your pool and spa!

Step 11: Troubleshooting

Note: the voltages involved with pools include 24VAC, 120VAC and 240VAC, easily enough to kill you if you touch the wrong wires or wire something incorrectly. Many of the steps below require the main power to be on so that you can check for proper voltage at the controlled devices. If you are not experienced with electrical work like this, get an expert to help with the troubleshooting.

The relay board has a red LED for each relay that turns on when the relay is activated. If some device is supposed to be on, check that the red LED is on. If the LED for the wrong relay is lit, then check that the jumpers are wired correctly from the pins D5-D11 onthe Arduino to IN1-IN8 on the relay board. If the proper red LED is lit, use a multimeter to determine where in the chain from power supply to the device it is failing. If there is the appropriate voltage at the device, then check the device itself.

The thermistors should have 5VDC applied between the end of the resistor that is connected to the 5VDC connection on the Arduino and the wire of the thermistor that is connected to GND. Check that first, then if it is okay, check that the voltage at the three way connection (other end of the resistor, other wire of the thermistor, wire to pin A0 or A1 of the Arduino) is at some voltage roughly midway between 0 and 5VDC. Make sure the jumper is connected properly to pin A0 or A1.

If the problem is on the Raspberry Pi end, power it down over ssh and restart with a display and keyboard attached. Open Node Red in a browser. The serial interface nodes should show that it is connected to the Arduino. You can add a Debug node to the same output that sends the serial message to the Arduino so that you can see the value of the serial bytes in the Debug window in Node Red. You can add Debug nodes anywhere else to check what is happening. Remember to redeploy after adding or changing any nodes.

The service and installation manuals for heaters, valve actuators, pumps, etc. are often available online. If your device is not like the ones described here, it might be well worth your while to find the manual and see what it says about how it works and how to use it. For example, the manual for my Hayward heater describes in detail the electrical connections and the difference between two and three wire remotes (though it didn't mention that 0VAC is on and 24VAC is off; that I discovered by trial and error!).

Step 12: Parts List

This is a list of the parts used. Prices are for buying from US sources like Amazon. You can save a fair amount by buying electronics from China, e.g., from AliExpress, if you are willing to wait a little for the shipping. Buy things like Arduinos and buck converters and protoboard in multiples of three or five or ten, then you'll have some extra for future projects!

Raspberry Pi - about $35 plus power supply, case - I used a model 3 which has built in wifi but any model that can run Node Red and can connect to your home network. I'm planning to try a Pi Zero W ($10).

Arduino Nano - about $8 for one from local sources or $3 each in multiples of 5-10 from AliExpress or other similar sites - other models would also work but you might have to change the sketch to accommodate different pin layouts. You need one with at least seven digital outputs (for the relays) and two analog inputs (for the thermistors).

Lexan - about $5 for an 8.5x11 sheet from Lowe's or Home Depot

Water thermistor - about $25 - Pentair 520272 from Amazon

Air thermistor - about $2 each in a pack of 5 - OCR 10K-5

USB cable to connect Raspberry Pi and Arduino Nano - about $8 - $10 depending on the length - Cable Matters Gold Plated Hi-Speed USB 2.0 Type A to Mini-B Cable

Relay board - about $7 each in a pack of two - Huayao 2pcs 8 Channel DC 5V Relay Module with Optocoupler for Arduino

Buck converter - about $1.20 each in a pack of 10 (you need 3 for this project) - LIGHTHINKING 10PCS XM1584

Circuit boards (a.k.a., protoboard) - about $6 each, get two - Busboard Protot SB400

Capacitors: 1000uF or 2200uF (not critical) - about $6 for a pack of 10 - Nichicon 2200uF, Nichicon 1000uF. You can use 1000uF or 2200uF for all three, I just happened to have two 1000uF and one 2200uF.

Resistors: 10K ohm - $4 for 100 - 100 Uxcell 10K resistors

Wire and solder

Jumpers

Screws and spacers for circuit board mounting

Optional: breadboard, resistors and LEDs for the test setup

Tools: soldering iron, multimeter, drill

Total cost for parts is about $100 including extras as mentioned above. If you are like me and already have Arduino Nanos, capacitors, buck converters and other items sitting around waiting to be used in projects like this, it will cost less. A lot of electronic parts, like resistors and capactors, are much cheaper if you buy them in assortments that include a number of different sizes and several of each size.

Fix It! Contest

Runner Up in the
Fix It! Contest

Share

    Recommendations

    • Toys Contest

      Toys Contest
    • Make it Glow Contest 2018

      Make it Glow Contest 2018
    • First Time Author

      First Time Author

    21 Discussions

    0
    None
    tgvoss

    2 months ago

    I am not an Arduino/RaspberryPi expert so maybe this is already evident but why not just use the RaspberryPi with the included I/O ports? Is it necessary to use the Arduino for low level logic or could you set up this type of system on just eh RaspberryPi? I know the Pi does not have Analogy I/O so maybe that is the reason?

    2 replies
    0
    None
    neilroethtgvoss

    Reply 2 months ago

    A Pi could certainly handle the logic; it is not necessary to use an Arduino. An earlier comment by nessiemack talked about using just a Raspberry Pi. The reasons I used an Arduino/Pi combo instead of just a Pi are:

    1) The Arduino has analog inputs, the Pi does not, and I wanted to use analog thermistors. Options include using a digital thermistor, or getting an ADC for the Pi. I had about 10 Arduino Nanos that I bought for approximately $3 each, and I found multiple sketches online for the Arduino to convert the analog voltage from a thermistor to a number, so using an Arduino for this project made sense for me.

    2) I wanted the Pi inside my house because access to my home wifi is better inside and also because putting the Pi outside meant someone could take it, or use it to hack into my home network. If it is inside, then communicating to the devices outside means either running a whole bunch of wires between the relay board and thermistors outside to the Pi inside, or having the Arduino outside and running just one USB cable from there to the Pi.

    One of my reasons for explaining how everything works was so readers would have the knowledge to explore alternatives methods of accomplishing the same goals, or apply the ideas to different situations - like using a Pi only instead of a Pi/Arduino combo if it makes more sense in your situation, or if you are more comfortable programming a Pi than an Arduino.

    0
    None
    tgvossneilroeth

    Reply 2 months ago

    Interesting points, very helpful. I am working on swapping out the control unit for a blow up hot tub that I have had a dream of connecting to the internet for added functionality and adding a solar heat exchanger. This method will hopefully get me there. Thanks for introducing me to node-red and being so descriptive in your ible'. Really great project!

    0
    None
    SteveDonie

    Question 2 months ago on Step 12

    Could you post some details on how you connected to the heater, or how you figured out where the heater connection was?

    2 answers
    0
    None
    neilroethSteveDonie

    Answer 2 months ago

    Hi, Steve. I updated the section that describes how a heater works with more details and added a paragraph in the troubleshooting section about service and installation manuals as well. I hope that helps!

    0
    None
    SteveDonieneilroeth

    Reply 2 months ago

    Thanks - that is excellent. I also have a Hayward heater, so that helps a ton. Can't wait to get started on this! I have some ideas for tracking temperature over time and tracking heater use to give me a better idea how much I am spending.

    0
    None
    neilroethRenato STILINOVIC

    Reply 2 months ago

    Good catch, thanks! I'll fix the schematic. In the meantime, for anyone building this, the two '~' symbols on the rectifier are the AC input and the '+' and '-' outputs should be connected to the '+' and '-' of the capacitor and buck converter inputs.

    0
    None
    onetruegod

    2 months ago

    This is a well written, functional, money saving project. Thanks for documenting it so well. Now if only I had a pool...

    0
    None
    Netmizor

    2 months ago

    Thank you for taking the time to do a good write-up on your controller project. I taught Electronics Technology some year s ago and will say you did a pretty good job of keeping things in understandable layman's terms. I too have a pool and have been trying to figure out how I might re-create or modify the single-lever manual filter valve so that I could control it with an RPi. Ideally, I want the system to circulate and filter for a fixed period of time throughout the day and night, and during this time have the controller periodically move the valve to the backwash position and return it to the filter position when complete. I think I might be able to use the relative cloudiness of the sight glass to determine when it's clear enough to switch the valve back to filtering. Temperature monitoring will be included although I have no heater so that may be moot. You project has inspired me to take another swing at this!

    1 reply
    0
    None
    neilroethNetmizor

    Reply 2 months ago

    Go for it! Node-RED has a couple of node types that might be helpful to you. A Timestamp node can perform a task at regular intervals and an Inject node can perform an action at a specific time (turn on at time A and turn off at time B). The valve actuators on my system are add-ons to otherwise manual valves - maybe there is some kind of add-on electric actuator for your type of valve.

    0
    None
    JeremySCook

    2 months ago

    For the valve actuators and heaters, did you mean 24VDC? You have AC listed, which seems strange, but perhaps this is normal for pool systems?

    2 replies
    0
    None
    neilroethJeremySCook

    Reply 2 months ago

    The valve actuators and heater are 24VAC, not 24VDC. In the picture where I showed the three position switch on the actuator, you can see the label which says 24VAC. I've had two different brands of valve actuators and two different brands of heaters over the years that worked with the old controller board. That board provided 24VAC for each and there was no way to switch it to any other voltage, so I do believe 24VAC is normal for pool systems.

    0
    None
    nessiemack

    2 months ago

    Hello. Thanks for the well written instructable. I was able to download the PoolControl.ino file but not the PoolControlFlow file. I've tried a couple times and I have received a "Failed - Forbidden" message on the download each time. I am even logged in to the instructables webste. Any suggestions? Do you have the files on github by chance? I've been wanting to replace the failing controller in my hottub and thought that your project might be a good starting point. I would probably just use a single RPi and some DS 18B20 1-wire sensors for temp inputs. The RPi works well driving the relay boards and the temp sensors as I've done that on a home tstat project already. Thanks.

    3 replies
    0
    None
    neilroethnessiemack

    Reply 2 months ago

    Hi, nessiemack.

    Thank you for the nice comment and for alerting me to the problem. I renamed the file PoolControlFlow.txt which allowed me to download it without error. Can you try again?

    I chose to use the RPi/Arduino combo for two reasons: (1) I wanted the RPi inside and using an Arduino meant I could run a single serial cable from the RPi to it rather than a bunch of wires for the seven relays and two thermistors, and (2) I wanted to use analog thermistors and the Arduino has built in analog inputs, but using a digital temp sensor directly with an RPi should work just as well!

    0
    None
    nessiemackneilroeth

    Reply 2 months ago

    Hello again. You are quite welcome and thanks to you for fixing the file. I was able to get it just fine now. I understand why you used the RP1/arduino combo for your project. My hottub controller will all be inside the large cabinet area around my hottub so I can more consolidate my components in one area. Did you use an actual USB cable between the RPi and the arduino or an RS-232 serial type connection? The USB is rather limited on the length of the run but the RS-232 can go quite a distance. Thankis again.

    0
    None
    neilroethnessiemack

    Reply 2 months ago

    I did use an actual USB cable and you are absolutely correct about the length limitation. The maximum is about 16ft and I have a 15ft cable. An alternative would be to use the serial pins on the Arduino for serial communication; I ran an extra cable which I could use for that purpose.