Hall effect sensors

(oops, there was a serious bug in the code, causing overflows :slight_smile:

What is the range of RPM you expect 0..5000 per minute?
Then, doing the math in millis could be accurate enough,

retry please

//
//    FILE: rpm.pde
//  AUTHOR: 
//    DATE: 20-oct-2012
//
// PUPROSE:
//

volatile unsigned long rpmcount = 0;
unsigned long previous = 0;
unsigned int rpm;
unsigned long time;
unsigned long timeold;

void setup()
{
  Serial.begin(115200);
  attachInterrupt(0, rpm_fun, FALLING);

  rpmcount = 0;
  rpm = 0;
  timeold = 0;
  time = 0;
}

void loop()
{
  unsigned long rounds = rpmcount;
  if (rounds - previous >= 20) 
  {
    // DO THE MATH
    time = millis();  // would millis not be fast enough?
    unsigned long duration = time - timeold;
    timeold = time;
    rpm = ((rounds-previous) * 60000UL / duration); 
    previous = rounds;

    // DO THE OUTPUT
    // comma separated allows you to copy the output into excel
    // and make a nice graph
    Serial.print(duration);
    Serial.print(", ");
    Serial.println(rpm);
  }
}

void rpm_fun()
{
  rpmcount++;
}

another way to calculate the RPM is to measure for 1/10 of a second and then do the math

//
//    FILE: rpm.pde
//  AUTHOR: 
//    DATE: 20-oct-2012
//
// PUPROSE:
//

volatile unsigned long rpmcount = 0;
unsigned long previous = 0;
unsigned int rpm = 0;

unsigned long time = 0;
unsigned long timeold = 0;

void setup()
{
  Serial.begin(115200);
  attachInterrupt(0, rpm_fun, FALLING);
}

void loop()
{
  time = millis();
  if (time - timeold > 100)
  {
    unsigned long duration = time - timeold;
    timeold = time;
    unsigned long rounds = rpmcount;
    rpm = ((rounds - previous) * 60000UL / duration); 
    previous = rounds;
    // DO THE OUTPUT
    // comma separated allows you to copy the output into excel
    // and make a nice graph
    Serial.print(duration);
    Serial.print(", ");
    Serial.println(rpm);
  }
}

void rpm_fun()
{
  rpmcount++;
}

There is still a bug in my code that has to do with assigning long variables, they are not atomic. So in practice the rpmcount can be updated just in the moment it is assigned to rounds. By disabling/enabling the IRQ your original code did not have this issue. So you might still add that to these sketches.