Greg's Website

Projects

ESP32 Water Filter Monitoring System

This project involves using an ESP32 microcontroller to monitor the status of a multi-stage water filtration system. The need for this project arose from me not wanting to waste money on filters that were still good. The recomendataion for replaceing the filters was 6 months for some and 1 year for others. However, these recommendations are based on average usage of a family of four.

Using an ESP32 microcontroller and TDS sensors placed at various stages of the filtration process, the system measures the TDS levels of the water before and after each filter stage. The values are then sent to Home Assistant to display and log the values over time.

Code for the ESP32

The code for the ESP32 was pushed using esphome yaml configuration. I have included the code below for reference.


esphome:
  name: "tds-sensor"
  friendly_name: Water Filter
  min_version: 2024.11.0

esp32:
  board: esp32dev
  framework:
    type: esp-idf

# To Enable logging
logger:

# Enable Home Assistant API
api:

# Allow Over-The-Air updates
ota:
- platform: esphome

wifi: 
  ssid: "WifiSSID"
  password: "HiddenPassword"


sensor:
  - platform: adc
    pin: GPIO34
    name: "Water TDS Post Stage 1"
    update_interval: 600s
    unit_of_measurement: "ppm"
    filters:
      # Smooth out noise with an exponential moving average
      - exponential_moving_average:
          alpha: 0.1  # Smaller alpha = more smoothing
          send_every: 1
      # Convert ADC raw value to millivolts and apply the derived formula
      - lambda: return round(((0.4071 * (x * 1000)) - 7.1881));
      # Clamp values to avoid negative PPM readings
      - lambda: if (x < 0) return 0; else return x;

  - platform: adc
    pin: GPIO35
    name: "Water TDS Post RO"
    update_interval: 600s
    unit_of_measurement: "ppm"
    filters:
      # Smooth out noise with an exponential moving average
      - exponential_moving_average:
          alpha: 0.1  # Smaller alpha = more smoothing
          send_every: 1
      # Convert ADC raw value to millivolts and apply the derived formula
      # This formula is based on calibration with TDS meter readings
      - lambda: return round(((0.4071 * (x * 1000)) - 7.1881));
      # Clamp values to avoid negative PPM readings
      - lambda: if (x < 0) return 0; else return x;

Photos

Below are some photos of the project in various stages of development and deployment.

Water filter and esp32
Outlined in red is the container that holds the ESP32 with 2 TDS sensor cables and one power cable.
In the yellow box is the "Post Stage 1" TDS sensor measuring TDS after the sediment and carbon filters.
Post RO Filter Sensor
Outlined in green is the connection for the "Post RO Filter" sensor.
Home Assistant Screenshot
This is a screenshot of the Home Assistant dashboard displaying the TDS sensor readings, this history can be seen by clicking on the individual sensors.

Take-aways

Through this project, I gained hands-on experience with microcontroller programming, sensor integration, and data visualization. One mistake I made initally was using a static IP address for the ESP32. This caused issues when I changed subnets and had to reconfigure the IP address. Using DHCP with a reserved address would have been a better approach so I dont have to crawl underneath my sink to reconfigure the device.