Hot Tub Controller

So, I have to tell you about the hot tub project. It’s been going on for a few weeks now and we just basically finished it. I (with some help from Jesse) have set up a microcontroller to control and monitor the hot tub. We have a temperature sensor mounted on the heating element tube and we wired in a relay to control when the heater turn on. Then we wrote code to allow it to interface with email, the internet, and even text messages! For real. Look:

Text message from the hot tub
Text message from the hot tub

Haha! Here are some more gems:

Temperature plotsand you can control it with this form:

control_formOr you can just control it from the command line:

terminalSo here’s what’s going on. Firstly, there’s an arduino connected to a USB port of the computer in the basement. Here’s a pic:

ArduinoOne of the digital pins on the Arduino is connected to a OneWire bus with three temperature sensors hooked up to it with a pull-down resistor connecting the bus to the 5V line. That’s the green wire. The ground is white ground.  The three sensors are hooked up (in parasite power mode) to 30 feet of indoor/outdoor CAT-5 wire from Home Depot. I surrounded each temperature sensor with a piece of 3/8″ O.D. copper tubing (which is miraculously already corroding) and pinched them down and sealed them up with Silicone. Here’s a pic of the outdoor sensor.

Outdoor temp sensor in copper

Anyway, yeah. The last sensor, the one on the tub, is wrapped in lots of insulation from the hardware store to try to keep the outdoor temperature from affecting the hot tub readings.

On another digital pin (the orange wire), we have a relay circuit that we can turn on and off easily. In the hot tub, it connects the wire that connects the coil of the main heater relay. So it’s  a relay for a relay, effectively. We just set the temperature dial very high and use the Arduino to cut it off when we want. We got the circuit from here. Here’s a copy of that:

schematic

Nice. I used a relay that can handle up to 30A, 240V, with a 12V coil. I got the 12V by splicing off of the hard drive power cable inside the computer (blue wire, with white blue as ground. That’s the same ground, but we didn’t want to tap into the fragile cat5 wire again). That’s unfortunate because it requires the computer be on to have the heater on. A better design would not rely on the computer to maintain control of the hot tub.

The rest of it is just software. I’m using the pySerial module to read and write to the USB tty device in 32-bit Ubuntu 8.10 Linux. The code that I compiled on the Arduino chip simply accepts simple characters through the serial port and does as asked. It knows how to turn heater on, off, read temperatures, and tell whether or not the heater is on. I’ll build some safety logic in soon. Right now, all the control logic and communication is done in Python on the computer. I have an Arduino class that abstracts the commands the Arduino knows. Then there’s the hottubController class that checks the sensors and turns the heat on and off accordingly. It calls the communication class, that checks for commands in an IMAP email account, submits temperature information to a MySQL database on my server, and sends command responses via SMTP. The text messaging functionality works simply because you can easily use the text-to-email gateways used by many major phone companies. The MySQL stuff is done with the MySQLdb python module, which is fairly simple.

The web form is a python cgi that makes that simple HTML table and sends the commands in. The plotter is another python script that reads the database and puts the data into an HTML file, which is then parsed by the flot JavaScript plotting routines on the clientside, allowing zooming and dynamic date x-axis labels, which are awesome.

Still to come: predictive hot tub times. Since the heating is very linear, it’s possible to extrapolate the time at which the tub will reach a given temperature. You’ll get a text that says: “the hot tub will be ready at 10:37PM” How cool will that be at the bar?

With all the copper, casings, arduino, sensors, relays, silicone, insulation, and various other tools I bought during this, it’s up to about $100, not including the computer. Not bad!

More Details

In case you’re wondering or debugging the hot tub controller, here are some more details.

The breadboard setup for the hot tub controller
The breadboard setup for the hot tub controller
Here's what the arduino wires look like. Nothing special.
Here's what the arduino wires look like. Nothing special.

Out at the hot tub, you’ll see a silver toggle switch. Under normal operation, this should be in the center position. To shut down special features and go back to plain-old hot tub, put the switch in the up position. This gives control of the hot tub back to its internal thermostat. It also disables the 10 second heater delay relay.

3 thoughts on “Hot Tub Controller”

  1. I am trying to do a similar project.

    can a SSR be driven straight from the Arduino Output?

    where did you get your relay and what type did you use?
    (DPST?)

  2. Hi Nick,

    Is it possible for you to share your code of the hottub controller?

    Thanks
    Ruben

    1. Great question. I can find the mess of Python code I used for this (it’s from when I was first learning so…not pretty) but I’m having a bit of trouble locating the arduino controller code that went with it. I’m sure I have it somewhere on some backup drive.

Leave a Reply to Ruben Cancel reply

Your email address will not be published. Required fields are marked *