Liquid Level Sensor
| ||
Overview
- Output voltage boosts along with the immersion depth of the module.
Specification
- Detection depth: 48mm
- Power: 2.0V ~ 5.0V
- Dimension: 19.0mm * 63.0mm
- Mounting holes size: 2.0mm
- Output type: Analog output
- Principle: This module mainly uses the current amplification principle of the triode. When the liquid level makes the base of the triode conductive with the positive electrode of the power supply, a certain amount of current will be generated between the base and the emitter of the triode. A current with a certain magnification will be generated between the collector and the emitter of the triode, and the current will generate a voltage through the resistance of the emitter for the AD converter to collect.
Pinouts
PIN | Description |
AOUT | Analog output |
GND | Ground |
VCC | Power input (3.3V-5.0V) |
Configure Pico
MicroPython and C examples are provided for this sensor, to use it with Pico, you need to first flash firmware to the Pico according to the example.
Please refer to the guides of Raspberry Pi about how to flash the firmware. We recommend you use the firmware from the Demo codes archive.
Hardware connection
Hall | Pico | Description |
---|---|---|
VCC | 3.3V | Power input |
GND | GND | Ground |
AOUT | GP26 | Analog data output |
(Connect according to the table, the picture is for reference only):
Examples
Download the example
Open the terminal of Raspberry Pi and run the following command to download the example:
sudo apt-get install p7zip-full cd ~ sudo wget https://files.waveshare.com/upload/a/a0/Liquid-Level-Sensor-code.7z 7z x Liquid-Level-Sensor-code.7z -o./Liquid-Level-Sensor-code cd ~/Liquid-Level-Sensor-code cd Pico/c/build/
C
Here we use the Raspberry Pi board to flash the Pico.
- Compile the c examples:
- Go into the directory of C examples
cd ~/Liquid-Level-Sensor-code/Pico/c/
- Go into the build folder and add the sdk; ../../pico-sdk is the path of the SDK, if may be different if you have saved the SDK in other paths.
cd build export PICO_SDK_PATH=../../pico-sdk
- Generate Makefile by cmake command.
cmake ..
- Compile the codes by command make.
make -j9
- Note: If you use Pi zero, please run make only.
- After compiling, a uf2 file is generated.
- Hold the button of the Pico board, and connect the Pico board to Raspberry Pi by USB cable.
- After connecting, release the button, and a portable disk (RPI_RP2) is recognized.
- Copy the main.uf2 file generated which locates in the build folder to the portable disk (RPI-RP2).
cp main.uf2 /media/pi/RPI-RP2/
Python examples
- In Windows PC
- Hold the BOOTSET button of the PICO board, and connect the Pico board to Raspberry Pi by USB cable.
- After connecting, release the button, and a portable disk (RPI-RP2) is recognized.
- Copy the rp2-pico-20210418-v1.15.uf2 file to the portable disk (RPI-RP2).
- Open the Thonny IDE (Please install the newest version which supports the Pico board or update).
- Choose Tools -> Options -> Interpreter, and choose the Pico and the port.
- Download the demo codes, unzip and find the MicroPython example:
- Choose File -> Open -> Liquid Level Sensor.py and run it.
- Flash the uf2 file to the Pico board just like in the Windows PC.
- Open the Thonny IDE of Pi, make sure that it is the newest version, or update it.
- Choose Tools -> Options... -> Interpreter.
- Choose Pico and the Port
sudo apt upgrade thonny
- Choose File -> Open... -> python/Liquid Level Sensor.py and run it.
Expected result
When the module is inserted into water, the serial port outputs data. The higher the water level, the greater the data.
The examples provided are based on the STM32F103RBT6 and the STM32H743, the connection provided is based on the STM32F103RB.
If you want to use other STM32 boards, please change the connection and you may need to port the codes yourself.
STM32
Hardware connection
Liquid | STM32 | Description |
---|---|---|
VCC | 3.3V | Power input |
GND | GND | Ground |
AOUT | PA6 | Analog data output |
Examples
The examples are based on the HAL library. Please download the demo codes, unzip them, and find the STM32 examples.
- Open the project from Liquid-Level-Sensor-code\STM32\STM32F103RB\MDK-ARM by Keil.
- Build the project and program it to the STM32 board.
- Connect the UART1 of the STM32 board to the PC and check the serial data by SCCOM software.
Expected result
When the module is inserted into water, the serial port outputs data. The higher the water level, the greater the data.
The examples provided are based on the Arduino UNO, if you need to use other Arduino boards, please check if the board is compatible with the UNO.
Arduino
Hardware connection
Liquid | Arduino | Description |
---|---|---|
VCC | 5V | Power input |
GND | GND | Ground |
AOUT | A0 | Analog data output |
Examples
- Please download and install Arduino IDE to your PC.
- Download the demo codes, unzip and find the Arduino examples.
- Choose your development board and the corresponding port.
- Compile and download.
- After the download is successful, run SSCOM to connect the Liquid Level module, and you can view the status of the sensor in real time.
Expected result
When the module is inserted into water, the serial port outputs data. The higher the water level, the greater the data.
Resources
FAQ
{{{5}}}
{{{5}}}