Lab05 - Water Level Sensor Works and Interface It With Arduino

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

Laboratory Activity #5

Water Level Sensor Works and Interface it with Arduino

Name: ______________________________________ C/Y/S: ____________ Date Submitted: _______________________

Objectives:
▪ Detect the presence and level of water using Arduino

Introduction:

If you have ever had a water heater explode or ever tried to make submersible electronics, then you know how important it is to
detect when water is around. With this Water Level Sensor shown in Figure 1, you can do just that! This sensor can be used to measure
the water level, monitor a sump pit, detect rainfall, or detect leakage.

Figure 1

As shown in Figure 2, the sensor has a series of ten exposed copper traces, five of which are power traces and five are sense
traces. These traces are interlaced so that there is one sense trace between every two power traces. Usually, these traces are not
connected but are bridged by water when submerged.

Digital Electronics 2: Microprocessors and Microcontrollers


Darwin D. Mañaga, Meng-ECE, PECE, ACPE
Figure 2

How Water Level Sensor Works?


The working of the water level sensor is straightforward. The series of exposed parallel conductors, together acts as a variable resistor
(just like a potentiometer) whose resistance varies according to the water level. The change in resistance corresponds to the distance
from the top of the sensor to the surface of the water. The resistance is inversely proportional to the height of the water:
▪ The more water the sensor is immersed in, results in better conductivity and will result in a lower resistance.
▪ The less water the sensor is immersed in, results in poor conductivity and will result in a higher resistance.
The sensor produces an output voltage according to the resistance, which by measuring we can determine the water level.

Water Level Sensor Pinout


As shown in Figure 3, the water level sensor is super easy to use and only has 3 pins to connect.

Figure 3
Digital Electronics 2: Microprocessors and Microcontrollers
Darwin D. Mañaga, Meng-ECE, PECE, ACPE
Components:

▪ Breadboard
▪ Arduino Uno R3
▪ Water Level Sensor
▪ LEDs
▪ 330 ohm resistors

Wiring Water Level Sensor with Arduino

Let’s hook the water level sensor up to the Arduino. First you need to supply power to the sensor. For that you can connect
the + (VCC) pin on the module to 5V on the Arduino and – (GND) pin to ground. However, one commonly known issue with these
sensors is their short lifespan when exposed to a moist environment. Having power applied to the probe constantly speeds the rate of
corrosion significantly. To overcome this, we recommend that you do not power the sensor constantly, but power it only when you take
the readings.

An easy way to accomplish this is to connect the VCC pin to a digital pin of an Arduino and set it to HIGH or LOW as per your
requirement. So, we’ll connect the VCC pin to the digital pin #7 of an Arduino. Finally, connect the S (Signal) pin to the A0 ADC pin on
your Arduino. Figure 4 shows the wiring.

Figure 4

Digital Electronics 2: Microprocessors and Microcontrollers


Darwin D. Mañaga, Meng-ECE, PECE, ACPE
Water Level Sensing Basic Example
Once the circuit is built, upload the following sketch to your Arduino.

// Sensor pins
#define sensorPower 7
#define sensorPin A0

// Value for storing water level


int val = 0;

void setup() {
// Set D7 as an OUTPUT
pinMode(sensorPower, OUTPUT);

// Set to LOW so no power flows through the sensor


digitalWrite(sensorPower, LOW);
Serial.begin(9600);
}

void loop() {
//get the reading from the function below and print it
int level = readSensor();
Serial.print("Water level: ");
Serial.println(level);
delay(1000);
}

//This is a function used to get the reading


int readSensor() {
digitalWrite(sensorPower, HIGH); // Turn the sensor ON
delay(10); // wait 10 milliseconds
val = analogRead(sensorPin); // Read the analog value form sensor
digitalWrite(sensorPower, LOW); // Turn the sensor OFF
return val; // send current reading
}

Digital Electronics 2: Microprocessors and Microcontrollers


Darwin D. Mañaga, Meng-ECE, PECE, ACPE
Once the sketch is uploaded, open a Serial Monitor window to see the output from the Arduino. You should see a value 0
when the sensor is not touching anything. To see it sense water, you can take a glass of water and slowly put the sensor in it.
Calibration
To get accurate readings out of your water level sensor, it is recommended that you first calibrate it for the water that you plan
to monitor. As you know pure water is not conductive. It’s the minerals and impurities in water that makes it conductive. So, your sensor
may be sensitive depending on the type of water you use.
Before you start storing data or triggering events, you should see what readings you are getting from your sensor. Using the
sketch above, note what values your sensor outputs when the sensor is completely dry -vs- when it is partially submerged in the water -
vs- when it is completely submerged. For example, using the same circuit above, you’ll see the close to the following values in the
serial monitor when the senor is dry (0) and when it is partially submerged in the water (~420) and when it is completely submerged
(~520). See Figure 5 for illustration:

Figure 5

Water Level Sensing Project


For your next task, design a portable water level sensor that will light up LEDs according to the water level.

Digital Electronics 2: Microprocessors and Microcontrollers


Darwin D. Mañaga, Meng-ECE, PECE, ACPE

You might also like