๐ง AquaWatch โ ESP8266 Water Level Monitor
A self-hosted water tank monitoring system using an ESP8266 and HS-S37P water depth sensor.your device serving a live dashboard on your local network.
๐ธ Features
- 4-level water detection using the HS-S37P analog sensor
- Animated tank visualization on a live web dashboard
- Buzzer alert triggers when water reaches Level 4 (top line)
- Full-screen popup alert on the dashboard when tank is full
- Live history chart of sensor readings
- Self-hosted โ ESP8266 runs its own web server, no internet needed
- Demo mode โ dashboard previews with simulated data when not connected
๐งฐ Hardware Required
| Component | Details |
|---|---|
| ESP8266 | NodeMCU or Wemos D1 Mini |
| HS-S37P | Water depth / level sensor |
| Buzzer | Active buzzer (3.3V or 5V) |
| Jumper wires | Male-to-female |
| Power supply | USB or 5V adapter |
๐ Wiring
HS-S37P Sensor ESP8266
โโโโโโโโโโโโโโ โโโโโโโ
S โโโโโโโโโโโโโโโบ A0 (analog signal)
+ โโโโโโโโโโโโโโโบ 3.3V (VCC)
G โโโโโโโโโโโโโโโบ GND
Buzzer ESP8266
โโโโโโโโโโโโโโ โโโโโโโ
+ โโโโโโโโโโโโโโโบ D2 / GPIO4
- โโโโโโโโโโโโโโโบ GND
Note: The HS-S37P has 4 exposed sensing traces. As water rises and bridges more traces, the analog voltage on A0 increases in steps.
๐ Setup Guide
1. Flash the Firmware
- Open
aquawatch_esp8266.inoin Arduino IDE - Install required libraries if not already present:
ESP8266WiFi(comes with ESP8266 board package)ESP8266WebServer(comes with ESP8266 board package)
- Set your WiFi credentials:
const char* ssid = "Your_WiFi_Name"; const char* password = "Your_Password"; - Select your board: Tools โ Board โ NodeMCU 1.0 (or your variant)
- Upload the sketch
2. Calibrate the Sensor
The HS-S37P gives a rising ADC value as more of the sensor is submerged. You need to find the ADC value at each of the 4 sensor lines:
- Open Serial Monitor at
115200baud - Dip the sensor to each line, one at a time, and note the ADC value printed
- Update the thresholds in the firmware:
#define LEVEL1_MIN 50 // ADC > this โ Level 1 (bottom line)
#define LEVEL2_MIN 200 // ADC > this โ Level 2
#define LEVEL3_MIN 350 // ADC > this โ Level 3
#define LEVEL4_MIN 515 // ADC > this โ Level 4 โ buzzer triggers here
These are typical values for a 3.3V supply. Your sensor may vary โ always calibrate.
3. Find the Device IP
After flashing, open Serial Monitor. You will see:
AquaWatch โ HS-S37P 4-Level Build
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Connected!
IP: 192.168.1.105
Server ready.
Note the IP address.
4. Open the Dashboard
- Open
water_dashboard.htmlin any browser on the same WiFi network - Enter the device IP in the Device IP field (e.g.
192.168.1.105) - Click Connect โ the dashboard starts polling every second
๐ How the Sensor Works
The HS-S37P is not a true ultrasonic depth sensor. It works by detecting electrical conductivity between exposed copper traces on the sensor PCB. As water rises:
| Water touches... | ADC range (approx) | Level shown |
|---|---|---|
| Nothing (dry) | 0 โ 50 | 0% |
| Line 1 (bottom) | 50 โ 200 | 25% |
| Line 2 | 200 โ 350 | 50% |
| Line 3 | 350 โ 450 | 75% |
| Line 4 (top) | 450+ | 100% ๐จ |
When Level 4 is reached:
- Buzzer beeps (250ms on / 300ms off pattern)
- Dashboard tank turns red
- Full-screen alert popup appears with an ACKNOWLEDGE button
๐ API Endpoint
The ESP8266 serves a JSON endpoint at http://<device-ip>/data:
{
"level": 600,
"waterLevel": 4,
"threshold": 515,
"percent": 100,
"isFull": true,
"status": "FULL"
}
| Field | Description |
|---|---|
level | Raw ADC value (0โ1023) |
waterLevel | Detected level 0โ4 |
threshold | ADC value for Level 4 trigger |
percent | Percentage (waterLevel ร 25) |
isFull | true when Level 4 is reached |
status | DRY / NORMAL / HIGH / FULL |
โ๏ธ Configuration Reference
Firmware (aquawatch_esp8266.ino)
| Constant | Default | Description |
|---|---|---|
LEVEL1_MIN | 50 | ADC threshold for Level 1 |
LEVEL2_MIN | 200 | ADC threshold for Level 2 |
LEVEL3_MIN | 350 | ADC threshold for Level 3 |
LEVEL4_MIN | 450 | ADC threshold for Level 4 (buzzer) |
BEEP_ON_MS | 250 | Buzzer ON duration per beep (ms) |
BEEP_OFF_MS | 300 | Buzzer OFF duration per beep (ms) |
Dashboard (water_dashboard.html)
Settings are entered directly in the UI:
| Field | Description |
|---|---|
| Device IP | IP address of your ESP8266 |
| Full Threshold (ADC) | Reference ADC value shown in stats |
๐ ๏ธ Troubleshooting
Buzzer beeps immediately on power-up โ That is intentional โ a single short beep on startup confirms the buzzer works.
ADC reads random values / sensor noisy โ Add a 10kฮฉ pull-down resistor between A0 and GND. Also ensure stable 3.3V supply.
Dashboard shows "Disconnected"
โ Make sure your browser and ESP8266 are on the same WiFi network. Some browsers block HTTP fetch from a local file โ try serving the HTML via a local server or use the ESP8266's / page directly.
Sensor degrading over time โ The HS-S37P copper traces corrode with prolonged water contact. For longer life, only insert the sensor into water when needed, or coat the non-sensing back side with silicone sealant.
Compilation error: 'D2' not declared
โ The firmware uses raw GPIO numbers (#define BUZZER_PIN 4) instead of Arduino-style macros to avoid this. If you change pins, use the GPIO number, not the D-label (e.g. D2 = GPIO4, D1 = GPIO5).
๐ Pin Reference (NodeMCU)
| NodeMCU Label | GPIO | Used for |
|---|---|---|
| A0 | ADC0 | Sensor signal (S) |
| D2 | GPIO4 | Buzzer (+) |
๐ License
MIT โ free to use, modify, and distribute.
Built with ESP8266 Arduino Core ยท No cloud dependencies