.. _per_water_tank: 2.8 Smart Water Tank ============================= In this project, we use a water level sensor module and a servo to simulate a smart water tank. The water level sensor is fixed inside the tank to measure the water level, and when the water level is below a threshold, the valve controlled by the servo is allowed to open to let water in. Component List ^^^^^^^^^^^^^^^^^^^^^^^^ - Raspberry Pi Pico W x1 - MicroUSB cable x1 - 830 Tie-Points Breadboard x1 - Servo x1 - Water Level Sensor Module x1 - Jumper Wire Several Wiring ^^^^^^^^^^^^^^^^^^^^^^^^ .. image:: img/Water_Tank_Wiring.png Pico W has three GPIO pins that can use analog input, GP26, GP27, GP28. That is, analog channels 0, 1, and 2. In addition, there is a fourth analog channel, which is connected to the built-in temperature sensor and will not be introduced here. .. image:: img/Water_Tank_Wiring2.png * S of water level sensor is connected to GP26(A0), + to VBUS, - pin to GND. * The orange wire (signal) of the servo is connected to GP15, the red wire (power) is connected to VBUS, and the brown wire (ground) is connected to GND. Code ^^^^^^^^^^^^^^^^^^^^^^^^ .. note:: * Utilize the visual programming interface shown below through drag-and-drop methodology. * Import ``2.8_Smart_Water_Tank.png`` from the location ``Ultimate-Starter-Kit-for-Pico-W\Piper_Make``. For complete instructions, reference :ref:`import_code_piper`. .. image:: img/Water_Tank_Code.png Following Pico W connection, activate the **Start** button to initiate program execution. Position your hand above the ultrasonic sensor to observe corresponding variations in the LED bar graph illumination pattern. How it Works? ^^^^^^^^^^^^^^^^^^^^^^^^ .. image:: img/Water_Tank_Code2.png Set the rotation speed of pin15 (servo) to 15%. * [servo pin() set speed to ()%]: Used to set the rotation speed of the servo pin, the range is 0%~100%. .. image:: img/Water_Tank_Code3.png Reads the value of pin A0 and stores it in the variable [water_level]. * [set (water_level) to]: Used to set the value of the variable, you need to create the variable from the **Variables** palette. * [read voltage from pin ()]: Used to read the voltage of the analog pins (A0~A2), the range is 0 ~ 3.3V. .. image:: img/Water_Tank_Code4.png Set the voltage threshold to 1. When the voltage of water level sensor is less than 1, let the servo rotate to 180° position, otherwise rotate to 0° position. * [servo pin () set angle to ()]: Set the angle of servo pin to, the range is 0 ~ 180°.