Effect Achieved
Pour water into the cup, and the change in water level can be observed through the serial monitor showing the value changes output by the water level sensor. In this experiment, tap water was used. It was found that in dry conditions (when not submerged in water), the resistance value is at its maximum, and the output analog signal is 0. Gradually, as water is added to the cup, the analog signal increases, indicating that conductivity has occurred, and as more water is added, the conductivity improves. Until the water completely covers the arranged copper wires, the maximum analog signal value obtained is around 380.
With this value, we can determine the height of the current water level.
Component Description
The Water Level Sensor can not only detect the height of water (although it can only detect a height difference of 4cm), but it can also be used as a rain drop sensor for monitoring various weather conditions, detecting whether it is raining and the amount of rainfall. It is widely used in automatic windshield wiper systems, smart lighting systems, and smart sunroof systems, among others.
-
The module has a power LED that lights up when the module is powered.
-
Operating Voltage: DC3.3V-5V
-
Output Type: Analog Signal
!! Note: During use, the water level sensor/rain drop sensor should be waterproofed except for the copper wire arrangement part to avoid short circuits that could damage the module.
Working Principle
The working principle of the water level sensor is very simple.
This sensor has a total of ten exposed copper wires, five of which are power wires and the other five are sensing wires. These wires are arranged in an alternating pattern, so there is a sensing wire between every two power wires.
Normally, these copper wires are not connected, but when submerged in water, they are bridged by the water. The conductivity between these connected copper wires varies based on the degree of water immersion. It is similar to a variable resistor (like a potentiometer), where the resistance changes according to the water level. The change in resistance corresponds to how much the sensor is submerged.
The resistance is inversely proportional to the height of the water for the following reason: The more water the sensor is submerged in, the better the conductivity, resulting in lower resistance and a larger connected electrical value. The less water the sensor is submerged in, the worse the conductivity, resulting in higher resistance and a smaller connected electrical value. The sensor generates an output voltage based on the resistance, and by measuring it, we can determine the water level.
However, pure water is not conductive; it is the minerals and impurities in the water that give it conductivity. Therefore, the values obtained in your experiments may differ from those in mine.
The calibration method is to first measure the analog signal values at different water levels to determine the approximate depth. These values can be used as a basis for writing if statements in the code.
The same principle applies when used as a rain drop sensor; raindrops on the surface of the arranged copper wires can create connections, thus generating conductive electrical values, leading to changes in the analog signal.
Pin Description
GND (-) Analog Output, outputs values 0-1023 VCC (+) Ground, connects to Arduino’s ground (GND) S Power supply, connects to 3.3V-5V DC power
BOM List
Name | Quantity |
---|---|
Arduino Uno | x1 |
Water Level Sensor | x1 |
Jumper Wires (Dupont Wires) | Several |
Cup | x1 |
Water | Appropriate Amount |
Wiring Method
Arduino Uno Pin | <-> | Water Level Sensor Pin |
---|---|---|
5V | <-> | VCC(+) |
GND | <-> | GND(-) |
S | <-> | AO |
Water level sensor fritzing material reference download: https://fritzing.org/projects/test-water-sensor
Program Points
Getting Analog Signal Data from Water Level Sensor
Use the analogRead() function to get data from the A0 analog port and store it in a specified variable, for example:
val = analogRead(A0);
Usage of if Statements
If… means do something if something happens. If…else… means do something if something happens, otherwise do something else.
There are several syntaxes for if statements, which can be referred to.
Basic Usage of if…
if(boolean_expression)
{
// Statements to execute if the boolean expression is true
}
Basic Usage of if…else…
if(boolean_expression)
{
// Statements to execute if the boolean expression is true
}
else
{
// Statements to execute if the boolean expression is false
}
Multi-condition if…else… Statements
if(boolean_expression 1)
{
// Execute when boolean expression 1 is true
}
else if(boolean_expression 2)
{
// Execute when boolean expression 2 is true
}
else if(boolean_expression 3)
{
// Execute when boolean expression 3 is true
}
else
{
// Execute when none of the above conditions are true
}
One-line if Statements can omit the brackets.
if (x > 120) digitalWrite(LEDpin, HIGH);
If you do this, the next line (defined by a semicolon) will become the only conditional statement.
if (x > 120)
digitalWrite(LEDpin, HIGH);
Program Implementation
Original link, code browsing is more user-friendly
// lingshunlab.com
int val = 0; // Define a variable val, initialize value to 0
void setup() {
Serial.begin(9600); // Set baud rate to 9600
}
void loop() {
val = analogRead(A0); // Get data from A0 analog port and assign it to val variable
Serial.print("val = "); // Serial output val's current data
Serial.print(val);
if(val < 10) { // If val is less than 10
Serial.println(" | dry"); // Indicates very dry, no water
} else if(val < 300) { // If less than 300
Serial.println(" | water level: ~ 0-1 cm"); // Water level is approximately 0-1cm, subsequent statements follow this pattern
} else if(val < 345) {
Serial.println(" | water level: ~ 1-2 cm");
} else if(val < 365) {
Serial.println(" | water level: ~ 2-3 cm");
} else if(val < 385) {
Serial.println(" | water level: ~ 3-4 cm");
} else {
Serial.println(" | water level: over 4 cm");
}
delay(1000); // Wait for 1 second
}
Pour water into the cup
By changing the water level, you can see the change in water level.
If this article helps you, I will be very happy.
If you can like, follow, and share, that would make me even happier.