Automated Pool Controller [NEEDS UPDATING: ALL GROOVY CODE IS OBSOLETE]

I did look at Particle’s Tinker app…is that the one or is there another one? That one didn’t have enough for the basic functions that I hoped to incorporate. We looked at Blynk and Cayenne as well.

After watching my son-in-law work a few sessions in the last few days, I have realized how much I have to learn. A simple one: Particles’ new desktop workbench (still in beta) based on Visual Studio Code makes code development for the photon easier, I wasn’t aware it existed. It’s really nice if you aren’t already using it!

My son-in-law has taken a liking to this pool project. He is a tinkerer like myself, but MUCH more capable. In addition to the google sheets interface to the Photon, he has created a pool app for Android that is tailored to my plans. He has forced me to make some interface decisions much earlier than I planned. My photon code plans are now waaay behind my front-end interface, haha.

Tinker is the default firmware on the photon and yeah you can use the app to control tinker but that’s not what I’m talking about. Just the particle app in the iOS store and for android too can also access your custom firmware it’s not just for tinker. It allows you to access your particle functions and send commands as well as see your particle variables. Here’s an example screenshot and requires no additional work at all and allows you simple access anywhere from your phone. Albeit not as aesthetic or user friendly.

Another Particle support tool I was not aware of, haha. That WOULD have done what I needed…I think I was too enthralled with writing the control code that I did not properly investigate all that was available. Thanks Brennon, that app is a really nice addition to the toolkit! I guess I need to take a day and see if I am missing anything else that is obvious (to others).

Brennon, how are your orp & ph readings going? That is something that really interests me. It seems that with enough data, someone could get the orp to work well…I guess it might depend on how closely the ph control works. But I realize this is probably not the time of year when this is debuggable/critical, my pool is mostly on autopilot when these cooler temps hit.

I haven’t deployed anything yet…I am sidetracked on the android phone app which is coming along pretty well. Also, the data tracking (fake sensor data at this point since the photon is still sitting on my desktop) to the google spreadsheet has been flawless…don’t know if you are able to track data using habitat/Smartthings in detail, but it seems that it might help in figuring out the orp.

@Jonpcar, I would be interested to see the ino code you’re using as well. My programming abilities are pretty limited, so I rely heavily on others’ code lol. I currently have my temperature sensors working and my laser distance for chlorine tank reading. Need to work on some of the functions utilizing the libraries that work with my NCD relay, but I have manual control of everything working with Home Assistant (in my mock-up). Are either of you doing filter pressure? I bought a pressure sensor, but need to work up a way to test it. I was thinking of some pvc with the ability to add air pressure via an air compressor, but haven’t done it yet.

1 Like

Lance, I actually haven’t worked on my photon code for over a month. I have two versions of .ino, neither of which is in a state that would be useful for anyone. One is the partially implemented code for the pool controller, the other is the fake interface to the google spreadsheet and to the Android app (which I have been spending all my time on).

I will gladly share when it is somewhat ready but I also believe that it is very specific to my desired setup. It is a schedule based design so that the photon can control my pool for weeks if necessary without a WiFi connection (not that it needs to work that long).

I am planning on 3, possibly 4, pressure gauges. I did test one by connecting it to my compressor. I expect to get information about my filter, the pump basket, and the skimmer through characterizing pressures and gpm. In addition, my In-Floor-Cleaning-System’s operation is very dependent on PSI at the manifold so one will be used for that purpose.

We are going to be gone for the next two weeks, and I still have probably a good month to finish my Android app after that (so that I don’t forget all the pointers and setup help I got from my son-in-law over Christmas ). As I said a couple times…my pace is possibly slower than a snail, but that is partially because we are currently watching our twin grandsons full time. But I will gladly share when i deploy the hardware, even though it will include only about 1/2 of what I eventually want. I still haven’t bought the etapes, partly because I haven’t decided what shaped container I will use for the acid.

I actually did put my Android studio code (for the pool control app) up on github, but took it all down when I realized my photon access “secrets” were hard coded into it, haha…pretty dumb. I still have a lot of learning to do. So sorry, sharing it is at least 6 weeks away.

Well I still haven’t gotten around to replacing the board I fried that I think I talked about somewhere above. It was my bad. I just had my board double sticky taped in there and it came off and shorted some pins. Fried one of my sensor boards I believe and the two non contact liquid chemical level sensors. I swapped the good sensor board to ph so I’ve had ph control and I haven’t gotten around to replacing orp yet. Although early tests did seem to show that I could at least see some useful data from the orp. Ive since 3d printed bumper Mounts for my boards in the box to prevent a future Mishap.
I’ve been working on dialing in the aggressiveness and logic for triggering an acid additions. I’ve gone through a couple of different renditions of code to handle that. I haven’t settled on the best. Other than my completely avoidable blunders above I’ve noticed I seem to have to calibrate my ph probe pretty often as it seems to drift pretty far after a few weeks. Perhaps I did some unknown damage to that with the above blunder. Or maybeI had unrealistic expectations about calibration frequency. If I have to It wouldnt be too hard to calibrate every few weeks as it’s an easy process. I’m not sure. I’ve just been keeping an eye on it for now. Also maybe related to the above I found I needed to program a semi auto approach to the chemical photons cloud connections since a failed cloud attempt can keep it hanging. I had what I speculate to be this exact problem happen and my chemical pump was triggered to come on for three minutes and ran for like 5hours… the ph of the pool plummeted. This could have caused my sensors drift too just being exposed to a strange environment. Luckily I noticed pretty quick and got some soda ash and borax in the pool to quickly bring it back in range. My theory is it got hung up trying to connect to cloud and when it does that it stops running the loop. So I have since added code that will interrupt any cloud connection that takes longer than say 10 seconds to establish. Disconnect go back to running the loop so pumps on timers shut off when they are supposed to. Then it schedules a time to attempt a reconnect in the future. So far that code has been working flawless… I’m not sure why particles automatic mode is so dumb like that.

Brennon, do you know about watch dog timers (WDT)? Eventually I plan on putting one in my code…particle.io supports a version of this on the photon. It basically is a mechanism that requires a software function to regularly reinitialize a timer that is counting down…if the timer counts down to zero, a device reset is done…if the software successfully reintializes the WDT every “x” amount of time, then no reset occurs (called “petting the dog”). It is a fail safe in case the code, for any reason, goes off into lala land.

Wondering about your pH calibration process. My current implementation is to enter my chemical testing on my pool controller phone app, which sends it to the photon, which in turn enters it into the google spreadsheet. The photon will keep the most recent 8 test results (FC, pH, CH, TA, Cya) in its eeprom. Would having the latest hand tested pH value on the photon allow you to easily calibrate your probe?

I think the writing to google spreadsheets is going to be valuable for data recording…if there is interest, I might try to document that so that others could use it, too. It might take me a bit of time to figure out exactly what my son-in-law did, though…haha.

1 Like

I’ve used IFTTT tied into Particle to write the status of a Photon used to control my garage to Google Spreadsheets every 15 minutes because it would hang when it couldn’t connect to the internet/wifi. I added a watchdog timer to reboot it, upon failure, IFTTT writes ALARM! to tell me it disconnected.

Then I wrote a program to erase the Google Spreadsheet after a week to keep it clean.

Update on my application of your code. I have added an instance of the open source energy monitor as well as performing PWM to control a pool pump. 5-97% duty cycles at 100Hz gets me anything from 600-3450 RPM. I have a link below, but I have stripped out the valves, lights, aerator, and chemical. I do have a cleaner, but that will just be single relay control and temperature will be later.

PWM pool control and energy monitor

1 Like

Hey Nick…what model pool pump allows you to control it with a PWM output? Is your PWM controlling a relay that supplies the AC current to the pump, or is it a DC pump that you are controlling? That’s pretty neat!

It is a Century Vgreen 1.65 pump 240VAC pump. There is a Cenury automation adapter that connects to the pump via RS-485. The adapter then connects to the relay outputs from Jandy/Hayward systems but one input to the adapter is PWM, which then allows any speed from 600-3450 RPM. I will hook up the adapter and sniff the RS-485 protocol to see if i can cut it out completely to give me a secondary means of control.

Thanks Nick…looks like a cost effective pump. It doesn’t seem like there is a real advantage for you take out the interface (costs one more pin??). Do you already have the pump installed in your system?

I have gotten around to putting a project update on my Github account:

No code posted yet, just a description and some screen shots of the phone app. It’s taking me forever as I have gotten bogged down in little details that I probably shouldn’t have bothered with at this point . In addition, I have had little time as we are watching my twin grandsons full-time. I started working back on the Photon .ino code (still mostly interface to phone app) and will eventually post that as a starting point for which I will begin adding the “real” pool functionality.

The “real” pool functionality that I started prior will need to be modified heavily as I have refined many of my ideas about what the Photon should actually be doing and how it should be done. I have learned a few things about modularity and object-oriented-programming so far (mostly from my son-in-law) and probably know just enough to screw up my efforts to move forward, but not nearly enough to do it right. But as I have said, it IS a lot of fun and I’ll continue to plug away.

Brennon, any updates?..summer is getting close and I am not going to make it for my system…it looks like it will be into the fall, darnit!

1 Like

Yeah, I’m just going to stick with the PWM method for now, the protocol sniff was just going to be for fun, to see if I could decode the Century protocol for controlling the pump.

The neat thing is, I had a Hayward pump and Motor, but the original motor went bad, which was replaced with a single speed Century motor. Seeing as how easy that was, I just watched a youtube video on replacing a pool pump motor, meaning no plumbing to do, just unbolt/unwire the pump, then this one was a direct bolt in, just make sure you get the appropriate C-face or Square face pump. All in all, about an hour of work. I had a electromechanical timer which I just pulled out the tabs so that it wouldn’t do anything.

It has a built in 24 hour program and is currently running on its own. But I want the pool cleaner booster pump to turn on when the pool pump is at max RPMs, so the Photon will have relay control of the booster pump.

Hey guys (Lance you asked to see some of this)…I have started posting pieces of my .ino code over on the Particle.io site. I still have a lot to do, but started making some steadier progress in the last week because our twin grandsons went into full time daycare, haha. I do miss having them…anyway…

1 Like

Hey guys, I’m posting my progress over on the Trouble Free Pool website. Thanks Brennon @bscuderi13 for all the help and inspiration! Would love to hear updates on your ph/orp, that is still on my radar but on the backburner while I bring up the basic functionality.

Anyway, here is the link:

1 Like

Hey guys I’ll just lump the replies in this post. I’m Just now getting around to reading these updates. I’m glad you guys are still involved in this project. I haven’t made any head way at all recently as my job has just been full steam ahead the last few months and I’ve had no free time for projects at home recently. So now I’ve got a backlog of some partially finished projects. This one is near the top of those projects if I can just get some me time back. Right now my pool is running and dosing the chemicals just on a timer mode basically running the chemical pumps For a set time multiple times a day and I’m bypassing the probe readings as I still haven’t gotten around to replacing the one I broke haha. I didn’t notice the updates to this thread for some reason my hotmail was filtering the alerts to junk. As far as calibrating my probes I put a calibration mode function in my code that takes a reading every second instead of once a minute. That reading doesn’t get sent to the smart hub but instead I just use the particle app to read the value I then write them down and then I change the variable values I created for calibration points on my ino code and re-push the firmware to the photon with the new calibration values. I’m sure there is a better way but that’s just what I came up with. I’d love to see your guys watch dog timer code. My code has been more reliable since going semi automatic with my connection logic having an offline mode and scheduling reconnect attempts to help with possible lagging with connectivity problems. However every now and then I’ve seen a couple of my photons get stuck in a state it can’t seem to get out of and I’m sure the watchdog could help me with these instances.

Brennon, glad to hear from you…I understand being busy, haha. As you can see on my thread on TFP, I am making some progress. About the watch dog timer…I am having second thoughts about trying to use the software implementation in the photon, partly due to this thread:

Once I get most of my software up and running, I want to see how much bandwidth is available on the photon. That IS something I worry about with all the functionality I am planning, does the photon have the cpu power? If it has sufficient bandwidth, I am considering adding an external WDT that attaches to the I2c bus to reset my system if things seem unattended for any reason.

Like you, I have seen my photon get in a state where it seems that it has lost the web connection and continually tries to reattach. I haven’t yet played with all the options that are available for connecting to the web (automatic, semi, etc), as you have.

I am looking for a solution for the winter months. I have a hayward Salt cell with the flow sensor. I also have a variable speed pentair pump. What I really want to know is if the water is flowing during the winter months. We rarely get below freezing but I want to know so I can make sure my Pool pump is working.

Any ideas?

You could add a second flow switch and connect a smart dry contact sensor. This could either be a hacked open/close sensor, or a dedicated dry contact sensor like the Aeotec, Remotec, etc.