Introduction: ESP8266 Pool Temperature Monitor MQTT

I always wanted to track the temperature of my pool water and wanted a cheap/easy way to do it. With the power of ESP8266, we can do all kinds of sensors.

Since I live working with MQTT, I found a nice MQTT Framework for ESP8266 that works beautifully called Homie.

Here are the parts list

Step 1: Flash ES

First step is to get our flashy new ESP8266 flashed with the firmware.

Connect the jumper cables from your ESP8266 to your FT232 to put in flash mode.

You will also need to download the Homie ESP8266 from their github. Please also head over to Homie Read me pages to configure with your WiFi

Arduino Sketch

#include <Homie.h>
#include <OneWire.h>
#include <DallasTemperature.h>

#define FW_NAME "temperature" #define FW_VERSION "1.0.0"

const int TEMPERATURE_INTERVAL = 300;

unsigned long lastTemperatureSent = 0;

#define ONE_WIRE_BUS 2 // DS18B20 pin OneWire oneWire(ONE_WIRE_BUS); DallasTemperature DS18B20(&oneWire);

HomieNode temperatureNode("temperature", "temperature");

void setupHandler() { Homie.setNodeProperty(temperatureNode, "unit").setRetained(true).send("f"); }

void loopHandler() { if (millis() - lastTemperatureSent >= TEMPERATURE_INTERVAL * 1000UL || lastTemperatureSent == 0) { float temperature = 22; // Fake temperature here, for the example DS18B20.requestTemperatures(); temperature = DS18B20.getTempFByIndex(0);

Serial.print("Temperature: "); Serial.print(temperature); Serial.println(" °F");

Homie.setNodeProperty(temperatureNode, "degrees").send(String(temperature));

lastTemperatureSent = millis(); } }

void setup() { Serial.begin(115200); Serial.println(FW_NAME FW_VERSION); DS18B20.begin();

Homie_setFirmware(FW_NAME, FW_VERSION); temperatureNode.advertise("degrees");

Homie.setSetupFunction(setupHandler); Homie.setLoopFunction(loopHandler); Homie.setup(); }

void loop() { Homie.loop(); }

Step 2: Put It All Together

Solder all the pieces together. This was my first project so things don't look as clean as I would like.

Step 3: Sensor Holder

Here is the 3D STL file schematic.