Introduction: Hot Tub / Pool Controller Web Interface

Picture of Hot Tub / Pool Controller  Web Interface

The ulimate webbased hottub / pool controller.

Step 1: Step 1: Intro

Picture of 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

Picture of 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

Picture of 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...

Picture of 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

Picture of 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


Sahipool (author)2017-09-07

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.


thedawnsc (author)2017-04-02

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...

MarioA53 (author)thedawnsc2017-06-01

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.

MilošH10 (author)2017-05-04

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.

Rickiewickie (author)MilošH102017-05-16

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.

MilošH10 (author)Rickiewickie2017-05-19

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...

MarioA53 (author)2017-02-14

Great. It's working. Almost. The only problem for me are the sensors. Right now I use only one. But I'm not sure which pin to use. In the example the sensor is connected to pin 7 or GPIO4. It doens't work for me. In the normal layout the reading is 9999°. In the tablet layout it says 18.4° and not changing over time.

I am using a Pi b model. Which pin should I use? And if I add other sensors to it what are the corresponding pins.

Mooi werk, Rickiewickie

Rickiewickie (author)MarioA532017-02-16

just the GPIO 4 for the data wire. Do you have a resistance of 4.7K over the power and data wires?

Sensor reading 9999 will tell you that the sensor can't be found. Remove the sensor from the software click again on the scan option (in the sensor menu). When a sensor appears, the sensor is found a can be added.

The 18.4 what you are seeing is a value from the database -> The tablet page has a delay of 1 minute to avoid load from this page. On the sensor page it is real time data. So when your sensors i connected right i should give a temperature.

I've you cant get it work, send me a personal message so i can help further.

Bedankt !

MarioA53 (author)Rickiewickie2017-02-16

Yo Rickie,

Personal messages ain't helping others if they have the same issue. I learn a lot by these comments and if I can help others by staying public ...

Did some research and found out that the address is hardcoded into the sensor

And to connect multiple sensors :

Didn't know about the scan option.
And yes, I used the resistor. Never doubt the teacher :)

I did the scan and named my sensor. I have a reading in the normal view
but now no reading in the tablet view. Just the degrees symbol. Can I
change which sensor I like to see in the tablet view?

Would like to dive right now into my hot tub (self made)

Bedankt (Thanks)

Rickiewickie (author)MarioA532017-02-17

Hi Mario,

Your right, let's stay public!

To get the right sensor visible in the tablet page, login into the webapp and on this main screen you will see a edit option (See Attachment). Edit the "Mid Column (Hottub Temp.)" and this will be the same sensor for your tablet page.

Let me now is this worked for you!


MarioA53 (author)Rickiewickie2017-02-18

I manually changed the temp value in the database and now I have a reading. Somehow the cronjobs are not executed. If I look at your image in the var/spool/cron/crontabs I have 2 files. contrab and root. On mine no files at all. Tried to copy them but access denied.

Rickiewickie (author)MarioA532017-02-18

Thats it not the directory the files are stored.
Go to /var/www/html/cron_jobs , here are the files stored.

To verify login as root in the terminal (activate root when not activated)

Or login as pi and type "passwd root" and give root another password.
When logged in as root type "nano /var/spool/cron/crontabs/root"

At the bottom you should at least see the following text:

* * * * * wget -q -O - ""

MarioA53 (author)Rickiewickie2017-02-18

Finally it works.

Using Filezilla you can't just see the files in the spool/cron ... directorie. That's why I was confused.

I opened for the 100th time :) the crontab. Checked again and saw that in step 5 - setting up crontabs - you added the auth code to the lines. And in the comment here above not. So I removed it. And there was also one syntax error.

You can ask why going trough all this trouble and not using the image b'cause it works? Yes its works. Great. But I wanted to change the icons on/off and access was denied using the image. So I had to make one following your steps. And changed the icons.

Why changing the icons? I am a mecanical maintenance engineer. And on each control cabinet in our factory a green light means the corresponding process is on. And red is off. Also I want to figure out how to change to color of the circles. Instead of the text 'on' I like to have a green filled circle or when off red.

Never the less this is a very great project and you were very helpfull. Keep up the good jobs.

I love dutch people. Sometimes :) Most greetings from Flanders

Rickiewickie (author)MarioA532017-02-18

You can edit the files with Filezilla.
Log in as Pi , set root password "sudo passwd root" change to whatever you want.
Go to FileZilla , login as root with your password on port 22 !
Then you should be able to change the files..

In version 1.1 you don't need the auth code anymore. This only for version 1.0. . Thanks of reminding me on it. I should change it in the tutorial.

Changing the colors can be done in 2 ways.
1) Replace the icon "poweron.png / poweroff.png" to every icon you may like.

2) Change to source code of controller.php. This file can be found in /files/control/controller.php. Change line 181 and 182

When you finished your project, please upload your project. I am curious :)

MarioA53 made it! (author)Rickiewickie2017-02-22

I did it. And here is how:

I have changed some images in the images directory. Two of them I just swapped the name. poweron.img and poweroff.img.
The images check_off.png and check_off1.png I colored red. And the check_on.img and check_on1.img became green for the tablet.
I've made in the logged.css file two new classes. Namely red-circle and green_circle. Just a copy of the
pump_circle class but another backgroundcolor.
And finally I added to the controller.php file in files/control a if statement to check the status of the according
pins and draw the corresponding circle. Off=red. On=green.

If you like I can send you the logged.css and controller.php Rick Feenstra ;)to compare with the originals.

remember I have no skills or what so ever to make html or interactive
sites. Just figured this out in a few hours. I do have knowledge of
programming :)

MarioA53 (author)Rickiewickie2017-02-19

Godverd... :)

When I did a reboot my Pi had trouble finding the kernel. Had to do the hole cycle all over again. But with new knowledge it went smoothly :)

The icons are changed, now the filling of the circles. I'll keep you posted.

Enjoy your Sunday

MarioA53 (author)MarioA532017-02-16

The cause is the temperature is not written to the database.

I have two SD cards. One with your image installed and one I created myself following your steps. The first one works ok. Mine not all the way :(

I will compare all files in the html map. Maybe I'll missed one up during configuration.

Rickiewickie (author)MarioA532017-02-17

If the temperature is not writtin in the database, then the cronjob (cron_min.php) ain't working properly.

In the provided sd card image it should work, this is a one on one copy of my controller. You only need to set the right sensors then (as discussed above)

matthiaskind (author)2016-12-09

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?

This could be possible. But there should be a option to disable this because not everyone will use this function.

Step 1: Level Control : On/Off
Step 2: When level control is ON and the GPIO IN is high/low(configurable) pump and heater control should go ON/OFF (configurable)

Sounds logical?

Yes, sounds good. Another good option would be a general On/Off switch that turns all devices off and overrides the automatic controls without the need to turn off the whole raspi ("Standby mode").

Last time i was not able to work on my project. But a standby mode is already in place, it is called cleaning mode. This will disable all automatic comtrols. Perhaps i should rename it.

MattD177 (author)2017-01-14

Excellent project...

Looking to do the same with an older 3 man tub, everything is in working order, except for the original control box.

I see from the pictures that you have the temperature probe in the plumbing. I haven't seen any fittings that would hold this. How did you manage to accomplish this?

Rickiewickie (author)MattD1772017-01-14


Good to hear that everything is working fine!.

For the temperature sensors i used pneumatic parts (see enclosed picture) . I through it was a 8 mm to 1/2 threaded.

And fixed this parts in the plumbing with a PVC part from 1/2 to a glue connection.

Hope this will help you.


MattD177 (author)Rickiewickie2017-01-15

Thanks, I see the fitting now.. Funny, since I use similar system for my misting system..

Have you looked into adding external controls(ie, pump toggle)

See attachted parts

RyanD148 (author)2016-07-13

Thank you for this! So I have everything working except I am not able to change settings like Tablet view: Off I change it to On and press enter, it says it saves but I go back and it didn't change it... any advice?

Rickiewickie (author)RyanD1482016-07-14

Go to PhpMyAdmin -> Table Config , set tablet_view from 0 to 1.

Soon i will release a new version with a few bug fixes / updates.
I'am trying to get a push notification when required.

Any other idea's ?

RyanD148 (author)Rickiewickie2016-07-14

Another little issue I've been having. I've been playing with the Automatic Device Control and can't get it to work. Let's say when my heater comes on I want my pump to come on. So I add that all in under the automatic device control tab. I click the manual heater button on and that relay changes state but my pump relay doesn't.... any advice? I've also can't seem to get the time schedule to actual change relay states. Otherwise I love what you have done! I haven't actually got it wired to the tub yet but can't wait!

Rickiewickie (author)RyanD1482016-07-15

1) Are cronjobs enabled / installed correct?

2) The cronjob will run once per 60 seconds.

So when you turn on the heater, it could take up to 60 seconds before the pump goes on in you're case.
About the Time Schedule, it must be in 24 hours format , see attachment.

Perhaps when you have more issue's reinstall or download the complete image

RyanD148 (author)Rickiewickie2016-07-15

Yeah I did a fresh install with your image file. Waited the 60 sec like you said still nothing... In the log tab I have this listed every minute... "Someone tried to run a cronjob. From ip:"

Rickiewickie (author)RyanD1482016-07-16

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

The auth. code seems to be different then you have in you're config.

1) You have changed the "token" in Configuration -> General . In that case the cronjob rule above should be different.

2) Like you told me that you missed the config table previous time, so the token field is empty. Changed it to " Gdw34zXrFHYDe "

Then it should work.

Perhaps it could make a new image when it still doesn't work

RyanD148 (author)Rickiewickie2016-07-16

Yeah it was different! It was Gdw34^%FHYDe... But yeah i changed it to Gdw34zXrFHYDe and everything works perfectly! Thanks for your help man. So you have any other features your thinking of adding?

Rickiewickie (author)RyanD1482016-07-17

I'm working on push notifications for you're phone. For example when hottub water is getting to hot i will get a push notification.
Any other options for the controller?

RyanD148 made it! (author)Rickiewickie2016-07-18

Okay yeah that would be neat. I can't think of anything else it needs. You got everything you need in there! Anyway here's a picture of my creation! Hope yeah like!

RyanD148 made it! (author)RyanD1482016-07-19

Hey I can't see any temperatures in tablet mode. It shows my sensor but no temp. In the regular website view (non tablet mode) I can see my temperatures. Any thoughts?

RyanD148 (author)RyanD1482016-07-19

One more question! :) I have a two speed motor. When the heating element comes on I have the low speed of the pump come on. But say I'm sitting in the hot tub and I want the high speed to come on so I enable my high speed relay, but it takes 60 sec for my low speed to kick out because I have my automatic device control settings to shut of my low speed if my high speed kicks in. Can I change that to scan every 1 second instead of 60 seconds... Reason being I don't want my low speed and high speed winding of my pump running at the same time for any amount of time

MattD177 (author)RyanD1482017-01-15

I know this is a little late... You could use a STDP Relay for your High/Low speed changing. When the relay is energized, the pump is in High Speed, de-energized it is in Low Speed. Most hot tubs use a Contactor for this job, in tandem with the heater(usually off when in High Speed). A Contactor is just a High Current Relay. I've found it to actually be cheaper to use 2 relays and use the low current relay to swap them, That way the high speed will alway kick in with out the low speed. I think this also makes a little sense for replacing of failed parts, easy to troubleshoot too.

jimburnsinc (author)RyanD1482016-08-08

awesome work

RyanD148 (author)RyanD1482016-07-14

Oh and I got tablet mode working thank you! I actually had to add it to the config table... it wasn't there. But it works now!

death__hound made it! (author)2016-12-07

awesome project it works so well only thing i had to change was the the heater control as i use solar array on my roof so has to pump when roof is hotter then pool but lower then setpoint . by the way the author seems top notch and cant wait to see how this awesome device evolves.

death__hound (author)2016-11-25

Hi ,

Awesome Project and great build. I'm going home to build one for my pool this weekend. One question , if i wanted to add inputs ie... switches to turn pump on manually from RPI input could that be achieved?

Regards Jon

Hi Jon,


Sounds like a good option. I will have a look this weekend what the options are.


thanks for having a look. was even thinking if we could apply logic to those inputs we could manage water leveles and stuff this would be the ultimate pool/ hot tub controller.

jcrandall1 (author)2016-11-25

This is a great instructable. What makes this even more great is that Rickie is very supportive with your questions with quick, pin point accuracy. He is a busy guy though. He sounds very motivated to help others as I am also. I look forward to further communication with him on other projects.

Rickiewickie (author)2016-11-14

See surrounded circles in blue to add the relay pins on.

For the DS18B20 sensors connect this one to the GPIO 4 (green arrow pin 7)

Hope this would be more clear.

jcrandall1 (author)Rickiewickie2016-11-16

PM sent.

jcrandall1 (author)2016-11-16

I actually was referring to the relay wiring configuration. I'm loving this so far. I finally got your image 1.1 installed and running I believe. I purchased everything just for this project. I can't wait to get it running cuz my back is killing me. Great instructable! YAY!

jcrandall1 (author)2016-11-13

Are the "pins" pdf for this project for the Raspberry 3 B+ also?

I'm a bit lost when reading the instructions because it doesn't identify the pins as to what I am understanding. So Pin 1 (on the relay) is connected to which pin on the GPIO? GPIO pin 8 as in counting from j1 to j2 ,j1 being pin one and j 2 being pin 2? If so that puts me at GPIO14 (4th down on the right)..... Yes I am confused.... Sorry, can you help me understand?

perfoliate (author)2016-11-01

This is exactly what I'm looking for. Thanks for this. I will be getting some components and getting to work. Are you still on the board for questions if they come up?

Thanks again

About This Instructable



More by Rickiewickie:Hot tub / Pool Controller  Web interface
Add instructable to: