Advertisement
microrobotics

Untitled

Jul 27th, 2021
5,890
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Reading liquid flow rate using an Arduino
  2.  
  3. volatile int NbTopsFan;            //measuring the rising edges of the signal
  4. int Calc;
  5. int hallsensor = 2;                //The pin location of the sensor
  6.  
  7. void rpm ()                        //This is the function that the interupt calls
  8. {
  9.   NbTopsFan++;                     //This function measures the rising and falling edge of signal
  10. }                                  //The setup() method runs once, when the sketch starts
  11.  
  12. void setup()
  13. {
  14.  pinMode(hallsensor, INPUT);       //initializes digital pin 2 as an input
  15.  Serial.begin(9600);               //This is the setup function where the serial port is initialised
  16.  attachInterrupt(0, rpm, RISING);  //and the interrupt is attached
  17. }
  18.                                    // the loop() method runs over and over again
  19.                                    // as long as the Arduino has power
  20. void loop ()
  21. {
  22.  NbTopsFan = 0;                    //Set NbTops to 0 ready for calculations
  23.  sei();                            //Enables interrupts
  24.  delay (1000);                     //Wait 1 second
  25.  cli();                            //Disable interrupts
  26.  Calc = (NbTopsFan * 60 / 7.5);    //(Pulse frequency x 60) / 7.5Q = flow rate in L/hour
  27.  Serial.print (Calc, DEC);         //Prints the number calculated above
  28.  Serial.print (" L/hour\r\n");     //Prints "L/hour" and returns a new line
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement