🦅 Tutorial 13 - Water Level Sensor
A water level sensor module is a type of electronic sensor that is used to detect the level of water in a tank, reservoir, or other container. It typically consists of a set of probes or sensors that are inserted into the water and connected to supporting circuitry.
The probes are typically made of conductive material, such as stainless steel, and are arranged in a specific pattern to detect the level of the water. When the water level reaches a certain point, the probes come into contact, completing an electrical circuit and triggering an output signal from the supporting circuitry.
Water level sensor modules are commonly used in a variety of applications, such as in industrial and commercial water storage tanks, fish tanks, and swimming pools. They are also used in home automation systems for monitoring water levels in sump pumps, humidifiers, and other devices.
Water level sensor modules are available in various types and configurations, such as capacitance sensors, ultrasonic sensors, and float switches. They are designed to be durable and reliable, with a high level of accuracy and precision.
Overall, water level sensor modules are an important component in electronic circuits and devices, providing reliable monitoring and control of water levels for a wide range of applications.
Components Needed
Component | Quantity |
---|---|
Raspberry Pi Pico W | 1 |
Micro USB Cable | 1 |
Breadboard | 1 |
Wires | Several |
Water Level Sensor Module | 1 |
Fritzing Diagram
Code
import machine
import utime
sensor = machine.ADC(28)
threshold = 30000 #This value needs to be modified with the environment.
while True:
value=sensor.read_u16()
if value > threshold :
print("Liquid leakage!")
utime.sleep_ms(200)
Code Explanation
Importing necessary modules:
import machine
import utime
The code imports the machine module, which is typically used for interacting with hardware on microcontrollers, and the utime module, which is used for time-related operations.
Setting up the water sensor pin and threshold value:
sensor = machine.ADC(28)
threshold = 30000 #This value needs to be modified with the environment.
The code sets up an ADC (Analog-to-Digital Converter) object for the water sensor using pin number 28. It also defines a threshold value, which is a value that needs to be modified based on the specific environment or water leakage detection requirements.
Reading water sensor value and checking for liquid leakage:
while True:
value = sensor.read_u16()
if value > threshold:
print("Liquid leakage!")
utime.sleep_ms(200)
The code enters an infinite loop and reads the value of the water sensor using the read_u16() method, which reads the analog value as a 16-bit unsigned integer. It stores the value in the value variable. The code then compares the value with the threshold using an if statement. If the value is greater than the threshold, it prints “Liquid leakage!” to indicate that liquid leakage has been detected. The code sleeps for 200 milliseconds using the utime.sleep_ms() method, providing a delay to avoid continuous reading and processing of water sensor values.