Ugenz Academy/IoT Tutorial

Water And Liquid Sensors

15 min read2,863 words

Reading progress

Keep learning

Water and Liquid Sensors

Water and liquid sensors are used to detect, measure, monitor, and control water or other liquids.

They are widely used in:

  • 💧 Water tanks
  • 🚰 Automatic water pumps
  • 🌧️ Rain detection
  • 🏠 Leak detection
  • 🌱 Irrigation systems
  • 🏭 Industrial liquid monitoring
  • 🐟 Aquaculture
  • 🚿 Smart bathrooms
  • 🤖 IoT water-monitoring systems

1 What Are Water and Liquid Sensors?

A water/liquid sensor is an electronic device that detects the presence, level, flow, quality, temperature, or other properties of a liquid.

For example:

WATER TANK ┌─────────────────┐ │ │ │ WATER │ │ │ │ ~~~~~~~~~~~~~~~ │ │ │ │ SENSOR │ │ ↓ │ └────────┬────────┘ │ ESP32 │ Relay │ Water Pump

The sensor sends information to a microcontroller such as:

  • Arduino
  • ESP32
  • ESP8266
  • Raspberry Pi

The controller can then make decisions automatically.


2 Types of Water and Liquid Sensors

There are many types.

SensorWhat it detects
Water Level SensorAmount/presence of water
Float SwitchHigh/low liquid level
Ultrasonic Level SensorDistance to liquid surface
Water Flow SensorFlow rate
Water Leak SensorLeakage/presence of water
Rain SensorRain/water droplets
Pressure SensorLiquid pressure/level
Turbidity SensorWater clarity
TDS SensorDissolved solids
EC SensorElectrical conductivity
pH SensorAcidity/alkalinity
Water Temperature SensorTemperature
Capacitive Level SensorLiquid level without direct contact

Let's understand them one by one.


3 Water Level Sensor

A basic water-level sensor detects whether water is present at a particular level.

A common module has exposed conductive tracks.

Example:

Water Level ↓ ┌─────────────┐ │ │ │ WATER │ │ ~~~~~~~~~~~ │ │ ||||||||||| │ ← Sensor │ ||||||||||| │ └─────────────┘ │ ESP32

When water touches the conductive tracks, electrical conductivity changes.

Output

Depending on the module, it can provide:

  • Analog output
  • Digital output

The analog output can be connected to an ADC pin.

Applications

  • Water tank monitoring
  • Overflow detection
  • Rain detection
  • Plant watering
  • Leak detection

Limitation

Simple conductive water-level sensors can corrode over time, especially when continuously powered.

For long-term projects, capacitive sensors or float switches can be better.


4 Float Switch

A float switch is one of the simplest and most reliable ways to detect a specific liquid level.

It contains a floating element and a switch.

Tank ┌─────────────┐ │ │ │ WATER │ │ ~~~~~~~~~~~ │ │ ● │ ← Float │ │ │ │ │ │ └──────┼──────┘ │ Switch

When the water rises:

Water rises ↓ Float rises ↓ Switch changes state ↓ ESP32 detects it

Typical use

LOW LEVEL → Pump ON HIGH LEVEL → Pump OFF

For example:

WATER TANK ┌───────────────┐ │ HIGH ───────● │ ← Stop pump │ │ │ │ │ LOW ───────● │ ← Start pump └───────────────┘

You can use two float switches:

  • Low-level switch
  • High-level switch

This is excellent for automatic tank filling.


5 Ultrasonic Water-Level Sensor

An ultrasonic sensor measures the distance between the sensor and water surface.

For example:

Ultrasonic Sensor ┌───────┐ │ HC-SR04 └───┬───┘ ↓ ultrasonic waves ↓ ┌───────────────┐ │ │ │ │ │ WATER │ │ ~~~~~~~~~~~~~ │ └───────────────┘

The sensor measures the distance:

Sensor ↓ ↓ distance ↓ ~~~~~~~~~~~~ water

If the tank height is known:

Water Level = Tank Height - Measured Distance

Example

Tank height:

100 cm

Measured distance to water:

25 cm

Therefore:

Water level = 100 - 25 = 75 cm

Approximate percentage:

Water % = (75 / 100) × 100 = 75%

Advantages

  • No direct electrical contact with water
  • Easy to interface with microcontrollers
  • Useful for IoT projects

Applications

  • Smart water tanks
  • Industrial tanks
  • Automatic pumping
  • Water-level dashboards

6 Water Flow Sensor

A water-flow sensor measures how much water is moving through a pipe.

A common type contains a small internal rotor.

Water Flow ───────→ ┌──────────┐ ───────→ │ Rotor │ │ ↻ │ └──────────┘ │ Sensor │ ESP32

When water flows, the rotor rotates.

The sensor generates pulses.

The microcontroller counts these pulses.

Water Flow ↓ Rotor rotates ↓ Pulses generated ↓ ESP32 counts pulses ↓ Flow rate calculated

6.1 Flow Rate

Flow rate tells us how quickly water is moving.

Common units:

  • L/min
  • L/hour
  • m³/hour

For example:

Flow = 5 L/min

means approximately 5 liters of water pass through the sensor every minute.


7 Water Leak Sensor

A leak sensor detects unwanted water.

Example:

HOUSE ┌──────────────┐ │ │ │ 💧 │ │ 💧 💧 │ │ SENSOR │ └──────┬───────┘ │ ESP32 │ Buzzer

When water reaches the sensor:

Water detected ↓ ESP32 ↓ Buzzer ON ↓ Alert notification

Applications

  • Kitchen
  • Bathroom
  • Server room
  • Water purifier
  • Washing machine area
  • Basement
  • Industrial systems

8 Rain Sensor

A rain sensor detects water droplets/rain.

A typical module contains:

Rain plate ↓ Sensor module ↓ Arduino / ESP32

It can provide:

  • Analog output
  • Digital output

Example:

Rain detected ↓ Close window ↓ Stop irrigation ↓ Send notification

Smart irrigation example

Rain Sensor │ ↓ Soil Moisture → ESP32 ← Weather data │ ↓ Water Pump

If rain is detected, the system can avoid unnecessary irrigation.


9 Capacitive Liquid-Level Sensor

A capacitive sensor detects liquid by measuring changes in capacitance.

Unlike conductive sensors, it doesn't necessarily require the sensing electrodes to be electrically exposed to the liquid.

Conceptually:

Sensor ████████████ │ │ electric field ↓ ┌─────────┐ │ Liquid │ │ │ └─────────┘

When liquid level changes, the electrical characteristics change.

Advantages

  • Less corrosion
  • Can work through some non-metallic containers
  • Useful for continuous monitoring
  • Good for clean liquids

10 Pressure-Based Liquid-Level Measurement

Liquid creates pressure due to its weight.

The pressure depends on:

P = ρgh

Where:

  • P = pressure
  • ρ = liquid density
  • g = gravitational acceleration
  • h = liquid height

Therefore, measuring pressure at the bottom of a tank can help determine liquid level.

Tank ┌───────────┐ │ │ │ WATER │ │ │ │ │ │ │ └─────┬─────┘ ↓ Pressure sensor

This method is more common in industrial applications.


11 Turbidity Sensor

A turbidity sensor measures how cloudy or clear water is.

Clean water:

Light ↓↓↓↓↓ ~~~~~~~~~~~~ Clear water

Dirty water:

Light ↓ ↓ ↘ ~~~~~~~~~~~~ Particles ● ● ● ●

Suspended particles scatter light.

The sensor uses this change to estimate turbidity.

Applications

  • Water quality monitoring
  • Fish tanks
  • Aquaculture
  • Drinking-water systems
  • Environmental monitoring

Important

A turbidity sensor does not directly tell you whether water is safe to drink.

It mainly indicates optical cloudiness/particle content.


12 TDS Sensor

TDS = Total Dissolved Solids

It estimates the amount of dissolved substances in water.

Commonly discussed units:

ppm

TDS monitoring is often used in:

  • RO systems
  • Water-quality projects
  • Aquariums
  • Hydroponics
  • IoT water monitoring

Basic concept:

Water ↓ TDS Sensor ↓ Electrical measurement ↓ ESP32 ↓ Estimated TDS

Important

TDS is not the same thing as water safety.

A TDS reading alone cannot determine whether water is potable.


13 EC Sensor

EC = Electrical Conductivity

It measures how easily electricity passes through a liquid.

More dissolved ions generally produce higher conductivity.

Applications:

  • Hydroponics
  • Agriculture
  • Water quality
  • Industrial processes
  • Salinity monitoring

For agriculture:

EC measurement ↓ Nutrient/salt environment information ↓ Crop management

EC and TDS are related, but they are not identical measurements.


14 pH Sensor

A pH sensor measures whether a liquid is acidic or alkaline.

The pH scale is commonly represented as:

0 7 14 |-------|--------| Acid Neutral Alkaline

Examples:

pHGeneral description
< 7Acidic
7Neutral
> 7Alkaline

A pH sensor generally uses a probe and an interface circuit.

pH Probe │ ↓ pH Interface │ ↓ ESP32

Applications

  • Agriculture
  • Hydroponics
  • Aquaculture
  • Water treatment
  • Laboratory systems

Calibration

pH probes normally require proper calibration using standard buffer solutions.

Typical calibration points can include:

pH 4 pH 7 pH 10

depending on the measurement range and probe/application.


15 Water Temperature Sensor

Water temperature can be measured using sensors such as:

  • DS18B20
  • Thermistors
  • RTDs
  • Waterproof temperature probes

A waterproof DS18B20 is especially popular in Arduino/ESP32 projects.

Waterproof Probe │ ↓ ┌─────────────┐ │ WATER │ │ │ └─────────────┘ │ ESP32

Applications

  • Aquarium
  • Fish farming
  • Water tanks
  • Hydroponics
  • Solar water heaters
  • Industrial monitoring

16 Water Sensor Comparison

SensorMeasuresContact with waterTypical use
Water-level platePresence/levelYesBasic projects
Float switchSpecific levelYesTank control
UltrasonicDistance/levelNoSmart tanks
Flow sensorFlow rateYesWater usage
Leak sensorWater presenceYesLeak detection
Rain sensorRain/waterYesWeather
CapacitiveLevelUsually no direct electrical contactTanks
Pressure sensorLiquid pressure/levelDependsIndustrial
TurbidityCloudinessYesWater quality
TDSDissolved solids estimateYesRO/water monitoring
ECConductivityYesHydroponics
pHAcidity/alkalinityYesWater chemistry
DS18B20TemperatureProbe contactAquaculture

17 Automatic Water Tank System

One of the best beginner IoT projects is an automatic water tank controller.

Components

  • ESP32
  • Ultrasonic sensor
  • Relay module
  • Water pump
  • Water tank
  • Buzzer
  • OLED/LCD
  • Optional float switches

Working

WATER TANK ┌─────────────────┐ │ │ │ WATER │ │ │ │ ~~~~~~~~~~~~~~~ │ │ │ └───────┬─────────┘ │ Ultrasonic │ ↓ ESP32 / \ ↓ ↓ Display Relay │ ↓ Pump

Logic:

Water < 20% ↓ Pump ON Water reaches 90% ↓ Pump OFF

This prevents unnecessary manual operation.


18 Simple ESP32 Water-Level Example

For an ultrasonic sensor such as HC-SR04, a simplified example:

#define TRIG_PIN 5 #define ECHO_PIN 18 #define RELAY_PIN 23 const float TANK_HEIGHT = 100.0; void setup() { Serial.begin(115200); pinMode(TRIG_PIN, OUTPUT); pinMode(ECHO_PIN, INPUT); pinMode(RELAY_PIN, OUTPUT); digitalWrite(RELAY_PIN, LOW); } void loop() { digitalWrite(TRIG_PIN, LOW); delayMicroseconds(2); digitalWrite(TRIG_PIN, HIGH); delayMicroseconds(10); digitalWrite(TRIG_PIN, LOW); long duration = pulseIn(ECHO_PIN, HIGH); float distance = duration * 0.0343 / 2.0; float waterLevel = TANK_HEIGHT - distance; if (waterLevel < 0) { waterLevel = 0; } if (waterLevel > TANK_HEIGHT) { waterLevel = TANK_HEIGHT; } float percentage = (waterLevel / TANK_HEIGHT) * 100.0; Serial.print("Water Level: "); Serial.print(percentage); Serial.println("%"); if (percentage <= 20) { digitalWrite(RELAY_PIN, HIGH); } if (percentage >= 90) { digitalWrite(RELAY_PIN, LOW); } delay(1000); }

Important ESP32 Safety

Many HC-SR04 modules use a 5V echo output.

ESP32 GPIOs are 3.3V logic, so do not blindly connect a 5V ECHO signal directly to an ESP32 GPIO.

Use a suitable:

  • Voltage divider
  • Logic-level converter
  • 3.3V-compatible ultrasonic sensor

19 Water Consumption Monitoring

A flow sensor can be combined with a microcontroller to monitor water usage.

Water Pipe ↓ Flow Sensor ↓ ESP32 ↓ LCD / OLED ↓ Liters Used

Example:

Flow Rate: 3.5 L/min Total Used: 42.8 L

This can be useful for:

  • Homes
  • Farms
  • Hotels
  • Laboratories
  • Smart irrigation

20 Smart Water Monitoring System

A more advanced system can combine several sensors.

┌──────────────┐ │ ESP32 │ └──────┬───────┘ │ ┌─────────────┼─────────────┐ ↓ ↓ ↓ Water Level Flow Sensor Temperature │ │ │ └─────────────┼─────────────┘ ↓ Dashboard │ ┌───────┴───────┐ ↓ ↓ Pump Control Alerts

You can add:

  • pH
  • TDS
  • EC
  • Turbidity
  • Leak detection
  • Mobile notifications
  • Cloud database

21 Water-Level Control Logic

A good automatic system should use different ON and OFF thresholds.

For example:

100% ───────── 90% ──────── Pump OFF 80% 70% 60% 50% 40% 30% 20% ──────── Pump ON 0% ─────────

This is called hysteresis.

Why?

If you use only one threshold, the pump could repeatedly switch:

49% → ON 50% → OFF 49% → ON 50% → OFF

That can cause rapid relay/pump switching.


22 Combining Water and Soil Sensors

For agriculture, water sensors can work together with soil sensors.

ESP32 │ ┌────────┼────────┐ ↓ ↓ ↓ Soil Moisture Tank Level Rain Sensor │ │ │ └────────┼────────┘ ↓ Decision Logic ↓ Pump

Example:

Soil is dry + Tank has enough water + No rain ↓ Pump ON

But:

Soil is dry + Tank is empty ↓ Pump OFF ↓ Alert user

This is a much smarter system than simply running a pump on a timer.


23 Common Problems

Problem 1: Water sensor gives unstable readings

Possible causes:

  • Electrical noise
  • Poor wiring
  • Dirty water
  • Corrosion
  • Long wires

Solutions:

  • Take multiple readings
  • Average readings
  • Use filtering
  • Improve grounding
  • Use better sensors

Problem 2: Ultrasonic reading jumps

Possible causes:

  • Water surface movement
  • Foam
  • Condensation
  • Sensor mounting problems
  • Incorrect distance range

Solution:

Take multiple measurements:

Reading 1 = 72 cm Reading 2 = 73 cm Reading 3 = 71 cm Reading 4 = 72 cm Reading 5 = 72 cm Average ≈ 72 cm

Problem 3: Conductive sensor corrodes

Reason:

The sensor is continuously exposed to water and electrical current.

Solutions:

  • Power sensor only when measuring
  • Use capacitive sensing
  • Use float switches
  • Use non-contact level measurement

Problem 4: pH reading is wrong

Possible causes:

  • No calibration
  • Dirty probe
  • Poor storage
  • Temperature effects
  • Incorrect interface circuit

pH probes require much more care than simple digital sensors.


24 Where Water Sensors Are Used

🏠 Home Automation

  • Tank monitoring
  • Leak detection
  • Automatic pump
  • Water consumption

🌱 Agriculture

  • Irrigation
  • Water tank monitoring
  • Hydroponics
  • Fertigation

🐟 Aquaculture

  • Water temperature
  • pH
  • Turbidity
  • EC
  • Water level

🏭 Industry

  • Tank level
  • Flow measurement
  • Process control
  • Water treatment

🚰 Water Treatment

  • pH
  • TDS
  • Turbidity
  • EC
  • Temperature

25 Which Sensor Should You Choose?

RequirementRecommended sensor
Detect water presenceWater sensor
Detect exact high/low levelFloat switch
Measure tank levelUltrasonic
Measure water flowFlow sensor
Detect leakageLeak sensor
Detect rainRain sensor
Measure water temperatureDS18B20
Measure cloudinessTurbidity
Estimate dissolved solidsTDS
Measure conductivityEC
Measure aciditypH
Long-term tank levelFloat/capacitive/ultrasonic

26 Complete Smart Water System

A professional educational project could look like this:

SMART WATER SYSTEM │ ESP32 │ ┌───────────┬───────┼────────┬───────────┐ ↓ ↓ ↓ ↓ ↓ Ultrasonic Flow Leak Temp pH/TDS │ Sensor Sensor Sensor Sensor └───────────┴───────┬────────┴───────────┘ ↓ Processing │ ┌─────────────┼─────────────┐ ↓ ↓ ↓ Display Relay Wi-Fi │ │ ↓ ↓ Pump Mobile App

The ESP32 can display:

WATER MONITOR Level: 76% Flow: 3.2 L/min Temp: 27.4°C pH: 7.1 TDS: 180 ppm Pump: OFF Status: NORMAL

27 Key Points

Remember these important concepts:

  1. Water-level sensors detect liquid level/presence.
  2. Float switches are simple and reliable for ON/OFF level control.
  3. Ultrasonic sensors measure the distance to the liquid surface without touching it.
  4. Flow sensors measure water movement through pipes.
  5. Leak sensors detect unwanted water.
  6. Turbidity sensors measure water cloudiness.
  7. TDS sensors estimate dissolved solids.
  8. EC sensors measure electrical conductivity.
  9. pH sensors measure acidity/alkalinity.
  10. DS18B20 is useful for water-temperature monitoring.
  11. Multiple sensors can be combined with ESP32 for smart water management.
  12. Always calibrate sensors that require calibration, especially pH, TDS/EC and analog level sensors. For automatic pumps, use proper relay/MOSFET drivers and electrical isolation where appropriate.
  13. For ESP32, never assume a sensor's output is safe for a 3.3V GPIO just because the sensor is marketed for Arduino.

Keep learning. Keep building. Keep growing.

© 2026 Ugenz Academy