Yfs401 Datasheet

0 views
Skip to first unread message

Azalee Rowling

unread,
Aug 5, 2024, 5:29:37 AM8/5/24
to reinocahand
1Is this sensors are accurate (+- 2% as told so in the datasheet.)

2-) Calibration factor in the data sheet "98 means around 0.17 ml for each pulse" is applicable on every project or changes due to piping, pump selection etc. (i am planing a 5V dc powered pump.)

3-) Does it need to be specific type of pump?

4-) Can you give an advice for example code? (need to be sure i read accurate results besides coding.)


Your posted link does not go to an actual data sheet. Please include a link to the ACTUAL data sheet for YOUR device.

No matter the flow sensor, you will need to calibrate the sensor you you have. Even if the specifications are identical, your plumbing equipment will effect the sensor performance.


In this article, we will interface the popular YF-S201 water flow sensor with Raspberry Pi Pico RP2040. We shall use an interrupt to measure the volume of water passing through the flow sensor. The project is explained using MicroPython and will work on all versions of Raspberry Pi Pico including the Raspberry Pi Pico W.


The YF-S201 Flow Sensor can be used to measure volume and flow rate. It works on the principle of the Hall Effect. According to Hall Effect, when a current-carrying conductor is placed in a magnetic field perpendicular to the current direction, an electric field is induced in the conductor perpendicular to both the electric current and the magnetic field. Let us look at the internal diagram of the YF-S201 flow sensor.


The arrangement consists of a freely rotating wheel placed inside an outer case. The outer case is made waterproof using O-rings and keeps the electronics components isolated. The wheel has a permanent magnet attached near its center. The magnet rotates along with the wheel when a liquid flows through the sensor. This creates a rotating magnetic field which induces a voltage in the Hall Effect Sensor. The Hall Effect Sensor then sends pulses, and a microcontroller can read the pulses to estimate the liquid flow rate through the sensor.


Please ensure that the MicroPython UF2 file is preloaded to RP2040. You can check out our article Getting Started With Raspberry Pi Pico & Raspberry Pi Pico W Using MicroPython, where we describe all the steps required to set up Raspberry Pi Pico.


The Hall Effect Sensor provides data in the form of square wave pulses. We can calculate the frequency of these pulses to find the flow rate. According to the datasheet, the following is the relationship between the flow rate and the corresponding frequency. There may be an error of 10% in readings.


Connect your Pi Pico, Flow Sensor, NPN transistor, and resistors(10K) as shown in the diagram below. The 3.3V output pin 36 is connected to the two 10K resistors. The emitter of the NPN transistor connects to the DATA pin of the flow sensor, and the collector of the transistor connects to the GP21 of Pi Pico.


After you run the script, blow air into the flow sensor or pass water through it. You should now see the flow rate displayed on the Serial Monitor of your IDE. In Thonny, the Serial Monitor is displayed in the lower part of the IDE.


In the following lines of code, pin 21 is declared as an input pin with PULL_UP enabled. The callback function will be executed when interrupt occurs, and the flow_frequency variable will be incremented by 1. A rising edge triggered interrupt is attached to the pin using pin.irq() function, and callback is specified as the function that must be called when interrupt occurs. You can also visit our article Raspberry Pi Pico External Interrupts & Button Interfacing Tutorial Using MicroPython to know about buttons and interrupts in Raspberry Pi Pico.


The while loop first checks if the time interval since the last reading is more than 1 second. If yes, the flow rate is calculated. Then the flow_frequency variable is reset to zero. This variable will again count up every time an Interrupt occurs. Its value is checked every second to calculate the flow rate and is reset after the calculation is done. The function time.ticks_ms() increments every millisecond and is used here to calculate the time intervals. The print() function prints the output to the Serial Monitor.


We will now learn to interact and display the flow rate on a 162 LCD display. Connect the LCD as shown in the diagram below. Pin 1(GP0) of Pico connects to the SDA pin of the LCD and Pin 2(GP1) of Pico connects to the SCL pin of the LCD.


To know more about how the LCD interfacing code works, you can refer to my article Raspberry Pi Pico LCD Tutorial-162 I2C Display(PCF8574) Interfacing Using MicroPython. If you prefer to display output on an OLED display, check out the article Raspberry Pi Pico OLED Display SSD1306 Interfacing Tutorial Using MicroPython.

3a8082e126
Reply all
Reply to author
Forward
0 new messages