loading

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
GND to GND

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
Type:

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
Type:

  sudo apt-get update 


Then:

 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: http://raspipress.com/2012/09/tutorial-install-ph...


Install GPIO

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

To get the DS18B20 sensors working use the follow commands:

Type:

 sudo nano /boot/config.txt


Add the following line

dtoverlay=w1-gpio

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

sudo nano /etc/modules 

Add these 2 lines at the and:
w1-gpio
w1-therm

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:
www-data ALL=(ALL) NOPASSWD: ALL

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 - "http://127.0.0.1/cron_jobs/cron_min.php?auth=Gdw34zXrFHYDe" 1,11,21,31,41,51 * * * * wget -q -O - "http://127.0.0.1/cron_jobs/cron_10minutes.php?auth=Gdw34zXrFHYDe"

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

<p>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...</p>
<p>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&deg;. In the tablet layout it says 18.4&deg; and not changing over time.</p><p>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.</p><p>Mooi werk, Rickiewickie</p>
<p>just the GPIO 4 for the data wire. Do you have a resistance of 4.7K over the power and data wires? <br><br>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.<br><br>The 18.4 what you are seeing is a value from the database -&gt; 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.</p><p> I've you cant get it work, send me a personal message so i can help further.<br><br>Bedankt ! <br> </p>
<p>Yo Rickie,</p><p>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 ...</p><p>Did some research and found out that the address is hardcoded into the sensor <br></p><p><a href="http://www.reuk.co.uk/wordpress/raspberry-pi/ds18b20-temperature-sensor-with-raspberry-pi/" rel="nofollow">http://www.reuk.co.uk/wordpress/raspberry-pi/ds18b20-temperature-sensor-with-raspberry-pi/</a></p><p><br> And to connect multiple sensors : </p><p><a href="http://www.reuk.co.uk/wordpress/raspberry-pi/connect-multiple-temperature-sensors-with-raspberry-pi/" rel="nofollow">http://www.reuk.co.uk/wordpress/raspberry-pi/connect-multiple-temperature-sensors-with-raspberry-pi/</a></p><p>Didn't know about the scan option.<br>And yes, I used the resistor. Never doubt the teacher :)</p><p>I did the scan and named my sensor. I have a reading in the normal view <br>but now no reading in the tablet view. Just the degrees symbol. Can I <br>change which sensor I like to see in the tablet view?</p><p>Would like to dive right now into my hot tub (self made)</p><p>Bedankt (Thanks)</p>
<p>Hi Mario,</p><p>Your right, let's stay public!</p><p>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 &quot;Mid Column (Hottub Temp.)&quot; and this will be the same sensor for your tablet page.</p><p>Let me now is this worked for you!</p><p>Regards,</p>
<p>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. </p>
<p>Thats it not the directory the files are stored.<br>Go to /var/www/html/cron_jobs , here are the files stored.<br><br>To verify login as root in the terminal (activate root when not activated)</p><p>Or login as pi and type &quot;passwd root&quot; and give root another password.<br>When logged in as root type &quot;nano /var/spool/cron/crontabs/root&quot; </p><p>At the bottom you should at least see the following text:<br><br>* * * * * wget -q -O - &quot;http://127.0.0.1/cron_jobs/cron_min.php&quot;</p>
<p>Finally it works.</p><p>Using Filezilla you can't just see the files in the spool/cron ... directorie. That's why I was confused.</p><p>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.</p><p>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.</p><p>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.</p><p>Never the less this is a very great project and you were very helpfull. Keep up the good jobs.</p><p>I love dutch people. Sometimes :) Most greetings from Flanders</p>
<p>You can edit the files with Filezilla. <br>Log in as Pi , set root password &quot;sudo passwd root&quot; change to whatever you want. <br>Go to FileZilla , login as root with your password on port 22 !<br>Then you should be able to change the files.. <br><br>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.<br><br>Changing the colors can be done in 2 ways. <br>1) Replace the icon &quot;poweron.png / poweroff.png&quot; to every icon you may like.<br><br>2) Change to source code of controller.php. This file can be found in /files/control/controller.php. Change line 181 and 182 </p><p>When you finished your project, please upload your project. I am curious :)</p>
<p>I did it. And here is how:</p><p>I have changed some images in the images directory. Two of them I just swapped the name. poweron.img and poweroff.img.<br>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.<br>I've made in the logged.css file two new classes. Namely red-circle and green_circle. Just a copy of the<br>pump_circle class but another backgroundcolor.<br>And finally I added to the controller.php file in files/control a if statement to check the status of the according<br>pins and draw the corresponding circle. Off=red. On=green.</p><p>If you like I can send you the logged.css and controller.php Rick Feenstra ;)to compare with the originals.</p><p>Do<br> remember I have no skills or what so ever to make html or interactive <br>sites. Just figured this out in a few hours. I do have knowledge of <br>programming :)</p>
<p>Godverd... :)</p><p>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 :)</p><p>The icons are changed, now the filling of the circles. I'll keep you posted.</p><p>Enjoy your Sunday</p>
<p>The cause is the temperature is not written to the database.</p><p>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 :(</p><p>I will compare all files in the html map. Maybe I'll missed one up during configuration.</p>
<p>If the temperature is not writtin in the database, then the cronjob (cron_min.php) ain't working properly.<br><br>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)</p>
<p>Hi! Absolutely amazing project! Great work!</p><p>Is it possible to <br>add another sensor via simple GPIO IN? I habe a sensor for the water <br>level that simply is closed when enough water and open if water level <br>too low.</p><p>Would be great if cloud add a device control like:</p><p>If &quot;water level&quot; = off don't allow pump or heater to turn on</p><p>Would this be possible?</p>
<p>This could be possible. But there should be a option to disable this because not everyone will use this function.</p><p>Step 1: Level Control : On/Off<br>Step 2: When level control is ON and the GPIO IN is high/low(configurable) pump and heater control should go ON/OFF (configurable) </p><p>Sounds logical? </p>
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 (&quot;Standby mode&quot;).
<p>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.</p>
<p>Excellent project... </p><p>Looking to do the same with an older 3 man tub, everything is in working order, except for the original control box. </p><p>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?<br></p>
Thanks!<br><br>Good to hear that everything is working fine!.<br><br>For the temperature sensors i used pneumatic parts (see enclosed picture) . I through it was a 8 mm to 1/2 threaded.<br><br>And fixed this parts in the plumbing with a PVC part from 1/2 to a glue connection.<br><br>Hope this will help you.<br><br>Regards,
<p>Thanks, I see the fitting now.. Funny, since I use similar system for my misting system..</p><p>Have you looked into adding external controls(ie, pump toggle)</p>
<p>See attachted parts</p>
<p>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?</p>
Go to PhpMyAdmin -&gt; Table Config , set tablet_view from 0 to 1.<br><br>Soon i will release a new version with a few bug fixes / updates.<br>I'am trying to get a push notification when required. <br><br>Any other idea's ?
<p>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! </p>
<p>1) Are cronjobs enabled / installed correct?</p><p>2) The cronjob will run once per 60 seconds. </p><p>So when you turn on the heater, it could take up to 60 seconds before the pump goes on in you're case. <br>About the Time Schedule, it must be in 24 hours format , see attachment.</p><p>Perhaps when you have more issue's reinstall or download the complete image</p>
<p>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... &quot;Someone tried to run a cronjob. From ip:127.0.0.1&quot; </p>
<p>* * * * * wget -q -O - &quot;http://127.0.0.1/cron_jobs/cron_min.php?auth=Gdw34zXrFHYDe&quot; 1,11,21,31,41,51</p><p>The auth. code seems to be different then you have in you're config. </p><p>1) You have changed the &quot;token&quot; in Configuration -&gt; General . In that case the cronjob rule above should be different.</p><p>2) Like you told me that you missed the config table previous time, so the token field is empty. Changed it to &quot; Gdw34zXrFHYDe &quot;</p><p>Then it should work.</p><p>------<br>Perhaps it could make a new image when it still doesn't work</p>
<p>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?</p>
<p>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. <br>Any other options for the controller?</p>
<p>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!</p>
<p>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?</p>
<p>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</p>
<p>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. </p>
awesome work
<p>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!</p>
<p>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. </p>
<p>Hi , </p><p>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? </p><p>Regards Jon</p>
<p>Hi Jon,</p><p>Thanks!</p><p>Sounds like a good option. I will have a look this weekend what the options are.</p><p>Regards,<br>Rick</p>
<p>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.</p>
<p>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. </p>
<p>See surrounded circles in blue to add the relay pins on.</p><p>For the DS18B20 sensors connect this one to the GPIO 4 (green arrow pin 7)</p><p>Hope this would be more clear.</p>
<p>PM sent.</p>
<p>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!</p>
<p>Are the &quot;pins&quot; pdf for this project for the Raspberry 3 B+ also?</p><p>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?</p>
<p>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?</p><p>Thanks again</p>
<p>Hi perfoliate,</p><p>Good to hear and that i made other people happy with my project :). <br>For any questions related to this project you can contact me any time!</p>
Hi Rickie, first of all thanks so much for this posting. I have a couple of questions:<br><br>- I see you have an API option - what is its purpose? Can you move the Webserver to the cloud so you don't have to be logging onto the local Webserver (I.e. When not at home)?
<p>Hi csepp1,</p><p>I'm using weaved online service to connect from my cell phone or remote computer.</p><p><a href="https://www.weaved.com/raspberry-pi-remote-connection/" rel="nofollow">https://www.weaved.com/raspberry-pi-remote-connect...</a></p><p>It works surprisingly well and look forward to fireing up my hot tub this winter as i'm heading home. I did have to put a link on the log-on page to the tablet page since it won't let me connect to sub pages.</p>
<p>Hi Csepp1,</p><p>The API option is to control you're hottub with another program. For example; Connect to a api with any other software and set you're hottb on/off or set temperature etc. </p><p>The hottub controller can not connect to the cloud. You only could connect to the webserver and login. The tablet page can be set without a login ( you must approve a IP adres for this ) </p>
Second question is: any way you include date stamp for the schedule of the I/Os? I think currently it is limited to hours and minutes. Reason for me asking is - I have a hot tub on a remote island and I am renting out the home on Airbnb. We are already using a smart lock which is hooked up with Airbnb (August). Idea would be to warm up the hot tub remotely for days when guests are arriving. Any chance we can hook up your controller with Apple Home Kit? Thanks so much,<br><br>Chris

About This Instructable

2,607views

25favorites

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