Instead of manual creation, download a ready-made YF-S201 Proteus Library from:
volatile int pulseCount = 0; float flowRate = 0.0; float totalLiters = 0.0; unsigned long lastTime = 0;const float PULSES_PER_LITER = 450.0;
void pulseCounter() pulseCount++;
void setup() Serial.begin(9600); pinMode(2, INPUT_PULLUP); attachInterrupt(digitalPinToInterrupt(2), pulseCounter, FALLING); lastTime = millis();
void loop() unsigned long now = millis(); if (now - lastTime >= 1000) // Every second detachInterrupt(digitalPinToInterrupt(2));
flowRate = (pulseCount / PULSES_PER_LITER) * 60.0; // L/min totalLiters += flowRate / 60.0; // Add volume for 1 second Serial.print("Flow Rate: "); Serial.print(flowRate); Serial.print(" L/min\t\tTotal: "); Serial.print(totalLiters); Serial.println(" L"); pulseCount = 0; lastTime = now; attachInterrupt(digitalPinToInterrupt(2), pulseCounter, FALLING);
The YF-S201 is arguably the most popular water flow sensor among hobbyists, students, and engineers working on Arduino, ESP32, or STM32 projects. It is inexpensive, reasonably accurate, and easy to interface. However, when moving from physical prototyping to simulation, many developers hit a wall.
Does a dedicated YF-S201 Proteus library exist?
If you have searched for "YF-S201 Proteus Library" on Google, GitHub, or Labcenter’s official forums, you have likely come up empty-handed. Out of the box, Proteus (version 8 and 9) does not include a native simulation model for flow sensors.
This article serves as a complete resource. We will explore why the library is missing, how to simulate the YF-S201 without a perfect model, and—for advanced users—how to create your own custom Proteus library for the sensor.
Now you have the knowledge to simulate water flow sensing in Proteus without waiting for an official library. Happy simulating!
References & Further Reading
Have you created a custom YF-S201 model for Proteus? Share your .LIB file in the comments below!
The YF-S201 Proteus library is a specialized simulation tool that allows engineers and hobbyists to model water flow measurement systems without physical hardware. By integrating this library into the Proteus Design Suite, you can simulate a Hall-effect water flow sensor and verify your firmware's ability to calculate flow rates and total volume. Core Features and Working Principle
The YF-S201 sensor typically consists of a plastic valve body, a water rotor, and a Hall-effect sensor.
Operating Mechanism: When water flows through the sensor, it spins the internal magnetic rotor.
Pulse Generation: The Hall-effect sensor generates an electrical pulse for every revolution of the rotor.
Calibration: For standard YF-S201 sensors, the output frequency formula is approximately , where is the pulse frequency (Hz) and is the flow rate in liters per minute (L/min). How to Install the YF-S201 Proteus Library yf-s201 proteus library
To add the YF-S201 sensor to your Proteus component list, follow these steps: Water Sensor Library For Proteus - The Engineering Projects
Now that you have a signal source (the DCLOCK), you need code to interpret the frequency. Here is a simple Arduino sketch you can compile and load into the Proteus Arduino model.
The Code:
// YF-S201 Simulation Code for Proteus
// Connect DCLOCK to Digital Pin 2 (INT0)
volatile int pulseCount = 0;
float flowRate = 0.0;
unsigned int flowMilliLitres = 0;
unsigned long totalMilliLitres = 0;
unsigned long oldTime = 0;
void setup()
Serial.begin(9600);
pinMode(2, INPUT);
attachInterrupt(digitalPinToInterrupt(2), pulseCounter, RISING);
void loop()
if ((millis() - oldTime) > 1000) // Only process once per second
// Disable interrupt briefly for calculation
detachInterrupt(digitalPinToInterrupt(2));
// Formula: Frequency / 7.5 = L/min
flowRate = ((1000.0 / (millis() - oldTime)) * pulseCount) / 7.5;
oldTime = millis();
flowMilliLitres = (flowRate / 60) * 1000;
totalMilliLitres += flowMilliLitres;
Serial.print("Flow rate: ");
Serial.print(flowRate);
Serial.print(" L/min\tOutput Frequency: ");
Serial.print(pulseCount);
Serial.println(" Hz");
pulseCount = 0;
attachInterrupt(digitalPinToInterrupt(2), pulseCounter, RISING);
void pulseCounter()
pulseCount++;
No simulation is perfect. Be aware of these limitations before relying entirely on virtual results.
Recommendation: Use the simulation for firmware development and basic system validation. Always test the final product with real water flow and a physical YF-S201.