ESP32 Pool Thermometer - Works With HomeKit and Alexa

By tomfrenzel

Project Overview

This tutorial guides you through building a Pool Thermometer that integrates with Apple HomeKit and Amazon Alexa. The design prioritizes low power consumption, making it suitable for battery operation with a small solar panel for charging. The thermometer sends temperature data via HTTP requests to a Homebridge setup, making it accessible through Alexa devices. The ESP32 unit goes into deep sleep for 10 minutes between readings to conserve power.

Supplies

Electronics:

Case:

Tools:

Step 1: Code

The code for the Thermometer is designed for simplicity and efficiency. It performs the following actions:

  1. Establishes a WiFi connection.
  2. Disables Bluetooth to reduce power consumption.
  3. Reads the current temperature from the DS18B20 sensor.
  4. Makes an HTTP request to the Homebridge server to send the temperature data.
  5. Disconnects from WiFi and enters deep sleep for 10 minutes before repeating the process.

Here is the Arduino sketch:


#include <WiFi.h>
#include <HTTPClient.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: %s\n", sender.errorToString(httpCode).c_str());
    }
    sender.end();
  } else {
    Serial.println("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() {
  // The ESP32 will wake up from deep sleep, execute setup(), and then go back to sleep.
  // The loop function is not used in this deep sleep configuration.
}
  

Step 2: Wiring

This step involves connecting the electronic components. The diagram below illustrates the necessary wiring. If you are comfortable following wiring diagrams, you may proceed directly to later steps.

Diagram Description: A wiring diagram shows the connections between the ESP32 microcontroller board, the DS18B20 temperature sensor, the mini solar panel, the LiPo battery, and the TP4056 battery charger module. Wires are color-coded for clarity.

Step 3: Voltage Regulator

The first part of the assembly is to build the voltage regulation board. It is recommended to use a stripboard with pre-connected pins for easier assembly. The process involves soldering components onto the stripboard.

Step 1: Soldering the electrolytic capacitor

Electrolytic capacitors have polarity. The lead on the side of the white/grey stripe is the negative pole. This pole should be connected to GND. Ensure the capacitor is placed correctly on the board.

Step 2: Adding the ceramic capacitor

Ceramic capacitors are non-polarized, so their orientation does not matter. Connect them using the outer lanes of the stripboard.

Step 3: Connecting the voltage regulator

Connect the voltage regulator to the board. The orientation of the voltage regulator depends on how the electrolytic capacitor was placed. If the capacitor's stripe is on the left, the round side of the regulator faces the capacitor. If the stripe is on the right, the flat side of the regulator faces the capacitor.

Diagram Description: A digital illustration shows a small circuit board with an electrolytic capacitor and a voltage regulator (labeled VREG 78xx) soldered in place, illustrating the connections.

Step 4: Thermometer Rod

Prepare the rod for the temperature sensor. Drill a 4mm hole through the entire rod and another hole through the center of the cream can's bottom. The diameter of the second hole depends on your rod and whether you intend to screw it into the can.

If you wish to screw the rod into the thermometer body, cut a thread onto one end of the rod and slip an O-ring onto the bottom of the thread.

Once prepared, push the temperature sensor wire through the rod and the can's bottom. Secure the rod to the can, potentially using a screw. Apply silicone sealant to the inside of the can to ensure it is watertight. After the silicone dries, test for leaks by placing the can with the lid and the large O-ring submerged in water for several hours.

Image Description (Top Left): A close-up view of the stainless steel DS18B20 temperature sensor probe, attached to a white plastic rod with a black O-ring seal.

Image Description (Top Right): The inside of the white Nivea creme can, showing the temperature sensor wire passing through the bottom and being secured with clear plastic wrap and sealant.

Step 5: Temperature Sensor

Connect the DS18B20 temperature sensor to the ESP32 board. The black wire connects to a GND pin on the ESP32. The orange/yellow wire connects to pin 4 of the ESP32 via a 4.7k Ohm resistor. The red wire connects to the other end of the resistor, leaving approximately 5cm of wire for the next step. If your sensor has a white wire, it can be ignored if you are using a 3-wire sensor setup.

Diagram Description: A detailed wiring diagram shows the ESP32 board with pin labels. The DS18B20 sensor's wires are connected: black to GND, orange/yellow to pin 4 through a resistor, and red to the other side of the resistor.

Step 6: Battery Charger, Battery, ESP, and Voltage Regulation Board

Now, wire the battery charger, battery, ESP32, and voltage regulation board together. Start with the voltage regulation board: connect its ground lane to a GND pin on the ESP32 and the OUT- pin of the battery charger. Connect the OUT+ pin of the battery charger to the center lane of the voltage regulation board.

Next, connect the power lane of the voltage regulation board to the 3.3V pin of the ESP32 and to the power wire from the temperature sensor. Finally, connect the LiPo battery to the battery charger. An extra connector between the battery and charger is optional and can facilitate battery swapping if needed.

It is recommended to charge the battery using the micro-USB port on the charging board until the battery is fully charged (indicated by a blue LED). For added protection against water ingress, applying hot glue to all connections is advised.

Image Description: A collection of electronic components laid out on a wooden surface: a LiPo battery, a TP4056 battery charger module, and the ESP32 board, all connected to a small voltage regulation board.

Diagram Description: A Fritzing diagram visually represents the complete circuit assembly, showing the interconnections between the ESP32, voltage regulator, battery charger, LiPo battery, and temperature sensor, powered by the solar panel.

Step 7: Thermometer Cap

With the electronics assembled, it's time to attach the solar panel to the lid of the can. Drill two small holes in the lid for the solar panel's wires, depending on their connector placement. Pull the wires through these holes and connect them to the battery charging board, as shown in the previous step's diagram.

To ensure a watertight seal, apply silicone sealant around the edges of the solar panel on the lid.

Once sealed, screw the lid onto the can. The thermometer is now ready for testing.

Image Description (Top): The white lid of the Nivea creme can with a solar panel affixed to its exterior.

Image Description (Bottom): The interior of the white can lid, showing the wires from the solar panel connected to the battery charging board.

PDF preview unavailable. Download the PDF instead.

ESP32-Pool-Thermometer-Works-With-HomeKit-and-Alex wkhtmltopdf 0.12.6 Qt 4.8.7

Related Documents

Preview DIY Automatic Plant Watering System with ESP32 and Blynk
A comprehensive guide to building a smart, automated plant watering device using an ESP32 microcontroller, various sensors, and the Blynk IoT platform. Learn about component selection, assembly, wiring, and software setup for effortless plant care.
Preview DIY ESP32 Soil Moisture Sensors and Automatic Watering System
Learn how to build a DIY automatic plant watering system using ESP32 soil moisture sensors and Home Assistant. This guide covers sensor setup, software configuration, and automation for efficient water usage.
Preview Smart Home Automation System using ESP32, Blynk, and IR Remote
Research paper detailing the design and implementation of an IoT-based smart home automation system using ESP32, Blynk, IR remote, and manual controls for efficient appliance management.
Preview Smart Home Automation with Blynk and ESP32: WiFi and Manual Control Guide
Learn to build a smart home automation system using an ESP32 microcontroller and the Blynk app for WiFi control. This guide covers integrating manual switches for backup, monitoring relay status, and setting up the project step-by-step.
Preview DIY Weather Station with ESP32: Build Your Own Smart Weather Monitor
Learn how to build a DIY smart weather station using the ESP32 microcontroller. This guide covers sensor integration, 3D printing, and connecting to Home Assistant for real-time data and forecasting.
Preview ESP32 Solar Power System Diagram
Diagram illustrating a solar-powered system for an ESP32 microcontroller, featuring a battery, a 'Babysitter' power management unit, and a buck converter for voltage regulation.
Preview 2.8inch ESP32-32E Display Module User Manual
User manual for the 2.8-inch ESP32-32E Display Module, covering resource description, software and hardware instructions, and precautions for use. Details include ESP32-WROOM-32E module, ILI9341 LCD controller, SPI communication, USB-to-serial conversion, and various circuit diagrams.
Preview ESP32 Practical Guide: Projects and Applications
A comprehensive guide to the ESP32 microcontroller, covering its fundamentals, installation, and practical application through various projects. Learn about GPIO, sensors, Bluetooth, web servers, MQTT, and more.