Yfs201 Proteus Library
Paste the file path into the field and click OK.
volatile int pulseCount = 0; float flowRate = 0.0; unsigned int flowMilliLitres = 0; unsigned long totalMilliLitres = 0; unsigned long oldTime = 0; const byte sensorPin = 2; // Connected to YF-S201 Output void pulseCounter() pulseCount++; void setup() Serial.begin(9600); pinMode(sensorPin, INPUT_PULLUP); // Trigger pulseCounter on falling edge attachInterrupt(digitalPinToInterrupt(sensorPin), pulseCounter, FALLING); void loop() if((millis() - oldTime) > 1000) // Detach interrupt while calculating to prevent data corruption detachInterrupt(digitalPinToInterrupt(sensorPin)); // Calculate flow rate in Liters per minute based on sensor calibration factor (7.5) flowRate = ((1000.0 / (millis() - oldTime)) * pulseCount) / 7.5; oldTime = millis(); // Determine volume passing through per second flowMilliLitres = (flowRate / 60) * 1000; totalMilliLitres += flowMilliLitres; // Print the results to the Virtual Terminal Serial.print("Flow rate: "); Serial.print(flowRate); Serial.print(" L/min"); Serial.print("\t Total Liquid: "); Serial.print(totalMilliLitres); Serial.println(" mL"); // Reset pulse counter and restart interrupt monitoring pulseCount = 0; attachInterrupt(digitalPinToInterrupt(sensorPin), pulseCounter, FALLING); Use code with caution. Running and Verifying the Simulation
The is a Hall Effect water flow sensor often used in Arduino projects to measure liquid flow rates. Since it is not a native component in the standard Proteus database, you must install an external library or use a pulse generator to simulate its output. 📥 Finding the Library yfs201 proteus library
Which are you planning to pair with the sensor?
void setup() Serial.begin(9600); // Attach interrupt to Pin 2 (Interrupt 0 on Uno) pinMode(2, INPUT_PULLUP); attachInterrupt(digitalPinToInterrupt(2), pulseCounter, FALLING); Paste the file path into the field and click OK
When you run the simulation, you may need to adjust the "flow rate" by clicking on the sensor and changing its frequency or pulse properties to mimic different water speeds.
Before starting the simulation, it is essential to understand how the physical sensor communicates with microcontrollers like Arduino. Since it is not a native component in
In Proteus, your virtual YFS201 will generate a virtual frequency that your microcontroller code can interpret.
: Attach VCC pins to the +5V power rail tool and GND pins to the GROUND tool rail in Proteus. Arduino Code for Simulation Testing
While simulation provides consistent pulses, physical sensors may need calibration for precise flow rates (typically pulses per second per liter/min).
Unlike a simple switch, the YFS201 library contains a called Frequency or FlowRate . When you run the simulation, the OUT pin toggles at this frequency.
