ESP32 C3 Super Mini - Water Sensor

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

In this tutorial, you'll learn:

ESP32 C3 Super Mini - Water Sensor

Hardware Preparation

1×ESP32 C3 Super Mini
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 traces.

Key Features:

  • Outputs analog voltage proportional to water depth
  • Works with 3.3V or 5V power supply
  • Simple analog interface for easy ESP32 integration
  • Cost-effective solution for water detection projects
  • Ideal for beginners learning analog sensor interfacing

Why Use It:

  • Perfect for leak detection systems
  • Great for learning analog input reading on ESP32
  • Enables rainfall monitoring applications
  • Suitable for tank overflow prevention projects

Water Level Sensor Pinout

The water level sensor has three pins for easy connection to your ESP32 C3 Super Mini:

  • S (Signal) pin: Outputs analog voltage proportional to water level - connect to ESP32 analog input pin
  • + (VCC) pin: Power supply pin - connect to 3.3V or 5V
  • - (GND) pin: Ground pin - connect to GND
water sensor pinout

How Water Level Sensor Works

The water sensor operates on a simple principle of electrical conductivity:

  • The more water covering the exposed traces, the higher the output voltage
  • Dry sensor produces near-zero voltage output
  • Fully submerged traces produce maximum voltage
  • ESP32 reads this analog voltage to determine water level

Wiring Diagram

Here's how to connect your water sensor to the ESP32 C3 Super Mini for optimal performance and longevity.

Important Power Management:

  • Note: Constant power to the sensor causes electrochemical corrosion in moist environments
  • Note: Connect VCC to a digital pin instead of 3.3V for power control
  • Note: Turn power ON only when reading, then OFF to extend sensor lifespan
  • Note: Only the exposed traces should touch water - never fully submerge the sensor
Water Sensor Pin ESP32 C3 Super Mini Pin
S (Signal) GPIO2 (Analog Input)
+ (VCC) GPIO3 (Digital Output for Power Control)
* (GND) GND
The wiring diagram between ESP32 C3 Super Mini Water Sensor

This image is created using Fritzing. Click to enlarge image

ESP32 C3 Super Mini Code - Reading Value from Water Sensor

This Arduino sketch reads analog values from the water sensor using the ESP32 C3 Super Mini.

What the code does:

  • Powers the sensor ON only during readings
  • Reads analog voltage from the sensor
  • Converts analog reading to a numerical value
  • Displays water level values on Serial Monitor
  • Powers the sensor OFF after reading to prevent corrosion
/* * This ESP32 C3 Super Mini code was developed by newbiely.com * * This ESP32 C3 Super Mini code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/esp32-c3/esp32-c3-super-mini-water-sensor */ #define POWER_PIN D4 // The ESP32 C3 SuperMini pin D4 connected to sensor's VCC pin #define SIGNAL_PIN A0 // The ESP32 C3 SuperMini pin A0 connected to sensor's signal pin int value = 0; // variable to store the sensor value void setup() { Serial.begin(9600); // 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

  • New to ESP32 C3 Mini? Complete our Getting Started with ESP32 C3 Mini tutorial first to set up your development environment.
  • Upload the Code: Copy the code above and paste it into Arduino IDE
  • Compile and Upload: Click the Upload button to program your ESP32 C3 Super Mini
  • Prepare Your Test: Get a glass of water for testing the sensor
  • Test the Sensor: Slowly dip the sensor into the water starting from the bottom traces
  • Open Serial Monitor: Set baud rate to 9600 to view readings
  • Observe Values: Watch values increase as more traces contact water
  • Pro Tip: Keep the sensor's PCB electronics above water - only dip the exposed sensing traces
Newbiely | Arduino IDE 2.3.8
──
File
Edit
Sketch
Tools
Help
ESP32C3 Dev Module
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'ESP32C3 Dev Module' on 'COM15')
New Line
9600 baud
The water sensor value: 0 The water sensor value: 0 The water sensor value: 0 The water sensor value: 25 The water sensor value: 196 The water sensor value: 587 The water sensor value: 625 The water sensor value: 1434 The water sensor value: 1449 The water sensor value: 1454 The water sensor value: 1469 The water sensor value: 2525 The water sensor value: 2526 The water sensor value: 2558
Ln 11, Col 1
ESP32C3 Dev Module on COM15
2

※ NOTE THAT:

The water sensor is not designed to be completely sank, only the exposed traces on the PCB can embed into the water. Please be careful to install it.

How To Detect Water Leakage

Water leakage detection is achieved by comparing the sensor reading against a threshold value determined during calibration.

Detection Applications:

  • Water leak detection in basements or appliances
  • Rainfall monitoring for weather stations
  • Tank overflow prevention systems
  • Flood warning systems

Let's create a practical example where the ESP32 C3 Super Mini turns on an LED when water leakage is detected.

Wiring Diagram

Component ESP32 C3 Super Mini Pin
Water Sensor S GPIO2 (Analog Input)
Water Sensor + GPIO3 (Digital Output)
Water Sensor - GND
LED Anode (+) GPIO8 (through 220Ω resistor)
LED Cathode (-) GND
The wiring diagram between ESP32 C3 Super Mini Water Sensor LED

This image is created using Fritzing. Click to enlarge image

ESP32 C3 Super Mini Code - Detecting Water Leakage

This code demonstrates water leak detection with visual LED indication.

What the code does:

  • Continuously monitors water sensor readings
  • Compares readings against threshold value
  • Turns LED ON when water is detected
  • Turns LED OFF when no water is present
  • Displays leak status on Serial Monitor
/* * This ESP32 C3 Super Mini code was developed by newbiely.com * * This ESP32 C3 Super Mini code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/esp32-c3/esp32-c3-super-mini-water-sensor */ #define LED_PIN D9 // The ESP32 C3 SuperMini pin D9 connected to LED pin #define POWER_PIN D4 // The ESP32 C3 SuperMini pin D4 connected to sensor's VCC pin #define SIGNAL_PIN A0 // The ESP32 C3 SuperMini pin A0 connected to sensor's signal pin #define THRESHOLD 1000 int value = 0; // variable to store the sensor value void setup() { Serial.begin(9600); // 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 advanced example divides water depth into four distinct levels for precise monitoring applications.

Water Level Categories:

  • Empty: No water detected
  • Low: Minimal water level
  • Medium: Moderate water level
  • High: Maximum safe water level
/* * This ESP32 C3 Super Mini code was developed by newbiely.com * * This ESP32 C3 Super Mini code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/esp32-c3/esp32-c3-super-mini-water-sensor */ #define LED_PIN D9 // The ESP32 C3 SuperMini pin D9 connected to LED pin #define POWER_PIN D4 // The ESP32 C3 SuperMini pin D4 connected to sensor's VCC pin #define SIGNAL_PIN A0 // The ESP32 C3 SuperMini pin A0 connected to sensor's signal pin #define THRESHOLD 1000 int value = 0; // variable to store the sensor value void setup() { Serial.begin(9600); // 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 is determined by the calibration process.
  • The above mapping method is not accurate. However, it is acceptable in many applications.

Water Level Sensor Calibration

Proper calibration ensures accurate water level readings for your specific sensor and container setup.

Calibration Process:

  • Determine minimum value (dry sensor)
  • Determine maximum value (fully immersed traces)
  • Map these values to your water level scale
  • Test and adjust threshold values

See how to calibrate the water lever sensor

※ NOTE THAT:

This tutorial uses the analogRead() function to read values from an ADC (Analog-to-Digital Converter) connected to a sensor or component. The ESP32 C3 Super Mini's ADC is suitable for projects that do not require high accuracy. However, for projects needing precise measurements, keep the following in mind:

  • The ESP32 C3 Super Mini's ADC is not perfectly accurate and might require calibration for correct results. Each ESP32 C3 Super Mini board can vary slightly, so calibration is necessary for each individual board.
  • Calibration can be challenging, especially for beginners, and might not always yield the exact results you want.

For projects requiring high precision, consider using an external ADC (e.g ADS1115) with the ESP32 C3 Super Mini or using another Arduino, such as the Arduino Uno R4 WiFi, which has a more reliable ADC. If you still want to calibrate the ESP32 C3 Super Mini's ADC, refer to the ESP32 ADC Calibration Driver.

Application Ideas

Here are practical projects you can build using the ESP32 C3 Super Mini with a water level sensor:

  • Basement flood detection system with smartphone alerts
  • Automatic plant watering system with soil moisture monitoring
  • Aquarium water level monitor and auto-refill controller
  • Rain gauge for DIY weather station projects
  • Coffee maker drip tray overflow prevention
  • Sump pump monitoring and failure alert system

Video Tutorial

Watch the video below for a visual walkthrough of this project.

Challenge Yourself

Ready to take your ESP32 water sensor project to the next level? Try these challenges:

  • Easy: Add a buzzer that beeps when water is detected
  • Easy: Display water level percentage on Serial Monitor instead of raw values
  • Medium: Create a WiFi-enabled leak detector that sends email notifications
  • Medium: Build a multi-sensor system monitoring multiple locations simultaneously
  • Advanced: Design an automatic water tank filling system with upper and lower level sensors
  • Advanced: Create a data logging system that tracks water levels over time and displays graphs

※ 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!