Measuring RPM using Hall sensor A3144

Hi Paul,

I am sorry for the late reply. I changed the variable speed into velocity because speed was showing in orange, so I guessed it must be a keyword of some sort for Arduino and best not used as a variable.

This is the code I have :

volatile byte revolutions;
byte revs;                                                   //** revolutions goes into this**
unsigned int rpmilli;
float velocity;
volatile unsigned long timeold;
unsigned long milliseconds;           // **millis() goes into this**
float wheel_circ = 1.634;

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

  revolutions = 0;
  rpmilli = 0;
  timeold = 0;
}

void loop()
{
  if (revolutions >= 10)                         //** Update RPM every 10 counts**
 { 
   revs = revolutions;
   milliseconds = millis();
   
   rpmilli = revs/(milliseconds - timeold);          // **calculate the revolutions per milli(second)**
   timeold = milliseconds;
    revolutions = 0;
    velocity = rpmilli * wheel_circ/ 1000;      // speed in meters per second
    velocity = 2.237*velocity;                    // speed in miles per hour

    Serial.print(" Speed:");
    Serial.print(velocity,DEC);
    Serial.println(" mph");
  }
}

void rpm_fun()
{
  revolutions++;
}

The display I get however when I bring the magnet close and far from the sensor is still 0.000000000 mph.