Calculating water flow rate based on the pulses counted

In this part, we measure the pulses and convert them to the flow of water using the following steps:

  1. Open a new Arduino IDE, and copy the following sketch.
  2. Verify and upload the sketch on the Arduino board.
            int pin = 2; 
            volatile unsigned int pulse; 
            constintpulses_per_litre = 450; 
     
            void setup() 
            { 
              Serial.begin(9600); 
     
              pinMode(pin, INPUT); 
              attachInterrupt(0, count_pulse, RISING); 
            } 
    
  3. The following code will calculate the pulses that are reading from the sensor; we divide the number of pulses counted in one second, and we have pulses per liter:
          void loop() 
          { 
            pulse = 0; 
            interrupts(); 
            delay(1000); 
            noInterrupts(); 
     
            Serial.print("Pulses per second: "); 
            Serial.println(pulse); 
     
            Serial.print("Water flow rate: "); 
            Serial.print(pulse * 1000/pulses_per_litre); 
            Serial.println(" milliliters per second"); 
            delay(1000); 
          } 
          void count_pulse() 
          { 
            pulse++; 
          } 
    
  4. Open the Arduino Serial Monitor, and blow air through the water flow sensor using your mouth. The number of pulses per second and the water flow rate in milliliters per second will be printed on the Arduino Serial Monitor for each loop, as shown in the following screenshot:
    Calculating water flow rate based on the pulses counted
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.224.61.19