ESP32-based water level monitoring system with configurable single/dual tank modes, web configuration, MQTT, BLE, and automatic pump control.
pio run -e esp32devThe project uses the published IonConnect library from PlatformIO registry.
- Wire JSN-SR04T sensor(s) to ESP32 (see wiring diagram in docs)
- Connect OLED display (I2C)
- Connect pump relay module
β οΈ Important: Use voltage divider on Echo pins (5Vβ3.3V)
pio run --target upload -e esp32dev
pio device monitor- Connect to WiFi:
IonConnect-XXXX - Browser automatically opens to
http://192.168.4.1 - Configure WiFi, tank dimensions, MQTT settings
- Save and device connects automatically
- OLED Display: Real-time tank levels and status
- Web Dashboard:
http://[device-ip]/ - MQTT: Subscribe to
water/level - BLE: Connect with nRF Connect app
β
Single or dual tank monitoring
β
JSN-SR04T waterproof ultrasonic sensors
β
Real-time measurements with median filtering
β
Configurable tank depth, units, and thresholds
β
OLED display with visual progress bars
β¨ Modern captive portal with beautiful responsive UI
β¨ Live dashboard with real-time status updates (SSE)
β¨ BLE provisioning for ESP32 (configure via Bluetooth)
β¨ REST API for programmatic access
β¨ Multi-network support with priority management
β¨ mDNS discovery (access via devicename.local)
β¨ Security features (password protection, API tokens)
β
MQTT publishing with JSON payloads and QoS
β
Automatic pump control with safety features:
- Dry-run protection (sensor error detection)
- Maximum runtime limits (prevents overflow)
- Cooldown periods (prevents motor damage)
- Auto/manual modes
β
OTA firmware updates (via web interface)
β
Configuration backup/restore (JSON export/import)
β
Diagnostics dashboard (memory, WiFi stats, errors)
β
Persistent storage (NVS on ESP32, LittleFS on ESP8266)
β
Web configuration (no hardcoding required!)
- ESP32 DevKit (WROOM-32 or compatible) - Dual core with BLE
- ESP32-S2 (Saola-1 or compatible) - Single core, WiFi only (no BLE)
- ESP8266 (Wemos D1 Mini Pro) - Single core, WiFi only, 80MHz
- JSN-SR04T waterproof ultrasonic sensor (1-2Γ)
- SSD1306 OLED 0.96" I2C display
- Relay module for pump control
- Voltage divider (10kΞ© + 20kΞ© resistors) for Echo pins
- 5V power supply (2A recommended)
Tank 1 Sensor: TRIG=GPIO25, ECHO=GPIO26
Tank 2 Sensor: TRIG=GPIO32, ECHO=GPIO33
OLED Display: SDA=GPIO21, SCL=GPIO22
Pump Relay: GPIO27
Status LED: GPIO2
Tank 1 Sensor: TRIG=GPIO10, ECHO=GPIO11
Tank 2 Sensor: TRIG=GPIO12, ECHO=GPIO13
OLED Display: SDA=GPIO8, SCL=GPIO9
Pump Relay: GPIO7
Status LED: GPIO15
Tank 1 Sensor: TRIG=GPIO14 (D5), ECHO=GPIO12 (D6)
Tank 2 Sensor: TRIG=GPIO13 (D7), ECHO=GPIO15 (D8)
OLED Display: SDA=GPIO4 (D2), SCL=GPIO5 (D1)
Pump Relay: GPIO0 (D3)
Status LED: GPIO2 (D4)
All pins configurable via web interface!
π docs/README.md - Complete project documentation
π§ͺ TESTING_GUIDE.md - Comprehensive testing procedures (11 scenarios)
π ION_CONNECT_INTEGRATION.md - IonConnect integration details
π COMPLETE_SUMMARY.md - Project overview and status
π EXECUTE_WORKFLOW.md - Complete build and deployment guide
π¦ PUBLISHING_STEPS.md - Library publishing instructions
- Detailed wiring diagrams for all supported boards
- Complete configuration guide via web interface
- API documentation (REST & MQTT)
- MQTT integration examples with QoS
- BLE characteristic reference (ESP32)
- Troubleshooting guide with solutions
- Home Assistant integration examples
- OTA update procedures
water-level/
βββ src/
β βββ main.cpp # Main application
β βββ config.h # Configuration constants
β βββ config_manager.* # NVS/LittleFS configuration storage
β βββ sensor_ultrasonic.* # Sensor driver with median filtering
β βββ display_oled.* # OLED display driver
β βββ wifi_ionconnect.* # IonConnect WiFi wrapper (NEW)
β βββ web_server.* # Web configuration interface
β βββ mqtt_client.* # MQTT client with auto-reconnect
β βββ ble_service.* # BLE GATT service (ESP32 only)
β βββ pump_controller.* # Pump control logic
βββ docs/
β βββ README.md # Complete documentation
βββ platformio.ini # PlatformIO configuration
βββ README.md # This file
Choose your board in platformio.ini:
# For ESP32 Classic (with BLE support):
default_envs = esp32dev
# For ESP32-S2 (WiFi only, no BLE):
default_envs = esp32s2dev
# For ESP8266 (Wemos D1 Mini Pro):
default_envs = d1_mini_proFeature | ESP32 Classic | ESP32-S2 | ESP8266
---------------------|---------------|-----------|----------
WiFi | β
| β
| β
MQTT | β
| β
| β
BLE | β
| β | β
Web Server | β
| β
| β
OLED Display | β
| β
| β
Pump Control | β
| β
| β
Dual Core Tasks | β
| β | β
Native USB | β | β
| β
CPU Speed | 240MHz | 240MHz | 80MHz
RAM | 327KB | 327KB | 80KB
Flash Usage | 55% (1.7MB) | 28% (883KB)| 42% (437KB)
Access at http://[device-ip]/ for:
- WiFi setup
- Tank calibration (dimensions, units)
- MQTT broker settings
- Pump control thresholds
- System status and monitoring
- OTA firmware upload
- Measure distance from sensor to tank bottom when empty β Enter as "Empty Distance"
- Fill tank to desired "full" level
- Measure distance from sensor to water surface β Enter as "Full Distance"
Example:
- Sensor mounted 200cm above tank bottom
- Full level is 10cm below sensor
- Configuration: Empty=200cm, Full=10cm
# Get status
curl http://[device-ip]/api/status
# Control pump
curl -X POST http://[device-ip]/api/pump -d '{"action":"on"}'# Subscribe to readings
mosquitto_sub -h mqtt.example.com -t "water/level"
# Control pump
mosquitto_pub -h mqtt.example.com -t "water/command" -m '{"command":"pump_on"}'Connect to service UUID: 4fafc201-1fb5-459e-8fcc-c5c9c331914b
- Tank 1 Level:
beb5483e-36e1-4688-b7f5-ea07361b26a8 - Tank 2 Level:
beb5483e-36e1-4688-b7f5-ea07361b26a9 - Pump Control:
beb5483e-36e1-4688-b7f5-ea07361b26aa
π‘οΈ Pump Protection:
- Dry-run protection (stops if source tank low)
- Maximum run time limits
- Minimum run time enforcement
- Cooldown periods between cycles
- Emergency stop on errors
π‘οΈ Sensor Monitoring:
- Median filtering (5 samples)
- Timeout detection
- Health status tracking
- Error recovery
Sensor not reading?
- Check voltage divider on Echo pin (must reduce 5V to ~1.6V)
- Verify sensor has clear line-of-sight to water
- Ensure sensor is within range (25-450cm for JSN-SR04T)
Can't connect to WiFi portal?
- SSID:
WaterMonitor_Setup - Password:
12345678 - Direct URL:
http://192.168.4.1
MQTT not connecting?
- Verify broker address and port
- Check username/password (if authentication enabled)
- Test with MQTT client tool first
See docs/README.md for comprehensive troubleshooting.
- Navigate to System tab
- Upload
.binfirmware file
pio run --target upload --upload-port [device-ip]Default OTA password: admin123 (change in config.h!)
Future enhancements:
- Offline Configuration Console - Physical button interface (4-6 buttons + OLED menu) for WiFi-free setup in field deployments
- Blynk integration
- Pressure sensor support
- Data logging to SD card
- Email/SMS alerts via IFTTT
- Multi-language web interface
- Mobile app (iOS/Android)
- Battery monitoring
- Solar panel integration
- Historical data graphs
This project uses IonConnect - a next-generation WiFi provisioning library for ESP32/ESP8266.
Modern User Experience:
- π¨ Beautiful responsive web interface (Tailwind CSS)
- π± Mobile-first design, perfect on all devices
- π Live status updates via Server-Sent Events
- β‘ Fast, async, non-blocking operation
Advanced Features:
- π‘ BLE Provisioning - Configure via Bluetooth (ESP32)
- π REST API - Programmatic configuration access
- πΎ Config Backup/Restore - JSON export/import
- π mDNS Support - Access via
devicename.local - π Diagnostics Dashboard - System health monitoring
- π Security - Password protection and API tokens
- π‘ Multi-Network - Store and prioritize multiple WiFi networks
Developer Friendly:
- π Plugin architecture for extensibility
- π Comprehensive documentation
- π― 9 working examples included
- π Active maintenance and updates
- π€ Community-driven improvements
PlatformIO (Already included):
lib_deps = coderunner/IonConnect@^1.0.2Arduino IDE:
# Library Manager: Search "IonConnect"- Library: https://registry.platformio.org/libraries/coderunner/IonConnect
- Documentation: See
/IonConnect/README.mdin workspace - Integration Guide: See
/IonConnect/INTEGRATION.md
MIT License - See LICENSE file for details
Built with:
- ESP32 Arduino Framework
- PlatformIO
- Adafruit GFX & SSD1306 libraries
- PubSubClient (MQTT)
- ESPAsyncWebServer
- ArduinoJson
Made with β€οΈ for the IoT community
Questions? Issues? Open a GitHub issue or check the full documentation.