MQTT Swimming Pool Temperature Monitor

1,529

21

0

Introduction: MQTT Swimming Pool Temperature Monitor

About: British but settled in Cape Town, South Africa. A retired electronics and instrument designer who now continues his 'work' as a hobby and loving every minute of it.

This project is a companion to my other Home Automation projects Smart Data- Logging Geyser Controller and Multi-purpose-Room-Lighting and Appliance Controller .

It is a pool side mounted monitor that measures the pool water temperature, ambient air temperature and barometric pressure. It then displays the pool water temperature on a local LED bargraph and transmits via WiFi/MQTT to a home system - in my case a software upgraded MQTT compatible version of the Lighting Controller. although it is easy to integrate it into any MQTT compatible Home system.

This Instructable focusses on the Pool Monitor design and construction, the upgrade of the Controller (new firmware and addition of an OLED display) will be included in the original controller shortly.

Key features include:

  • The absence of poolside mains electricity determines a 18650 battery power supply with an integrated 1W solar polar panel to maintain the battery charge, battery life is further optimised by the use of the ESP8266 "Deep Sleep" mode. In my system, the unit was able to run over our "active swimming pool season" (November through to April) without manual intervention of manual top up charge.
  • An optional local built in 8 LED bargraph displaying the pool temperature in 1 degree intervals.
  • MQTT data transmission via local WiFi connection to any compatible host system.
  • All programming is achieved over WiFi using the Monitor as an Access Point and internal Web Server configuration pages with all programmable parameters being stored in internal EEPROM.
    • Time intervals between wake up and transmissions. 1 to 60 minute intervals.
    • Configurable MQTT topic/message formats
      • Individual message topics (E.g PoolTemp, AirTemp, BaroPress)
      • Single compact topic (E.g. Pool Temp + Air Temp + Barometric pressure)
      • Compatible with OLED display mounted on Multi-purpose-Room-Lighting and Appliance Controller (see title figure for example)
    • WiFi network SSID and password
    • Access Point SSID and password
    • LED bargraph control
      • Programable minimum temperature range (15 to 25'C)
      • Programmable permanently ON, permanently OFF, Only on during daylight hours

Although I 3D printed my own enclosure / mounting arrangement and used a PCB board from a previous project, you can literally use what suits your personal preferences as nothing is critical or "cast in stone". The last section of this Instructable contains Gerber and STL Files for the PCB boards and ABS housing that I designed specifically for this project

Step 1: Block Diagram and Discussion About the Choice of Components

The block diagram above highlights the main hardware modules of the Pool Monitor.

Processor

The ESP8266 used can be any of the ESP03/07/12 basic modules through to the more perfboard friendly NodeMCU and WEMOS modules.

I used the ESP-12, If your pool is some distance from your WiFi router you may prefer the ESP-07 with an external antenna. The NodeMCU/Wemos modules are very board friendly but will result in a slight increased power consumption due to their extra onboard voltage regulator and LEDS - this will affect the ability of the solar panel to daily keep the battery in charge and you may require a periodic manual charge using the USB port on the charger module.

Temperature sensors - Fig. 2

I have used the easily available and low cost metal tube + cable versions of the DS18B20 temperature sensors that come with around 1 metre of connecting cable as they are already robust and weatherproof. One using the full length of the cable for the pool water measurement and another with a shortened cable for the ambient air temperature.

Air ambient sensor

I have selected the excellent BME280 module to measure the ambient air humidity and barometric pressure. You may be wondering why I did not used the air temperature measurement function of this module.

The reason is simple - if, as I did in the original prototype use this function, you end up measuring the static air temperature INSIDE the housing which tends to read high due to internal self heating of the enclosure air space by the outside sun (it reads perfectly at night!). It was quickly realised that the air temperature sensor needed to be mounted outside of the enclosure but in the shade away from the direct sun light so I switched to a second DS18B20 and provided a small mounting point underneath the enclosure. The BME280 temp sensor although is still used as a diagnostic measurement for the in-enclosure temperature and can be monitored on the configuration server main page.

LED bargraph - Fig. 1

The eight local high intensity LED outputs are driven by a PCF8574 IO expander chip which in turns drives each LED by a PNP 2N3906 transistor. The PCF8574 will indicate just one LED at a time (to reduce the power consumption) depending on the measured pool water temperature and will stay active even when the ESP8266 is in its sleep mode. Thus, if enabled, the LED bargraph will be active all of the time.

  • If the measured temperature is less than the minimum temperature assigned to the bargraph, then BOTH LED 1 and 2 will illuminate.
  • If the measured temperature is greater than the minimum temperature assigned to the bargraph+8, then BOTH LED 7 and 8 will illuminate.
  • If the light level as measured from output of the solar panel is lower than the threshold programmed in the configuration set up, the LED outputs will be disabled to save battery power, alternatively the bargraph can be permanently disabled (threshold set to 0) or enabled (threshold set to 100).
  • If your build does not require the bargraph simply omit the PCF8574, LED's, transistors and associated resistors

Solar panel, battery and battery charging board

The basic power supply is simply a 2000mAH (or greater) 18650 LIPO battery fed through an 1N4001 diode to reduce the battery voltage (max charged battery = 4.1V and max ESP8266 voltage = 3.6V).

Lower capacity batteries will work but I have no feeling if the daily charging by the solar panel will be adequate.

Beware the higher capacity labeled batteries (E.g. 6800 mAH) - many on the market are fakes. They will work but at what capacity and reliability is anyone's guess.

The 1W 5V solar panel is connected to the inputs of a TP4056 LIPO charger board and the output of the latter to the battery thus the battery will be charged when the light level is high enough to produce a usable charging voltage and also the battery can be manually charged via the USB connector on the TP4056 board.

If you intend to use the 3D printed housing design then you must use the 110mm x 80mm sized solar panel. There are other sizes available so just take care when purchasing as this may be critical when selecting your type/size of housing.

Also a word of caution re temperatures. It can be difficult to establish the true max temperature limit of these cheap panels as it is often not stated - I found 65'C max specified on one device but nothing on the majority of onsite suppliers. Now consider that the panel by design is a) black and b) going to be out in the bright sunlight all day every day - you may find it better to allow a little shade over the panel if it gets too hot. My unit has not suffered any failure (installed early 2019) but its reliability will surely depend on your local climate and probably mounting place.

Push buttons - Fig. 3

You might think that a push button is well "just a push button" but when it is on an enclosure that is outside in the sun and rain 24/7 then you need to take care of its specification. Electrically it is a simple component but the sealing integrity of your housing hinges on their mechanical quality. I used what is very popular waterproof single pole 12mm push button available from many suppliers - this has proved itself to be a very robust switch..

  • Button 1 is used as the reset button - used to manually force the monitor to make a measurement and transmit the result
  • Button 2 when pressed immediately afterpressing and releasing button 1 will instruct the monitor to start up its Access Point (AP) using the SSID and password that you have previously programmed it with. If fitted, each alternative LED on the bargraph lights up briefly to indicate that the AP is starting up.
  • Both buttons are also used in the initial build procedure to upload the firmware to the processor flash memory.

Note.
The 3 D printed housing is designed for these 12mm switches as listed in the bill of materials and as such are mounted on the side of the housing. If you are using your own housing I would recommend you fit them under the housing to shield them from weather exposure.

Toggle Button - Fig. 2

This is used to completely turn the monitor off when it is not being used and in storage. Note that the battery and solar panel remain connected to each other (but not the electronics) and so the battery will still receive charge if the panel is exposed to external light.

Enclosure - Fig. 3

This remains the last but very important component as this is the main component that provides protection for all of the other parts. The solar panel, push buttons, toggle switch, LED's and temperature sensors all require drilling or cutting holes in the housing so water proofing is severely jeopardised if the sealing after fitting the items is not taken care of. I glued the solar panel to the cover then sealed inside with silicone sealing. The LED board was potted inside to ensure that all of the LED points were sealed on the inside. You get the picture - prevent any potential ingress points. Since I used a 3D printed ABS model, I sprayed the inside of the housing including the main PCB with PCB sealing spray (you can also just used paint) just as a precaution! Figure 1 shows the enclosure mounted by the pool side. The included STL files also include a simple mounting assembly that allows the enclosure to be assembled to the weir top cover. It can be mounted anywhere that suits you subject to the length of the water temperature sensor cable, exposure to sunlight and the viewability of the LED bargraph if fitted.

Step 2: Bill of Materials

I have included a "potential" bill of materials based on my own choice of components As previously stated, you do actually have a lot of flexibility when it comes to almost all of the build items. I have cut and pasted some items off the Amazon online shopping site purely as an illustration - not as a recommendation of supply. The 18650 battery can have direct solderable tabs for the wires or you can buy a "standard" type and battery holder (as I did) for ease of assembly

You will also need glue (2 part epoxy recommended), 4 x M4 nuts and bolt.

Depending on your location, you will have potentially more convenient and/or cheaper suppliers. For a fact, if you are not in a rush for the components, AliExpress promises significant reductions on some if not all of the major items.

Step 3: Electronic Build & Firmware Upload

The schematic reveals a relatively simple "standard ESP8266" with no "surprises" comprising of just the microcontroller and a collection of input devices (2 x DS18B20 temperature sensor, 1 x BME280 environmental sensor, 1 x PCF8574 IO expander, 2 x push buttons and a battery/charge/solar panel combination.

ESP8266 Pin assignments

  • GPIO0 - Start AP Button
  • GPIO2 - Not used
  • GPIO4 - I2C - SCL
  • GPIO5 - I2C - SDA
  • GPIO12 - DS18B20 Data
  • GPIO13 - Test - Not used
  • GPIO14 - Not used
  • GPIO16 - Deep Sleep wakeup
  • ADC - Solar Panel voltage

PCF8574 pin assignments

  • P0 - LED bargraph 1 - Minimum Temperature
  • P1 - LED bargraph 2 - Minimum Temperature + 1'C
  • P2 - LED bargraph 3 - Minimum Temperature + 2'C
  • P3 - LED bargraph 4 - Minimum Temperature + 3'C
  • P4 - LED bargraph 5 - Minimum Temperature + 4'C
  • P5 - LED bargraph 6 - Minimum Temperature + 5'C
  • P6 - LED bargraph 7 - Minimum Temperature + 6'C
  • P7 - LED bargraph 8 - Minimum Temperature + 7'C

Uploading firmware

A copy of the firmware source code is included in the downloads section. The code has been written for the Arduino IDE version 1.8.13 with the following additions ....

  • ESP8266 Board Manager (version 2.4.2)
  • OneWire library
  • Dallas Temperature library
  • EEPROM library
  • Adafruit BMP085 library
  • PubSubClient library
  • Wire library

Ensure that you select the correct baud rate on the Serial monitor (115200), and the correct board dependent on what version of the ESP8266 chip you are using).

If you need further instructions how to set up the Arduino IDE then refer to my two previous instructables, both contain extensive set up instructions and also there is a multitude of online r sources available. If all else fails, post me a message.

I have included in the build a connector for the serial port lines (TxD, RxD & 0V) for connection to your computer using a standard FTDI USB to TTL convertor and the two push buttons provide you with the ability to power the ESP8266 in flash programming mode. (Apply power with BOTH the Reset and Start AP buttons pressed, release the Reset button whilst still holding the Start AP button, then release the Start AP button)

Additional Notes

  1. The push button connections, power supply, DS18B20 Temperature sensors can be brought out to standard 0.1" header pins for easy IO connections
  2. The 100 uF electrolytic capacitor (C4) and 100 nF ceramic capacitor (C6) should be mounted as close as possible to the power supply pins of the ESP8266.
  3. The 100nF ceramic capacitor (C5) should be mounted as close as possible to the power pins of the PCF8574
  4. Figure 10 illustrates the total wiring schematic - You can build all of the components on one board or split them into 2 boards with the PCF8574, 8 x 2N3906 transistors (Q1 to Q8), 16 x resistors (R3 to 14, R19 to 22), C5 on one "LED bargraph board) and the remainder on the "Controller board" (This is what I did)

Step 4: Using the Provided 3D Printed Enclosure

The choice of housing is flexible depending on your preferences and installation requirements. I 3D printed an ABS housing to suit my own installation and include it to either reproduce or use as an "inspiration" for your own construction. The STL files from the Download section can be printed at 0.2 mm resolution. If you do not own a 3D printer nor have a friend with one, there are many commercial 3D printing companies out there now who should be able to provide an affordable service for you.

The individual printed items are:

  • A. Enclosure base
  • B. Enclosure cover
  • C. Knuckle joint
  • D. Enclosure knuckle mount adaptor
  • E. Air sensor mount
  • F. Enclose sensor cable guide
  • G. 2 x rod (short and extended length - allows length of overall mount assembly to be varied)
  • H. Weir cover top adaptor
  • J. Weir cover bottom adaptor

Also needed are 4 x M4 threaded bolts and nuts

Notes

  1. Where items are glued, I recommend a two part epoxy resin or any suitable weatherproof glue.
  2. Glue the solar panel to the lid B and use silicon sealant in the inside of the cover to prevent any water ingress at the joining faces.
  3. Part E is glued to the part E at any point for mounting the air sensor. ALL of the air sensor must be below the housing base out of any direct view of sunlight (Ref Fig.5A)
  4. Part F and D should also be glued to the Enclosure part E base.
  5. The mounting knuckle assembly (G,C & G) fit together as a push fit and when their through holes are aligned, can be secured using 2 x M4 threaded bolts and washers (do not tighten until complete assembly is mounted and required orientation identified - do not over tighten to prevent cracking the plastic fittings). Cut the bolts to a suitable length if required.
  6. Mount parts H & J on the modified weir plat cover at a point where there is no risk of physical interference or stress from any pool cover strap etc (ref Fig 5 C,E & F). If the weir plate cover has a curved surface, I suggest that you use silicon sealant or epoxy to further bond part J to the underside of the weir cover.
  7. Now the enclosure assembly can be mounted onto the weir cover plate using the knuckle assembly (2xG & C). This knuckle assembly is a tight PUSH fit into both the enclosure base and the weir plate cover thus allowing the unit to be easily removed for winter stowage and/or maintenance. Do NOT glue this in place. Ref Fig. 5D
  8. Figure 4 outlines each part and how they fit together. For the mounting installation, I drilled a hole in my weir top cover to provide a mounting point for the mounting knuckle (This provides a 3 dimensional adjustment possibility for the housing relative to the the mounting mount)

Step 5: Configuration Server (Access Point)

All of the Monitor user settings are stored in EEPROM and can be monitored and changed via the built in web server that can be accessed when the monitor is put into Access Point (AP) mode.

To do this, the user must first press and release the RESET button then immediately after releasing, press and hold the second CONFIGURATION button for 1 to 3 seconds. On releasing the Configuration button, if fitted, each alternative LED on the bargraph will illuminate for a few seconds, meanwhile the AP will start up.

If you open the WiFi networks settings on your computer or mobile phone you will see the AP SSID appear in the available network list. If this is the first time you have started the AP this will appear as HHHHHHHHHHHHHHHHHHHH - Setup (the default name) otherwise it will be the name that you assigned to AP in the WiFi Settings followed by "-Setup".

Select the SSID and enter the password (the default is "password" without the quotation marks unless you have set it to something else.

Your computer/mobile phone will connect to the AP. Now open your favourite web browser and enter 192.168.8.200 in the URL address field.

Your browser will open at the Configuration web server Main Page - refer to Figure 6.

Here you will be able to read the current measured values and the buttons to the WiFi and other device setting pages. The bottom button is the last thing you press when you have changed all the parameters that you need to (if you do not press it the Monitor will stay powered up and continually drain the battery ....

Figure 7

This is the WiFi & MQTT settings page. You will be able to see the current stored network and MQTT details plus all of the available networks within range of the Monitor including the one that you want to connect to.

Wifi settings

Field A & B allow you to enter your required network SSID and password details, C is the name that you want to give your device and this will be the name of the AP SSID next time you start it. Lastly field D is the password that the want to give the AP.

MQTT settings

Here you will set the name of the MQTT broker (E) that you are using and most importantly whether the MQTT broker is a cloud based broker or a local broker (E.g. Raspberry Pi) connected to the household WiFi.

If you have previously selected the cloud based broker, you will see two additional fields for entering your username and password for the broker.

Note that if you leave any field blank, that field will not be updated - this allows you to make partial updates to settings without having to enter all fields.

The default address on first build is Broker name is MQTT-Server and is locally connected.

Figure 8

This shows the remainder of the device settings page accessed by the "Device Settings" button on the main page.

This has 2 formats depending on whether the MQTT settings is set to "HAS HouseNode Compatible" or Single/Compact topics

HAS HouseNode Compatible

This instructs the monitor to format its MQTT data to allow the data measurements to be displayed on one of the scrolling OLED screen displays on upto 5 of the Housenodes described in my previous Instructable "Mult-purpose-Room-Lighting and Appliance Controller". (See the opening Intro section for a picture of the Housenode displayed data. This is described further in the linked Instructable (updated November 2020).

You will need to enter the Hostname of the HouseNode that you want to sent the measurement data to (Field B)

Field C is the screen number that you want to display the data (this will make sense when you read the controller instructable!

Field A is a simple enable/disable for this data fram - if disabled, the data will not be sent.

This is repeated for upto 5 HouseNodes allowing you to sent the same data to upto 5 distributed Controller displays in your household.

Single topic

Each Monitor measurement is sent as a separate MQTT message using the topics "Pool/WaterTemp", "Pool/AirTemp" and "Pool/BaroPress". This allows you to easily select what parameter your MQTT subscribing master device wants to read directly rather than taking in everything with the Compact topic and extracting what you want to use.

Compact topic

All three measurements are combined into one Home Assitant compatible topic should your subscribing MQTT device prefers the format: Pool/{"WaterTemp":XX.X,"AirTemp":YY.Y,"BaraPress":ZZZZ.Z} where XX.X, YY.Y aand ZZZZ.Z are the measured Water Temperature ('C), Air Temperature ('C) and barometric pressure (mB)

Also on this page, you have the ability to select if the bargraph LED are switched off at night (recommended) to save un-necessary battery consumption. This is determined by the measured light level (LL) of the solar panel and is represented by a measurement from 0% (dark) to 100% (bright). You can set a threshold between 1 and 99% defining the light threshold under which the LED's will be disabled. 0% will permanently disable the bargraph and 100% will ensure that it is on all of the time.

You can also set the time interval between data transmissions between the range of 1 to 60 minutes. Clearly the longer the interval, the better the power management and you should remember that the pool temperature is not a fast changing measurement meaning that an interval between 30 and 60 minutes should be fine.

You may notice that the first time after initial construction that your air sensor (short lead) is indicated on the display as water temperature and vice versa! (tested by holding the sensor in your hand and/or dropping the sensor in a cup of of hot or cold water). If this is the case then the "DS18B20 pool and air address index addresses" data box allows you to reverse the index number (0 or 1) of the sensors - you will need to upload the setting and reboot the device before the sensor addressing will be correct.

Last and most importantly, remember that in any page where you have changed values, you MUST press the "Upload new settings to the device" button otherwise the Monitor will not update its EEPROM memory!

If you are happy with all of your setting changes, to exit the AP and revert to the normal monitor mode - press the bottom button on the AP main page. If you do not press it the Monitor will stay powered up and continually drain the battery ....

Step 6: A Little More Info on Using the Pool Monitor With the HAS Lighting and Appliance Controller

The Pool Monitor is designed to be a single component in your own MQTT based Home Automation System (HAS). I have mentioned several times that it was originally designed to be a member of my own HAS using my previous 2 published Instructables (Multi-purpose-Room-Lighting and Appliance Controller and Smart Data- Logging Geyser Controller). Both designs share a common approach to configuration using very similar integrated web servers ensuring a consistent and comfortable user interface across the platform.

Both these instructables were originally developed to be stand alone modules but in a recent upgrade, I introduced MQTT communication into each to allow satellite sensors (known as SensorNodes) to be linked to one or more Controllers (Known as HouseNodes). The main usage of this todate is to add a nice OLED display to the Multi-purpose -Room-Lighting and Appliance Controller and allow any enabled controller to routinely display all of the SensorNode data on it's local OLED display - the first picture above is of the three screens of a HouseNode that is scrolling through and displaying the data from itself, a Geyser controller and the Pool Monitor thus allowing a localised display of all captured data at any convenient location in the house hold.

Since any SensorNode or HouseNode can retransmit its data via MQTT , this allows upto 8 independent display points for your HAS measurement points. Alternatively any of the Nodes can be easily integrated into your own MQTT system and already one friend has integrated the geyser controller into his Home Assistant HAS.

Other SensorNodes in development currently are:

  • PIR movement sensor
  • InfraRed beam alarm sensor
  • Alarm siren and lamp control node
  • Alarm control panel
  • Handheld Remote control
  • Display only unit

These units will be released as Instructables some months after they have been running successfully in my own house.

Step 7: Downloads

The following files are available for download ....

  1. The Arduino IDE compatible source code file (Pool_Temperature_MQTT_1V2.ino).
    Download this file and place the file in a sub-directory of your Arduino Sketches directory called "Pool_Temperature_MQTT_1V2.
  2. The individual STL files for all of the 3D printed items (*.STL) compressed into one file Pool_Monitor_Enclosure.txt. Download the file, then RENAME the file extension from txt to zip and then extract the required .STL files.
    I printed them at 0.2mm resolution on 20% file using ABS filament using a Tiertime Upbox+ 3D printer.
  3. I have also included a set of jpeg files (FiguresJPEG.txt) covering all of the figures used in this Instructable to allow you, if necessary to print them separately at a size more helpful to you. Download the file, then RENAME the file extension from txt to zip and then extract the required jpeg files.
Battery Powered Contest

Participated in the
Battery Powered Contest

1 Person Made This Project!

Recommendations

  • Retro Tech Challenge

    Retro Tech Challenge
  • Lamps and Lighting Contest

    Lamps and Lighting Contest
  • Made with Math Contest

    Made with Math Contest

Comments