ESP32 Pool Thermometer - Works With HomeKit and Alexa

by tomfrenzel in Circuits > Sensors

10691 Views, 63 Favorites, 0 Comments

ESP32 Pool Thermometer - Works With HomeKit and Alexa

IMG_2029.JPEG
IMG_2030.JPEG

In this tutorial, I'll show you how to make a Pool Thermometer that works with Apple HomeKit and Alexa.

Since I'm writing these instructions after I built the Thermometer, I can only show off the results and write what I've done.

To make the Thermometer run off a battery, the power consumption has to be held as low as possible. This becomes even more important as the Solar panel should not be too large to keep the looks of the Thermometer clean.

Due to these circumstances, I went with the way of installing the HTTPWebHooks Plugin on my Homebridge and adding the Thermometer as a Temperature Sensor. With the Homebridge Alexa Skill, the Sensor got also accessible to Amazon Echo devices.

The big benefit of this is, that the current Temperature of the Pool is saved inside the Homebride rather than on the ESP. Therefore, the ESP only needed to make an HTTP request to the HTTPWebHooks Plugin and go to Deep Sleep for the next 10 minutes, before it boots again and read/send the current temperature to the Homebridge

That being said, we can start with the actual instructions 😉

Supplies

Electronics:

  • ESP32
  • DS18B20 Temperature Sensor
  • Mini Solar Panel (6V / 65mA / 0.4W)
  • LiPo Battery (3.7V / ~800mAh)
  • TP4056 Battery Charger Module
  • Voltage regulator (MCP1700-3302E)
  • 100uF electrolytic capacitor
  • 100nF ceramic capacitor
  • 4.7k Ohm resistor
  • 3x6 Circuit / Stripboard
  • Jumper Wires

Case:

  • Nivea Care Creme can
  • PVC Rod (20mm x 100mm)
  • O-Ring (75mm x 2.5mm)
  • O-Ring (20mm x 3.5mm) - optional
  • M16 Bolt - optional

Tools:

  • Soldering Iron
  • Soldering Wire
  • Soldering Paste
  • Drilling Machine
  • 4mm Drill
  • M16 Thread cutter - optional
  • Hot Glue
  • Silicone

Code

The code of the Thermometer is pretty simple:

  1. Establish WiFi connection
  2. Disable Bluetooth for less power consumption
  3. Read temperature from the sensor
  4. Make an HTTP request to the Homebridge carrying the current sensor temperature
  5. Disconnect from WiFi and go to Deep Sleep for the next 10 minutes

When the 10 minutes are over, the whole process starts over.

#include <WiFi.h>
#include <HTTPClient.h>
#include <ESPAsyncWebServer.h>
#include <esp_bt.h>
#include <esp_wifi.h>
#include <esp_sleep.h>
#include <OneWire.h>
#include <DallasTemperature.h>

#define ONE_WIRE_BUS 4

OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

const char* ssid = "YOUR_WIFI_NAME";
const char* password = "YOUR_WIFI_PASS";
HTTPClient sender;

#define uS_TO_S_FACTOR 1000000ULL  /* Conversion factor for micro seconds to seconds */
#define TIME_TO_SLEEP  600        /* Time ESP32 will go to sleep (in seconds) */

float temperature;

void push(){  
  if (sender.begin("http://IP_OF_YOUR_HOMEBRIDGE:51828/?accessoryId=esp32&value=" + String(temperature)))
  {
    int httpCode = sender.GET();
    if (httpCode > 0) 
    {
      if (httpCode == HTTP_CODE_OK) {
        String payload = sender.getString();
        Serial.println(payload);  
      } 
    }
    else
    {
      Serial.printf("HTTP-Error: ", sender.errorToString(httpCode).c_str());
    }
    sender.end(); 
  }
  else
  {
    Serial.printf("Error establishing HTTP connection!");
  }

}

void setup() {
  Serial.begin(115200);
  
  WiFi.disconnect(true);
  delay(1000);
  WiFi.mode(WIFI_STA);
  delay(1000);
  
  WiFi.begin(ssid, password);
  btStop();
  esp_bt_controller_disable();
  while (WiFi.status() != WL_CONNECTED) {
    delay(200);
    Serial.print(".");
  }

  Serial.println("Connected!");
  sensors.begin();

  esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);
  sensors.requestTemperatures();
  Serial.print(sensors.getTempCByIndex(0));
  Serial.println(" °C");
  
  temperature = sensors.getTempCByIndex(0);
  push();
  WiFi.mode(WIFI_OFF); 
  esp_deep_sleep_start();
}
 
void loop() {
}

Wiring

TemperatureSensor_Steckplatine.png

In the picture above, you can see how the Thermometer has to be wired up. If that's all you need to see in order to build it, you can skip Steps 2 - 4. Otherwise, keep reading and you'll know exactly what to do and what to pay attention to.

Voltage Regulator

IMG_2043.JPEG
Screenshot 2021-07-25 210353.png

The 1st thing to do is building to Voltage regulation board. Although I only used a Circuitboard where no Pins are connected from the factory, I highly recommend using one where all Pins of a row are already connected. That way you won't have to connect them with soldering wire, which can get pretty messy.

Since it's pretty hard to see what's going on in the picture of the actual Voltage regulation board, I added another picture of the Board in digital form.

I recommend using a board that has 3x6 Pins. That way you'll have enough space for the components and wires without having to bend any leads of the components.

Step 1: Soldering the electrolytic capacitor

Depending on what direction you solder the electrolytic capacitor, you'll have the place the voltage regulator in a certain way. This is because electrolytic capacitors have polarity. So the lead on the side of the white/grey stripe is the negative Pole and should later be connected to GND.

The GND lead should be connected to the left lane and the other lead to the right one. It's important to keep the middle lane empty just yet! You might have the bend the leads of the capacitor a little bit to make them fit into the two outer lanes.

Step 2: Adding the ceramic capacitor

Ceramic capacitors don't have polarity. Therefore, it does not matter in which direction you solder it on the board. Only make sure, that you use the outer lanes again.

Step 3: Connecting the voltage regulator

Finally, you'll have to connect the voltage regulator to the board. Now it is important, how you connected the electrolytic capacitor. If the white/grey stripe of the capacitor is on the left, the round side of the voltage regulator has to face the capacitor. If the stripe is on the right, the flat side of the regulator has to face the capacitor.

If you completed those 3 Steps, the Voltage regulation board is finished and you can continue wiring the rest.

Thermometer Rod

IMG_2044.JPEG
IMG_2036.JPEG
IMG_2031.JPEG

The 2nd Step is to prepare the Rod for connecting the Temperature Sensor to the ESP

That's done by drilling a 4mm hole through the entire Rod and another one through the center of the cream can's bottom (The diameter depends on the size of your Rod and whether you want to screw on the rod or not).

If you wish to screw the Rod the Thermometer body, you'll also need to now cut the thread onto one end of the Rod and slip on an O-Ring to the bottom of the thread.

Once that is finished, you can push the end of the Temperature sensors wire through the Rod and the bottom of the Can (coming from underneath as shown in the pictures). Next, you would also put the screw on the rod to connect it to the can.

Now you'll have to put some silicone on the inside of the can to seal it up. Once the silicone is dry, check if any water comes through by putting the big O-Ring onto the can, screwing the lid on, and keeping it under Water for a couple of hours.

Temperature Sensor

Screenshot 2021-07-25 211504.png

If the Rod is prepared, you can go on with connecting the Temperature Sensor to the ESP.

The Black wire has to be connected to a GND pin of the ESP.

The Orange / Yellow wire has to be connected to a 4.7k Ohm resistor and to pin 4 of the ESP.

The Red wire has to be connected to the other end of the Resistor with approx. 5cm extra wire left after the connection to the resistor. This wire will be connected during the next Step.

The white wire coming out of the Sensor can be ignored if you happened to order a DS18B20 with 4 wires instead of just 3.

Battery Charger / Battery / ESP / Voltage Regulation Board

IMG_2045.JPEG
TemperatureSensor_Steckplatine.png

Now it's time to wire up the Battery charger with the Battery, ESP, and Voltage Regulation Board.

Let's start with the Voltage Regulation Board again. The Ground lane has to get connected to one of the GND pins of the ESP and the OUT- pin of the Battery charger.

After that, connect the Out+ pin of the Battery charger to the center lane of the Voltage Regulation Board.

That's being done, the power lane of the Voltage Regulation Board has to be connected to both the 3.3V pin of the ESP as well as to the power wire coming from the temperature Sensor which we added in the previous step.

Now everything left is, to connect the Battery to the Battery charger. You can see that there is an extra connector between the Battery and the charger. That is not necessary and I just added it for testing. In case the battery was too small, I would only have to swap the battery and don't have to re-solder it to the Charging Board.


At this point, the Thermometer should already work if your battery is charged. Anyway, I recommend charging the Battery via the micro-USB port of the Charging Board until the Battery is fully loaded (when the blue LED of the Charging Board lits up).

Tip: As you can see in my pictures, I've put some Hot Glue on all connections, just in case that some water gets into the Thermometer.


Thermometer Cap

IMG_2032.JPEG
IMG_2034.JPEG
IMG_2038.JPEG

Now, that the Thermometer is already working, it's time to wire up the Solar panel.

To do so, drill two little holes through the lid of the can (depending on where the connectors of your solar panel are) and pull the wires through them. If that's done, you can connect the to the Battery Charging Board as shown in the picture of the previous Step.

The only thing left now is to put some silicone around the edges of the Solar panel, so it is sealed up.

If that is done, you're ready to go! Just screw on the lid and try the Thermometer out 🚀