Hot Tub / Pool Controller Web Interface





Introduction: Hot Tub / Pool Controller Web Interface

The ulimate webbased hottub / pool controller.

Step 1: Step 1: Intro

About 2 years ago i bought myself a raspberry pi and just playing around with it.. After a while i decided to make something useful instead of playing around with it.. So i decided to make a hottub controller with it. I'am running the controller over a year now and decided to share it with you :)

For all the functions see:

So in this tutorial we will see how to make a hottob / pool controller.

The controller is written in PHP with GPIO control

The following packages should be installed.
- Apache 2
- PHP5
- MySQL Database
- PhpMyAdmin
- GPIO Control

In case you don't want to install everything. You can download and install my Image / OS.
You can download my raspbian image HERE

Version 1.1 is available -> installed on raspbian jessie lite and updated a few bugs.
Download the image 1.1 HERE

Needed Hardware:
- Raspberry PI
- SD card ( 8 GB )
- 5V 4 Channel Relay Module ( or 8 channel is you wish )
- DS18B20 Temperature Sensors - Waterproof.
- Jumper Wires.

Step 2: STEP 2: Hardware Setup

Connect the DS18B20 sensors
Red Wire --> To 3.3v
Black Wire--> GND
Grew Wire (Data) --> GPIO pin 4
Also see Attachment

Contact the relai block as follow:
5v to 5v

See Attachment PDF for the right pin no. (or board overview, blue circles)

Pin 1 (relay) to WiringPi Pin 8
Pin 2 (relay) to WiringPi Pin 9
Pin 3 (relay) to WiringPi Pin 2
Pin 4 (relay) to WiringPi Pin 3

Be Aware ! The relay can switch a maximum of 10A

Step 3: Steps 3: Installing OS

First we will install a new fresh image of raspian.

I installed RASPBIAN JESSIE LITE, because we don't need all other stuff like desktop environment. But all other Raspian versions should be fine as well.

Flash your selected image with Win32DiskManager to the SD Card

Step 4: STEP 4: Install Packages

Download the program "putty" and "advanced port scanner" (both free software).

Scan with "advanced port scanner" and find your raspberry pi IP adress.

Go to Putty insert the IP of the raspberry and login with user "Pi" and password "raspberry".

First we need to expend filesysteem

sudo raspi-config 

Select expend file system en finish installation. The raspberry will restart now.

Wait a minute and connect again with putty to the raspberry and login.

Second we will update the PI

  sudo apt-get update 


 sudo apt-get upgrade 

Type "Y" to update (and upgrade the pi as necessary)

Install Apache2 with the following command:

sudo apt-get install apache2 

Install PHP5

sudo apt-get install php5 libapache2-mod-php5 -y 

Install MySQL

 sudo apt-get install mysql-server 

During installing mysql-server will ask for a password. This is to connect to the mysql server.. choose a password anything you like.. But don't forget this password. Write it down somewhere!! ( i choose "raspberry" )

Install PhpMyAdmin

sudo apt-get install phpmyadmin

Configure Apache to work with PhpMyAdmin

sudo nano /etc/apache2/apache2.conf <br>

Add the following line at the end of apache2.conf:
Include /etc/phpmyadmin/apache.conf
Control + X to save, type "Y" to overwrite.
Also See:

Install GPIO

sudo apt-get install git-core <br>
git clone git://<br>cd wiringPi<br>./build

To get the DS18B20 sensors working use the follow commands:


 sudo nano /boot/config.txt

Add the following line


Control + X to save, type "Y" to overwrite.

sudo nano /etc/modules 

Add these 2 lines at the and:

Control + X to save, type "Y" to overwrite.

run the gpio command to check the installation: <br><br>gpio -v <br>gpio readall

Yeah finally all packages installed :)

Step 5: Step 5: Setting Up Scripts...

Before we can upload the files to the raspberry we need to change a few settings

Add the pi user to the group
type: sudo gpasswd -a pi www-data
Change the group for the directory and allow the pi user to update the directory
type: sudo chown www-data:www-data /var/www
type: sudo chmod 775 /var/www

I've you have downloaded debian jessie you need to change the root directory of apache.
type: sudo nano /etc/apache2/sites-available/000-default.conf
Change /var/www/html to /var/www CTRL + X to save "Y" to overwrite.

To have access to control GPIO pins with a webpage.

Type: sudo visudo
Add this line to the end of the file:

Press CTRL + X to save and exit.

Download all the files from here

Download the program Filezilla Client (or other FTP program )
Connect to you're raspberry pi with following details:
SFTP://IpOfYourPi ( port 22 )
User: pi
Password: raspberry

Upload the files to /var/www ( - Just type /var/www in the right screen. )

In case you have another mysql password then "raspberry" you need to change to php configuration of the controller:
Edit the config.php file.
Change mysql_pass to the right password you have set during mysql-server installation.

Next step is to import the SQL file in the database.

Go to http://IP-Raspberry/phpmyadmin
Login with root and you're password (raspberry default)
Add a database with the name "controller"

Click on controller in the left area of the page and then click Import.
Select controller.sql from all controller files and upload by pressing start.

Setting up Cronjobs
type: crontab -e
Add this text to the end of the file.

* * * * * wget -q -O - "" 1,11,21,31,41,51 * * * * wget -q -O - ""

CTRL + X to save. Done !

Step 6: Step 6: Controller Page

Go to: http://raspberryIP

Welcome to the login screen :)..

Login with username: admin password: 123456

There is also a tablet page. special writtin for my tablet :).
See http://raspberryIP/tablet

4 People Made This Project!


  • Epilog Challenge 9

    Epilog Challenge 9
  • Paper Contest 2018

    Paper Contest 2018
  • First Time Author Contest 2018

    First Time Author Contest 2018

We have a be nice policy.
Please be positive and constructive.


3 Questions

On the install PHP5 step I am getting a message that says the package is not available but is referred to by another package. What might that be


this is by far the best home built tub control interface I've seen on the net. Well done!

My setup is a bit different, and i'd like to incorporate your interface. I'd using Sonoff relay switches that control a propane based system for my tub. They use the Mosquitto (MQTT) to control the various switches (pump/heater/temp sensor etc..) all either are low voltage or 110v. My guess is it is fairly trivial to replace MQTT calls in place of the GPIOs. If you're not familiar with MQTT , it's essentially a lightweight IoT protocol that publishes on/off signals to discrete devices. Super simple, and my guess is it can be inserted into your code to control any number of network enabled switches.

Could you give me a hint as to where to start? and what I might need to touch in your code, aside from installing MQTT.

Thanks for all the work so far!

I am familiar with MQTT , i use it for my other home automation.

But to integrate MQTT in the hottub controller you need to add a additional code in the functions.php file at the function "WritePin"
How do you want to publish to MQTT then? And with which other system do you want to cooperate?

Btw: There is already an API to control the hottub controller.


How do you download the links above? They both do not work for me.

My server went offline. But it should work again


Hi Rick,

I just used this tutorial and setup to build my own controller instead of buying a new circuit board from the manufacturer. Thanks for the great setup and image file.

I am having some problems while using the automatic heater control. For some reason, after my temperature gets within the requirement, the heater shuts off (as it should) but the pump remains on. Can you think of anything that would cause this?

Well I might have spoken too soon. I logged into the php myadmin page and switched the pump controller setting to on. Seems to be working now.

Hi Adam,
Go to hear that you got it working!
Enjoy the controller :)

Hi Rick,

i'll do it in English but i'm Dutch. Ik will post some pictures of my installation later. For now i want to ak you if it is posssible for you to build in a timed option in the controller? I would like the controller to keep the pool on temperature espacially in the night when it is cheap power (daltarief ;)) So

You know how the script is build so it should be easier for you than for me. First have to find out how it's build.


I need help on the fitting to pipe it into the water. I see in your pic you got a fitting and threaded it into a threaded cap. Can you send me information on the silver fitting? Where you got it? Thank you! Nice work... I'm still developing on mine...

Hello. Mine is still in progress. I have other projects with higher priority. But what I'm gonna use is a pipe fitting with cutting ring of 6 mm on one side and a thread of 3/8" on the other side. What I need to do first is to drill with a bit of 6mm through the fitting.

Or you can use epoxy.


Hello, I have reversed state of control... Why? I have RPI 3.

When I turn on then gpio read pin has value 0, when I turn off then gpio read pin has value 1 and then is turned relay.

Thank for your reply.

Hello, When you put a device on, does it goes on or off?
You can change the state control in the file functions.php if you want to change it.

When I put device on it goes to off. I set it on functions and on cron and other files... many many changes... It is really good functionallity with key press buttons... I'll programming it maybe...

Hi! Absolutely amazing project! Great work!

Is it possible to
add another sensor via simple GPIO IN? I habe a sensor for the water
level that simply is closed when enough water and open if water level
too low.

Would be great if cloud add a device control like:

If "water level" = off don't allow pump or heater to turn on

Would this be possible?