The sensor consists of a plastic valve body, a flow rotor, and a Hall-effect sensor.
is an inline water flow sensor featuring a water rotor, a magnetic shaft, and a Hall effect sensor.
const int sensorPin = 2; // Pulse input pin volatile long pulseCount = 0; float flowRate = 0.0; unsigned int flowMilliLitres = 0; unsigned long totalMilliLitres = 0; unsigned long oldTime = 0; void IRAM_ATTR pulseCounter() pulseCount++; void setup() Serial.begin(9600); pinMode(sensorPin, INPUT_PULLUP); // Attach interrupt to Pin 2, triggering on a falling edge attachInterrupt(digitalPinToInterrupt(sensorPin), pulseCounter, FALLING); void loop() if ((millis() - oldTime) > 1000) Total: "); Serial.print(totalMilliLitres); Serial.println(" mL"); pulseCount = 0; // Reset counter attachInterrupt(digitalPinToInterrupt(sensorPin), pulseCounter, FALLING); Use code with caution. Troubleshooting Common Simulation Issues
Write this code in the Arduino IDE, compile it, and export the compiled binary ( .hex file) to upload into your Proteus Arduino model.
The number of pulses is directly proportional to the flow rate. The generally accepted formula for YF-S201 is approximately 7.5 Hz ≈ 1 Liter/min. yf-s201 proteus library
Serial.print("Flow Rate: "); Serial.print(flowRate); Serial.println(" liters per minute");
Copy and paste the downloaded YF-S201 library files (*.IDX and *.LIB) into this folder. Step 3: Open Proteus Open Proteus ISIS. Press 'P' to pick devices. Type "YF-S201" in the keyword search. Select the component and place it on the workspace. 4. Interfacing YF-S201 with Arduino in Proteus
Outputs a digital square wave string. Operating Principle
void loop() unsigned long now = millis(); if (now - lastTime >= 1000) // Every second detachInterrupt(digitalPinToInterrupt(2)); The sensor consists of a plastic valve body,
The LCD screen will initialze and quickly transition to displaying the flow analytics. If you set your pulse generator to
: If a specific YF-S201 model is unavailable, you can use a Pulse Generator or a Logic State switch connected to your microcontroller's interrupt pin to mimic the sensor's behavior during simulation. Interfacing with Arduino
Ensure all component ground pins are tied to the Proteus system Ground terminal. Configuring the Simulation Parameters
(Potentiometer to simulate changing flow speeds manually, if using an advanced simulation model) Wiring the Schematic Troubleshooting Common Simulation Issues Write this code in
[Water Inlet] ──> [Rotating Pinwheel + Magnet] ──> [Water Outlet] │ [Hall Effect Sensor] ──> [Digital Square Wave Out]
Complete Guide to Integrating the YF-S201 Water Flow Sensor in Proteus
Connect all VCC pins to the POWER terminal (5V) and all GND pins to the GROUND terminal in Proteus. Arduino Code for the Simulation