Skip to content

Navigation Menu

Sign in
Sign up

Latest commit

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

🌊 AquaSync β€” Automatic pH Stabilization System

ESP32-based real-time water pH monitoring & auto-dosing system with a live web dashboard

Platform Language Backend License Status


πŸ“– About The Project

AquaSync is an automatic system for keeping water pH stable, built with an ESP32, a pH 4502C sensor, and two dosing pumps (acid & base) controlled through an L298N motor driver. The system reads the water's pH periodically, and whenever the pH drifts outside the neutral range, the ESP32 automatically pumps the appropriate neutralizing solution (acid or base) in small, gradual doses (pulse dosing) until the pH stabilizes again.

All sensor data and pump status are sent in real time to a Flask-based web dashboard, so the water condition can be monitored directly from a browser β€” complete with a pH gauge, pump status, and reading history.


✨ Features

  • πŸ§ͺ Real-time pH readings averaged over 20 ADC samples for stable results
  • βš–οΈ Hysteresis-based auto-dosing β€” prevents the pumps from rapidly toggling on/off near the threshold (threshold chattering)
  • πŸ’§ Pulse dosing β€” solution is pumped for a short burst followed by a mixing delay, preventing overdosing
  • πŸ”’ Safety interlock β€” the acid and base pumps can never be active at the same time
  • πŸ“Ά WiFi auto-reconnect if the connection drops
  • πŸ–₯️ Real-time web dashboard (auto-refreshes every 0.5 seconds) with a pH gauge, pump status, and a log of the last 5 readings
  • 🟒 Online/offline status detection based on the time since the last data was received

πŸ“Έ Dashboard Preview

The dashboard displays the real-time pH value, raw sensor voltage & ADC, the status of both pumps (base/acid), and a log of the last 5 pH readings along with the water condition (Acidic/Neutral/Basic).


πŸ› οΈ Hardware Used

Component Qty Notes
ESP32 DevKit 1 Main microcontroller
pH 4502C sensor + probe 1 Analog water pH reading
L298N Motor Driver 1 Dual channel β€” drives 2 DC pumps
12V DC Water Pump 2 Dosing pumps for base & acid solution
12V Power Supply 1 Power for pumps & driver
pH buffer solutions (4.01 / 6.86 / 9.18) - For sensor calibration

πŸ”Œ Wiring Diagram

πŸ“Œ The full pin mapping (GPIO to each component) is available in docs/wiring.md.

🧩 Prototype


🧠 How It Works

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” ADC Sampling β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ pH Sensor β”‚ ───────────────────▢ β”‚ ESP32 (Loop) β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ (20 samples/2 sec) β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
 β”‚
 pH < 6.5? β”‚ pH > 8.5?
 β–Ό
 β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
 β”‚ Pulse Dosing State β”‚
 β”‚ Machine (Hysteresis)β”‚
 β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
 β”‚
 Pump ON (2 sec) β†’ OFF β†’ Wait (5 sec)
 β”‚
 β–Ό
 β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
 β”‚ HTTP POST /api/ β”‚
 β”‚ update β†’ Flask Serverβ”‚
 β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
 β”‚
 β–Ό
 β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
 β”‚ Web Dashboard β”‚
 β”‚ (auto-refresh 0.5s) β”‚
 β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Hysteresis logic used:

Condition Base Pump ON Base Pump OFF Acid Pump ON Acid Pump OFF
pH Threshold < 6.50 β‰₯ 6.80 > 8.50 ≀ 8.20

The "buffer" range between the ON and OFF values prevents the pumps from rapidly switching on and off when the pH sits right at the threshold.


πŸ“‚ Project Structure

aquasync-ph-stabilizer/
β”œβ”€β”€ firmware/
β”‚ └── aquasync_firmware.ino # Main ESP32 code
β”œβ”€β”€ server/
β”‚ β”œβ”€β”€ app.py # Flask web server (dashboard + API)
β”‚ └── requirements.txt
β”œβ”€β”€ docs/
β”‚ β”œβ”€β”€ wiring.md # GPIO pin mapping details
β”‚ └── images/
β”œβ”€β”€ .gitignore
β”œβ”€β”€ LICENSE
└── README.md

πŸš€ Installation & Usage

1. Set Up the Web Server (Flask)

cd server
pip install -r requirements.txt
python app.py

The server will run at http://<your-computer-IP>:5000. Open it in a browser to view the dashboard.

2. Set Up the ESP32 Firmware

  1. Open the firmware/aquasync_firmware.ino file in Arduino IDE
  2. Install the required library: ArduinoJson
  3. Configure below based on your address
    const char* WIFI_SSID = "YOUR_WIFI_SSID";
    const char* WIFI_PASSWORD = "YOUR_WIFI_PASSWORD";
    const char* SERVER_URL = "http://<your-computer-IP>:5000/api/update";
  4. Upload aquasync_firmware.ino to the ESP32
  5. Open the Serial Monitor (115200 baud) to view sensor reading logs

3. pH Sensor Calibration

Use pH buffer solutions 4.01, 6.86, and 9.18 to calibrate the sensor, then adjust the PH_SLOPE and PH_INTERCEPT values in the firmware based on the voltage measured for each solution.


πŸ”§ Configurable Parameters

Parameter Default Description
PUMP_SPEED 150/255 Pump PWM speed
DOSE_ON_MS 2000 ms Pump active duration per dose
DOSE_WAIT_MS 5000 ms Mixing delay after a dose
INTERVAL_SENSOR 2000 ms Sensor reading interval
INTERVAL_HTTP 500 ms Data-sending interval to the server

πŸ“„ License

See the LICENSE file for details.


πŸ™‹ Contributors


Built with πŸ’§ for smarter water monitoring

About

AquaSync is an ESP32-based automatic water pH stabilization system that monitors water quality using a pH sensor and maintains a neutral pH through pulse dosing with acid and base pumps. The system provides real-time monitoring and control via a Flask web dashboard.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /