ESP32 S3 - Water Sensor

Learn how to interface a water level sensor with your ESP32 S3 to detect water leakage, rainfall, tank overflow, and measure water levels in this beginner-friendly Arduino tutorial.

What you'll build:

  1. A water level reader that outputs raw analog values to Serial Monitor
  2. A water leakage detector that lights an LED when water is present
  3. A multi-level water depth monitor categorizing levels from empty to high
  4. A calibrated sensor setup for accurate real-world water level measurements
ESP32 S3 - Water Sensor

Hardware Preparation

1×ESP32 S3 WROOM N16R8
1×USB Cable Type-A to Type-C (for USB-A PC)
1×USB Cable Type-C to Type-C (for USB-C PC)
1×Water level sensor
1×Breadboard
1×Jumper Wires
1×Optionally, DC Power Jack

Or you can buy the following kits:

1×DIYables Sensor Kit (18 sensors/displays)
Disclosure: Some of the links provided in this section are Amazon affiliate links. We may receive a commission for any purchases made through these links at no additional cost to you.
Additionally, some of these links are for products from our own brand, DIYables .

Overview of Water Level Sensor

A water level sensor is an analog sensor that detects the presence and depth of water by measuring resistance between exposed conductive traces on its PCB. As water bridges more of these traces, electrical resistance decreases and the output voltage rises proportionally. This makes it straightforward to pair with the ESP32 S3's built-in ADC for a range of water detection and measurement applications.

Key Specifications

The sensor operates on either 3.3V or 5V, making it directly compatible with the ESP32 S3's logic levels without any level-shifting circuitry. It exposes three pins — Signal, VCC, and GND — and outputs an analog voltage that scales with the depth of water contact. The sensing area consists of alternating conductive traces; only this exposed region should be immersed in water, keeping the onboard electronics dry at all times.

Water Level Sensor Pinout

The water level sensor has three pins for connection to your ESP32 S3.

  1. S (Signal) pin: Outputs an analog voltage proportional to the water level — connect to an ESP32 S3 analog input pin
  2. + (VCC) pin: Power supply pin — connect to 3.3V or a GPIO configured as a digital output for power-managed readings
  3. - (GND) pin: Ground reference — connect to GND
water sensor pinout

How Water Level Sensor Works

The sensor operates on the principle of variable electrical conductivity. When the exposed traces are dry, almost no current flows between them, producing a near-zero output voltage. As water rises and covers progressively more traces, conductivity increases and the output voltage climbs toward the supply rail. The ESP32 S3 reads this varying analog voltage through its ADC and converts it to a numeric value that reflects the current water depth.

Wiring Diagram

Connect the water sensor to your ESP32 S3 carefully to ensure reliable readings and long sensor lifespan. Because constant power causes electrochemical corrosion on the exposed traces, the VCC pin should be driven by a GPIO output rather than a permanent 3.3V rail — this way the firmware can cut power between readings.

Safety Notes

Power the sensor's VCC pin from a digital GPIO output pin rather than from the board's 3.3V pin. Enable that GPIO only for the brief moment needed to take a reading, then pull it low immediately afterward. Never submerge the sensor beyond the exposed trace region; the PCB electronics and the connector end must remain completely dry at all times.

Water Sensor Pin ESP32 S3 Pin
S (Signal) GPIO12 (Analog Input)
+ (VCC) GPIO14 (Digital Output for Power Control)
* (GND) GND
The wiring diagram between ESP32 S3 Water Sensor

This image is created using Fritzing. Click to enlarge image

ESP32 S3 Code - Reading Value from Water Sensor

The following code reads the raw analog value from the water sensor on your ESP32 S3 and prints it to the Serial Monitor. It controls power to the sensor via a digital GPIO pin, energising the sensor only during the measurement window to minimise electrochemical corrosion on the exposed traces. After taking a reading the firmware immediately cuts power, keeping the sensor in good condition for longer-term deployments.

/* * This ESP32 S3 code was developed by newbiely.com * * This ESP32 S3 code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/esp32-s3/esp32-s3-water-sensor */ #define POWER_PIN 14 // The ESP32 S3 pin 14 connected to sensor's VCC pin #define SIGNAL_PIN 12 // The ESP32 S3 pin 12 connected to sensor's signal pin int value = 0; // variable to store the sensor value void setup() { Serial.begin(115200); // set the ADC attenuation to 11 dB (up to ~3.3V input) analogSetAttenuation(ADC_11db); pinMode(POWER_PIN, OUTPUT); // Configure pin as an OUTPUT digitalWrite(POWER_PIN, LOW); // turn the sensor OFF } void loop() { digitalWrite(POWER_PIN, HIGH); // turn the sensor ON delay(10); // wait 10 milliseconds value = analogRead(SIGNAL_PIN); // read the analog value from sensor digitalWrite(POWER_PIN, LOW); // turn the sensor OFF Serial.print("The water sensor value: "); Serial.println(value); delay(1000); }

Detailed Instructions

  1. New to ESP32 S3? Complete our Getting Started with ESP32 S3 guide first.
  2. Wire the sensor to the ESP32 S3 following the table in the Wiring Diagram section above.
  3. Copy the code above and paste it into the Arduino IDE.
  4. Select your ESP32 S3 board and the correct COM port under the Tools menu.
  5. Click the Upload button to compile and flash the sketch to your board.
  6. Prepare a glass or bowl of water for sensor testing.
  7. Open the Serial Monitor and set the baud rate to 115200.
  8. Slowly dip the sensing traces into the water, starting from the bottom, and watch the values climb.
  9. Observe that values return toward zero when you lift the sensor out of the water.
  10. Pro Tip: Keep the sensor's PCB electronics and connector completely above the waterline — only the exposed conductive traces at the tip should contact water.
Newbiely | Arduino IDE 2.3.8
──
File
Edit
Sketch
Tools
Help
ESP32S3 Dev Module
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'ESP32S3 Dev Module' on 'COM15')
New Line
9600 baud
[2026-06-16 09:12:01] The water sensor value: 0 [2026-06-16 09:12:02] The water sensor value: 0 [2026-06-16 09:12:03] The water sensor value: 28 [2026-06-16 09:12:04] The water sensor value: 204 [2026-06-16 09:12:05] The water sensor value: 591 [2026-06-16 09:12:06] The water sensor value: 628 [2026-06-16 09:12:07] The water sensor value: 1441 [2026-06-16 09:12:08] The water sensor value: 1452 [2026-06-16 09:12:09] The water sensor value: 1470 [2026-06-16 09:12:10] The water sensor value: 2521 [2026-06-16 09:12:11] The water sensor value: 2529 [2026-06-16 09:12:12] The water sensor value: 2561
Ln 11, Col 1
ESP32S3 Dev Module on COM15
2

※ NOTE THAT:

The water sensor is not designed to be completely submerged. Only the exposed traces on the PCB should contact water. Please install and test the sensor carefully to avoid damaging the electronics.

How To Detect Water Leakage

Water leakage detection works by comparing the sensor's analog reading against a threshold value established during calibration. When the reading exceeds the threshold the firmware treats that as a leak event and can trigger an alert — in this example, a visible LED indicator. This pattern is the foundation for more sophisticated leak detection systems such as Wi-Fi notifications or automated shut-off valves.

Wiring Diagram

Component ESP32 S3 Pin
Water Sensor S GPIO12 (Analog Input)
Water Sensor + GPIO14 (Digital Output)
Water Sensor - GND
LED Anode (+) GPIO4 (through 220Ω resistor)
LED Cathode (-) GND
The wiring diagram between ESP32 S3 Water Sensor LED

This image is created using Fritzing. Click to enlarge image

ESP32 S3 Code - Detecting Water Leakage

The following code continuously monitors the water sensor and compares each reading to a configured threshold. When the sensor value rises above that threshold the ESP32 S3 switches the LED on to signal a leak; when the value drops back below the threshold the LED turns off. The current detection status is also printed to the Serial Monitor so you can observe the system's response in real time.

/* * This ESP32 S3 code was developed by newbiely.com * * This ESP32 S3 code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/esp32-s3/esp32-s3-water-sensor */ #define LED_PIN 2 // The ESP32 S3 pin 2 connected to LED pin #define POWER_PIN 14 // The ESP32 S3 pin 14 connected to sensor's VCC pin #define SIGNAL_PIN 12 // The ESP32 S3 pin 12 connected to sensor's signal pin #define THRESHOLD 1000 int value = 0; // variable to store the sensor value void setup() { Serial.begin(115200); // set the ADC attenuation to 11 dB (up to ~3.3V input) analogSetAttenuation(ADC_11db); pinMode(LED_PIN, OUTPUT); // Configure pin as an OUTPUT pinMode(POWER_PIN, OUTPUT); // Configure pin as an OUTPUT digitalWrite(POWER_PIN, LOW); // turn the sensor OFF digitalWrite(LED_PIN, LOW); // turn LED OFF } void loop() { digitalWrite(POWER_PIN, HIGH); // turn the sensor ON delay(10); // wait 10 milliseconds value = analogRead(SIGNAL_PIN); // read the analog value from sensor digitalWrite(POWER_PIN, LOW); // turn the sensor OFF if (value > THRESHOLD) { Serial.print("The water is detected"); digitalWrite(LED_PIN, HIGH); // turn LED ON } else { digitalWrite(LED_PIN, LOW); // turn LED OFF } }

How To Measure The Water Level

This example divides the full measurement range into four named categories — Empty, Low, Medium, and High — to give human-readable depth information rather than a raw numeric value. The firmware maps the calibrated sensor range onto these four levels and prints the current level name to the Serial Monitor each time a reading is taken.

/* * This ESP32 S3 code was developed by newbiely.com * * This ESP32 S3 code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/esp32-s3/esp32-s3-water-sensor */ #define LED_PIN 2 // The ESP32 S3 pin 2 connected to LED pin #define POWER_PIN 14 // The ESP32 S3 pin 14 connected to sensor's VCC pin #define SIGNAL_PIN 12 // The ESP32 S3 pin 12 connected to sensor's signal pin #define THRESHOLD 1000 int value = 0; // variable to store the sensor value void setup() { Serial.begin(115200); // set the ADC attenuation to 11 dB (up to ~3.3V input) analogSetAttenuation(ADC_11db); pinMode(LED_PIN, OUTPUT); // Configure pin as an OUTPUT pinMode(POWER_PIN, OUTPUT); // Configure pin as an OUTPUT digitalWrite(POWER_PIN, LOW); // turn the sensor OFF digitalWrite(LED_PIN, LOW); // turn LED OFF } void loop() { digitalWrite(POWER_PIN, HIGH); // turn the sensor ON delay(10); // wait 10 milliseconds value = analogRead(SIGNAL_PIN); // read the analog value from sensor digitalWrite(POWER_PIN, LOW); // turn the sensor OFF if (value > THRESHOLD) { Serial.print("The water is detected"); digitalWrite(LED_PIN, HIGH); // turn LED ON } else { digitalWrite(LED_PIN, LOW); // turn LED OFF } }

※ NOTE THAT:

  • SENSOR_MIN and SENSOR_MAX are determined by the calibration process described in the section below.
  • The linear mapping method used here is not perfectly precise, but it is acceptable for most practical applications.

Water Level Sensor Calibration

Accurate water level readings require calibrating the sensor against your specific setup because raw ADC values vary between individual sensors and ESP32 S3 boards. Record the output value when the traces are completely dry — this is SENSOR_MIN — then immerse just the trace region fully and record the maximum value as SENSOR_MAX. Enter both constants into your sketch to make the mapping functions work correctly for your environment.

See how to calibrate the water level sensor

※ NOTE THAT:

This tutorial uses the analogRead() function to read values from an ADC (Analog-to-Digital Converter). The ESP32 S3's built-in ADC is adequate for projects that do not require high accuracy. For projects that need precise measurements, keep the following in mind:

  • The ESP32 S3's ADC is not perfectly linear and may require calibration for accurate results. Each individual board can vary slightly, so calibration should be performed per board.
  • ADC calibration can be challenging for beginners and may not yield perfect precision in all cases.

For applications requiring high precision, consider pairing the ESP32 S3 with an external ADC such as the ADS1115. If you wish to calibrate the ESP32 S3's internal ADC, refer to the ESP32 ADC Calibration Driver.

Application Ideas

The combination of an ESP32 S3 and a water level sensor opens the door to a wide range of practical monitoring and automation projects.

  1. Basement flood detector: Alerts a smartphone via Wi-Fi the moment water is detected on the floor.
  2. Automatic plant watering system: Monitors soil moisture or reservoir level and triggers a pump as needed.
  3. Aquarium water level monitor: Detects evaporation and activates an auto-refill valve to maintain a safe water line.
  4. DIY rain gauge: Measures accumulated rainfall depth for a home weather station.
  5. Coffee maker drip tray alert: Prevents overflow by warning when the drip tray approaches capacity.
  6. Sump pump monitor: Detects pump failure by watching for rising water that should have been evacuated.

Video Tutorial

Watch the step-by-step video walkthrough for this ESP32 S3 project below.

Challenge Yourself

Now that your water sensor is working, push the project further by taking on one of these progressively harder challenges.

  1. Beginner: Add a buzzer that beeps when water is detected above the threshold.
  2. Beginner: Display the water level as a percentage of the calibrated range on the Serial Monitor instead of the raw ADC value.
  3. Intermediate: Build a Wi-Fi-enabled leak detector that sends an email or push notification when water is detected.
  4. Intermediate: Create a multi-sensor system that monitors several locations simultaneously and reports each one individually.
  5. Advanced: Design an automatic water tank filling system that uses upper and lower level sensors to control a relay-driven pump.
  6. Advanced: Build a data logging system that records water level readings over time and displays a trend graph on a web dashboard served by the ESP32 S3.

※ OUR MESSAGES

  • As freelancers, We are AVAILABLE for HIRE. See how to outsource your project to us
  • Please feel free to share the link of this tutorial. However, Please do not use our content on any other websites. We invested a lot of effort and time to create the content, please respect our work!