volatile int pulseCount = 0; float flowRate = 0.0; float totalLiters = 0.0; unsigned long oldTime = 0;

void pulseCounter() pulseCount++;

void loop() if (millis() - oldTime >= 1000) detachInterrupt(0);

void setup() pinMode(2, INPUT_PULLUP); attachInterrupt(digitalPinToInterrupt(2), pulseCounter, RISING); lcd.begin(16, 2); lcd.print("Flow Meter Ready"); delay(2000); lcd.clear(); oldTime = millis();

pulseCount = 0; attachInterrupt(digitalPinToInterrupt(2), pulseCounter, RISING); oldTime = millis();

| Benefit | Explanation | |---------|-------------| | | No need to buy physical sensors for initial testing | | Rapid prototyping | Test code changes in seconds | | Debugging | View pulse trains, count interrupts virtually | | Education | Safe environment for students learning flow sensors | | Hardware independence | Simulate even when sensor is out of stock |