Project 7: Water Sensor

Build a Water Detector using Water Sensor Module

10/31/20266 min read

Introduction

Have you ever wondered how electronic devices can detect water? Water sensors are used in many systems to identify leaks, monitor water levels, and prevent unwanted water damage.

In this project, you will use a water sensor module and an Arduino Uno to build a simple water detection system. The sensor will detect the presence of water and send a signal to the Arduino. The Arduino will then display whether water has been detected in the Serial Monitor.

This project introduces you to water sensing and teaches you how Arduino can read analog signals from sensors.

Water Sensor Module

What You Will Learn:

  • How a water sensor detects water.

  • How to connect an analog water sensor to an Arduino Uno.

  • How to read sensor values using analogRead().

  • How to use a threshold to identify water.

  • How to display sensor readings in the Serial Monitor.

  • How water sensors are used in real-world applications.

1. Components Required

You will need the following components from your Arduino robotics kit:

  • 1 Arduino Uno

  • 1 water sensor module

  • Jumper wires

  • 1 USB cable to connect and power the Arduino

2. Understanding the Water Sensor

A water sensor is an electronic component that detects the presence of water.

The sensing area usually contains several exposed conductive tracks. When water touches these tracks, it changes the electrical conductivity between them.

The sensor converts this change into an electrical signal that the Arduino can read.

In this project, we are using the analog output of the water sensor. This allows the Arduino to receive a changing numerical reading instead of just an ON or OFF signal.

Water sensors are commonly used in:

  • Water leakage detection systems

  • Water level monitoring

  • Flood detection systems

  • Smart irrigation systems

  • Home automation

  • Robotics projects

3. Connecting the Water Sensor to Arduino

Let's connect the water sensor to your Arduino Uno.

Step 1: Identify the Sensor Pins

Your water sensor module has three main connections:

  • SIG (or S labelled on sensor): Sends the sensor's analog signal to the Arduino.

  • VCC: Supplies power to the sensor.

  • GND: Connects to the Arduino's ground.

Step 2: Connect the Signal Pin

Connect the sensor's S pin to Arduino analog pin A0.

This allows the Arduino to read the sensor's output.

Step 3: Connect the Power Pin

Connect the sensor's VCC pin to the Arduino 5V pin.

Step 4: Connect Ground

Connect the sensor's GND pin to an Arduino GND pin.

Your connections should be:

  • Water sensor SIG → Arduino A0

  • Water sensor VCC → Arduino 5V

  • Water sensor GND → Arduino GND

4. Writing the Arduino Code

Now let's program the Arduino to detect water using the sensor.

Open the Arduino IDE using the setup you completed in Project 1.

Copy and paste the following code into your sketch.

Upload the code to your Arduino Uno.

Once the program starts running, open the Serial Monitor in the Arduino IDE and set the baud rate to 9600.

You should see messages displaying the sensor reading and its status.

When the reading is 300 or higher, the Serial Monitor displays:

WATER DETECTED

When the reading is below 300, it displays:

DRY

Warning: DO NOT expose any component to water except only the silver lines on the water sensor as shown in the image below otherwise it can lead to damaged parts or injury.

5. Understanding the Code

Let's break the program into simple parts so you can understand how it works.

A. Defining the Sensor Pin

Serial Monitor Reading before Water Drop on Sensor

Serial Monitor Reading after Water Drop on Sensor

This line assigns the name WATER_SENSOR_PIN to analog pin A0.

The Arduino uses this pin to receive the analog signal from the water sensor.

B. Setting the Water Threshold

A threshold is a value used to make a decision.

In this project, the threshold is set to 300.

The Arduino compares the sensor reading with this value to decide whether water has been detected.

The correct threshold can vary depending on your sensor. You can observe the readings in the Serial Monitor and adjust this value accordingly.

C. Starting Serial Communication

The setup() function runs once when the Arduino starts or resets.

Inside this function:

  • Serial.begin(9600) starts communication between the Arduino and your computer at 9600 baud.

  • Serial.println("Water Detector") displays the project name in the Serial Monitor.

D. Reading the Water Sensor

The analogRead() function reads the analog signal received from the water sensor.

On an Arduino Uno, analog readings range from 0 to 1023.

The reading is stored in a variable called reading.

When water touches the sensor's sensing area, the reading usually changes because water affects the electrical conductivity between the sensor's tracks.

E. Displaying the Sensor Reading

These instructions display the current sensor reading in the Serial Monitor.

The Serial.print() function displays information without automatically moving to a new line.

This allows you to see the numerical value received from the sensor.

F. Checking Whether Water Is Detected

This line uses a conditional operator to make a decision.

It checks whether the sensor reading is greater than or equal to the threshold.

  • If the reading is 300 or higher, it displays WATER DETECTED.

  • If the reading is below 300, it displays DRY.

The symbols >= mean greater than or equal to.

This is a shorter way of writing an if and else statement.

G. Adding a Delay

The delay() function pauses the program for 500 milliseconds, or half a second.
(1 second is equal to 1000 milliseconds)

After the delay, the Arduino takes another reading and repeats the process.

This allows the sensor to continuously monitor the presence of water.

6. Understanding the Serial Monitor

The Serial Monitor allows you to see the information sent by your Arduino while the program is running.

In this project, it displays two important things:

  • The numerical reading received from the water sensor.

  • The status showing whether water has been detected.

Example output:

Water Detector
Sensor reading: 120 | Status: DRY
Sensor reading: 180 | Status: DRY
Sensor reading: 350 | Status: WATER DETECTED
Sensor reading: 520 | Status: WATER DETECTED

These are example readings. Your actual values may be different depending on your sensor and the amount of water touching its sensing area.

You can use the Serial Monitor to observe the readings when the sensor is dry and when water touches it.

7. Real-World Applications

Water sensors are useful in many electronic systems where detecting water is important.

Water Leakage Detection: Water sensors can help detect unwanted leaks near pipes, washing machines, and water storage systems.

Flood Detection: They can be used in systems that monitor rising water or detect water in areas where flooding could cause damage.

Water Level Monitoring: Water sensors can be part of systems that monitor the presence of water in tanks and containers.

Smart Irrigation: They can help monitor water conditions in irrigation systems and support automated watering projects.

Robotics: A robot can use a water sensor to detect water in its surroundings and respond according to its programming.

8. Safety Tips

  • Keep the Arduino board and USB connection away from water.

  • Only expose the sensor's intended sensing area to water.

  • Do not immerse the entire sensor module or its electrical connections.

  • Disconnect the sensor when you have finished testing.

  • Avoid leaving resistive water sensor boards powered and wet for long periods, as this can cause corrosion.

Congratulations! You have built a water detection system using your Arduino Uno and a water sensor module.

Through this project, you learned how to:

  • Understand how a water sensor works.

  • Connect an analog sensor to an Arduino.

  • Read sensor values using analogRead().

  • Understand the analog reading range of 0 to 1023.

  • Use a threshold to identify water.

  • Display sensor readings using the Serial Monitor.

  • Understand how water sensors are used in real-world systems.

You have now learned how Arduino can detect changes in its surroundings using an analog sensor. This is an important concept in building more advanced electronic and robotics projects.