Skip to content
BeginnerESP8266esp8266esp32water-level-monitor

Water Level Monitor

A self-hosted water tank monitoring system using an ESP8266 and HS-S37P water depth sensor, serving a live dashboard on your local network.

Ksp_wirespace7/7/2026 10 min read 8 views
Water Level Monitor

πŸ’§ 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

ComponentDetails
ESP8266NodeMCU or Wemos D1 Mini
HS-S37PWater depth / level sensor
BuzzerActive buzzer (3.3V or 5V)
Jumper wiresMale-to-female
Power supplyUSB 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

  1. Open aquawatch_esp8266.ino in Arduino IDE
  2. Install required libraries if not already present:
    • ESP8266WiFi (comes with ESP8266 board package)
    • ESP8266WebServer (comes with ESP8266 board package)
  3. Set your WiFi credentials:
    const char* ssid     = "Your_WiFi_Name";
    const char* password = "Your_Password";
    
  4. Select your board: Tools β†’ Board β†’ NodeMCU 1.0 (or your variant)
  5. 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:

  1. Open Serial Monitor at 115200 baud
  2. Dip the sensor to each line, one at a time, and note the ADC value printed
  3. 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

  1. Open water_dashboard.html in any browser on the same WiFi network
  2. Enter the device IP in the Device IP field (e.g. 192.168.1.105)
  3. 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 – 500%
Line 1 (bottom)50 – 20025%
Line 2200 – 35050%
Line 3350 – 45075%
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"
}
FieldDescription
levelRaw ADC value (0–1023)
waterLevelDetected level 0–4
thresholdADC value for Level 4 trigger
percentPercentage (waterLevel Γ— 25)
isFulltrue when Level 4 is reached
statusDRY / NORMAL / HIGH / FULL

βš™οΈ Configuration Reference

Firmware (aquawatch_esp8266.ino)

ConstantDefaultDescription
LEVEL1_MIN50ADC threshold for Level 1
LEVEL2_MIN200ADC threshold for Level 2
LEVEL3_MIN350ADC threshold for Level 3
LEVEL4_MIN450ADC threshold for Level 4 (buzzer)
BEEP_ON_MS250Buzzer ON duration per beep (ms)
BEEP_OFF_MS300Buzzer OFF duration per beep (ms)

Dashboard (water_dashboard.html)

Settings are entered directly in the UI:

FieldDescription
Device IPIP 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 LabelGPIOUsed for
A0ADC0Sensor signal (S)
D2GPIO4Buzzer (+)

πŸ“œ License

MIT β€” free to use, modify, and distribute.


Built with ESP8266 Arduino Core Β· No cloud dependencies

C++

Water level monitor: calibration, installation, and fault checks

Choose the correct sensing method

Confirm whether this build uses a float switch, conductive probes, an ultrasonic sensor, or another level sensor. These methods do not produce interchangeable outputs: a float switch is usually a discrete high/low signal, while an ultrasonic sensor estimates distance to the surface. Use the method and pin assignments defined by the project sketch; do not copy wiring for a different sensor type.

Calibrate the measurement

For a distance-based design, measure the sensor-to-bottom distance and the empty-tank reference distance before converting distance into a level or percentage. Keep the sensor aligned vertically and avoid measuring through a narrow opening that causes echoes. For a float switch, test its open/closed state manually before installation and confirm whether the input needs a pull-up or pull-down. Define explicit low, normal, and high thresholds, and add hysteresis or a short confirmation interval so a wavering surface does not cause rapid status changes.

Installation and electrical safety

Keep the controller and exposed connections away from splashes and condensation. Use a suitable enclosure, cable strain relief, and sensor materials compatible with the liquid. Never immerse a sensor or module unless it is rated for that use. If the monitor controls a pump, drive it through a correctly rated relay or motor driver, never directly from a GPIO. Set a safe default state during boot and provide an independent overflow or dry-run safeguard where the consequences of failure matter.

Commissioning checklist

  1. Test the sensor with the tank empty, partly filled, and near the intended maximum level.
  2. Compare displayed values with a manual measurement and record the error.
  3. Restart the controller and verify that outputs start in a safe state.
  4. Disconnect the sensor briefly and confirm the fault is reported rather than interpreted as a valid level.
  5. If a pump is controlled, test switching with the pump load safely isolated before the full wet test.

Troubleshooting

  • Level is stuck: inspect sensor power, wiring, input mode, and the code’s selected pin.
  • Ultrasonic values jump: check mounting angle, condensation, surface turbulence, and minimum measurement distance.
  • Float state is inverted: confirm switch wiring and active-high/active-low logic.
  • Pump chatters near a threshold: add hysteresis and verify the sensor is not fluctuating around the setpoint.
  • Controller resets when a pump starts: inspect supply sizing, inductive suppression, grounding, and driver wiring.

Document the sensor model, reference dimensions, threshold values, and any failure behavior so another builder can reproduce the installation.

Build Sheet

Take this build with you

We'll email you the parts list for Water Level Monitor, with buy links and the Wokwi and source links, so you can order and build later. You'll also get new builds as they're published.

By subscribing you agree to our Privacy Policy. Unsubscribe anytime.

Q&A is currently disabled site-wide.

Related projects