
The YF-S201 water flow sensor relies on the Hall effect to measure the rate of water flowing through it, making it suitable for building water consumption monitoring systems or calculating the amount used in an automatic irrigation project.
Components needed
An Arduino Uno board, a YF-S201 water flow sensor (rated for 1 to 30 liters per minute), an indicator LED, and connecting wires.
Wiring it up
The sensor connects to digital pin 2, which supports interrupts on the Arduino Uno, in addition to the power and ground pins. The indicator LED connects to digital pin 13.
How it works
The sensor contains a small internal spinning wheel that rotates with the water flow, and each rotation generates electrical pulses that can be counted; the sensor produces roughly 7.5 pulses per liter of water flowing per minute. Instead of polling the state periodically, the code relies on an interrupt service routine automatically called on every pulse to increment a pulse counter — this is more accurate and faster than periodic checking since it never misses a pulse, however fast it comes. The counter value is processed once per second in the main loop to calculate the instantaneous flow rate in liters per minute, while the total volume consumed since startup accumulates in milliliters.
You can find the YF-S201 water flow sensor at Juthour Tech.
اترك تعليقا