A replacement spa thermostat using a Picaxe 14M2

A replacement spa thermostat using a Picaxe 14M2

My wife and I have been enjoying our retirement for 9 years now. One pleasure is to daily enjoy a dip in our spa while drinking our morning coffee.
Since it is only a step from our house's side door and is private we can go directly to it from our bed when we wake up. It is on a timer and so is already at the correct temperature.
However since I bought it used in 1997 and it has been almost continuously hot since, it was not too surprising when the bulb and bellows type thermostat failed recently.
Since no replacement could be found this was a good opportunity to take advantage of the new Readtemp command provided with the M2 Pickaxes. The thermostat is contained in a separate control box available to the bathers and fortunately uses regulated 5V for its controls.
Its sole output is a logic level, since I long ago replaced the original relay logic with integrated circuits to eliminate wear on the high power relay contacts.
The obvious choice to replace the thermostat is a pot for the control and a DS18B20 to sense the water temperature.
The dial on the control box (see the photo) is nicely engraved with the temperature setting in 1-degree (F) intervals. It took some effort to match these to within a degree using a pot, but I managed it.
Originally the control box had a red LED which was directly connected to the thermostat contacts. I embellished this with a 3-color LED: Blue=cold,Green=hot.
I also went into the modern natural-gas heater cabinet which is, by law, several feet away and put in an AC input optical-isolator to sense gas flow. This causes the LED to glow red.
The old thermostat had a natural hysterisis, This needed to be replicated in the program to limit pump cycling.

Here are photographs

Here are the circuit diagrams

Here is the code