Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 30th, 2012  |  syntax: Java  |  size: 1.07 KB  |  hits: 24  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. volatile int NbTopsFan; //measuring the rising edges of the signal
  2. int Calc;                              
  3. int hallsensor = 3;    //The pin location of the sensor
  4.  
  5. void rpm ()     //This is the function that the interupt calls
  6. {
  7.   NbTopsFan++;  //This function measures the rising and falling edge of the hall effect sensors signal
  8. }
  9.  
  10. void setup() //
  11. {
  12.   pinMode(hallsensor, INPUT); //initializes digital pin 2 as an input
  13.   Serial.begin(9600); //This is the setup function where the serial port is initialised,
  14.   attachInterrupt(1  , rpm, RISING); //and the interrupt is attached
  15. }
  16. void loop ()    
  17. {
  18.   NbTopsFan = 0;   //Set NbTops to 0 ready for calculations
  19.   sei();      //Enables interrupts
  20.   delay (1000);   //Wait 1 second
  21.   cli();      //Disable interrupts
  22.   Calc = (NbTopsFan * 60 / 5.5); //(Pulse frequency x 60) / 5.5Q, = flow rate in L/hour
  23.   Serial.print (Calc, DEC); //Prints the number calculated above
  24.   Serial.print (" L/hour\r\n"); //Prints "L/hour" and returns a  new line
  25.   Serial.print (NbTopsFan);
  26.   Serial.print (" rising edges\r\n");
  27.  
  28. }