Skip to content
BeginnerESP8266 / NodeMCUESP8266ESP32WATER 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 2 views
Source code
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++

Get new projects straight to your inbox

Arduino, ESP32 & IoT tutorials โ€” new builds, firmware tips, Wokwi guides. No spam.

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

Q&A is disabled for this project.

Related projects