Niño Olvis

0%
Back to Projects
ESP32PlatformIOEmbedded C++AWS IoT CoreReact NativeSupabasePID Control

Smart Rainwater Harvesting & Filtration System

An autonomous IoT rainwater collection, closed-loop Time-Proportioned PID chemical dosing, and filtration system with real-time TLS MQTT telemetry and Expo mobile control.

Real-time system dashboard monitoring pH, optical turbidity, rain status, tank level, and active finite state machine step.

01 / 01

Project Overview

A thesis capstone project engineering an autonomous IoT-driven rainwater collection, chemical dosing, and multi-stage water purification system. Built with ESP32 microcontrollers in C++/Arduino (PlatformIO) and a React Native Expo mobile app (thesis_emblematic), the platform executes an autonomous 9-state finite state machine to manage first-flush dirty water diversion, Time-Proportioned PID pH dosing (6.5–7.5 pH safety range), multi-pass filtration, optical turbidity verification, and clean water dispensing. Telemetry streams continuously via TLS-encrypted MQTT (Port 8883) to AWS IoT Core, featuring real-time mobile charts powered by React Native Skia and Gifted Charts, with manual actuator overrides, live PID tuning, and Supabase Edge Function command routing.

Role

Embedded & Full-Stack IoT Developer

  • Embedded Firmware Lead
  • IoT & Mobile Developer

Tech Stack

ESP32 MicrocontrollerEmbedded C++ / Arduino FrameworkPlatformIOAWS IoT Core (MQTT over TLS 8883)ADS1115 16-bit I2C ADCReact Native / Expo (Expo Router v55)TypeScriptSupabase (Auth & State Logging)Zustand State ManagementSupabase Edge Functions (Deno)

Backend & Architecture

  • Engineered an autonomous 9-state finite state machine (IDLE, FIRST_FLUSH, COLLECTING, DOSING, FILTERING, TURB_CHECK, DISPENSING, RETURNING, COOLDOWN) to automate rainwater harvesting and multi-pass water purification.
  • Implemented 2-point buffer software calibration (pH 4.0 & pH 7.0 reference curves) and signal processing (21-sample median windowing & 20-sample moving average smoothing) on a 16-bit ADS1115 ADC to eliminate sensor noise.
  • Architected a Time-Proportioned Proportional-Integral-Derivative (PID) controller (br3ttb/PID) to map continuous analog PID outputs into variable relay ON-times over a 5000ms loop, preventing pH overshoot.
  • Bridged mobile commands to AWS IoT Core securely by utilizing Supabase Webhooks and Deno Edge Functions to dispatch MQTT payloads asynchronously, ensuring reliable delivery.

Frontend & UX

  • Built a cross-platform React Native Expo app (thesis_emblematic) with real-time telemetry gauges (pH, optical turbidity NTU, rain sensor level, tank volume, active state machine step).
  • Designed interactive real-time line charts powered by React Native Skia and Gifted Charts to track water quality trends and sensor historical telemetry.
  • Integrated interactive relay actuator toggles with safety debouncing and developed a remote PID tuning interface to calibrate Kp, Ki, and Kd constants via JSON-formatted MQTT payloads on-the-fly.

Challenges & Technical Solutions

01Challenge

Analog pH and turbidity sensors experienced severe electrical interference and voltage drift when raw water pumps operated.

Solution

Decoupled ADC sampling via an I2C ADS1115 16-bit module and applied dynamic 21-sample median filtering combined with a 20-sample moving average smoothing algorithm.

02Challenge

Chemical over-dosing and extreme pH overshoot caused by relay-driven pumps functioning on simple bang-bang logic.

Solution

Implemented a Time-Proportioned PID algorithm that scales relay activation duration relative to the real-time pH error, drastically smoothing the approach to the target setpoint.

03Challenge

Unreliable MQTT broker connection drops on ESP32 due to intermittent Wi-Fi access point restarts.

Solution

Developed a non-blocking background connection manager on the ESP32 that maintains offline state machine operation while attempting automatic exponential backoff MQTT reconnects.