Help counting number of times a pin is 'high' in set time.

Hello,
I am trying to interface a H21a1 with my arduino to help measure the speed at which a wheel on a small robot spins. For those unfamiliar, the H21a1 is just a small optical interrupter switch. I have hooked the H21a1 up correctly and I can verify it does work, however my code keeps returning crazy results, and I can not seem to resolve why. I would like to apologize in advance, for I fear it is some simple error I can not pick up. I have only been using the arduino for about a week, and this is also my first time learning a programming language. Below is the code I have typed up.

//................................................all consants used.........................
const int rpmPin =  13;      // the number of the sensor input pin
const int spokes = 30;    // number of spokes on reading sproket X2
const int wheelDiameter = .1; //wheel diameter in m
const int interval = 250;            // time, in millisec between readings
//...
int wheelSpeed = 0;          // speed wheel is rotating
int rpm = 0;             // number of sprokets read
int previousRead = 0;    // previous sensor input
int currentRead = 0;            // current sensor input
long previousMillis = 0;        // will store last time LED was updated

void setup() {
  pinMode(rpmPin, INPUT); 
  Serial.begin(9600); 
}

void loop()
{
//..............................count numer of spokes going by..........................
  currentRead = digitalRead(rpmPin);
  if(currentRead != previousRead);
  {
    rpm ++;
    previousRead = currentRead;
  }
//......................Calculate rpm/speed and send over serial...............
  unsigned long currentMillis = millis();
 
  if(currentMillis - previousMillis > interval) 
  {
    previousMillis = currentMillis;   
    wheelSpeed = ((rpm / spokes) * 3.14 * wheelDiameter) * (1000/interval);
   Serial.print(wheelSpeed);
   Serial.println(" m/s");
   Serial.println(rpm);
   Serial.print((rpm / spokes)*(1000/interval));
   Serial.println(" rpm");
   rpm = 0;
  }
}

All this code is trying to do, is count how many times the beam of light is interrupted in 250 millisec. Using that number, and the info provided, it should then be able to calculate speed in m/s. However, as of right now, the reading ALWAYS says 0m/s and around 22000 for the value of 'rpm'.
Any and all help will be greatly appreciated! Thank you

const int wheelDiameter = .1; //wheel diameter in m

Integer can’t be 0.1, so it’s always = 0. Declare “float”.
Avoid this math: (rpm / spokes), you work with integer, so when rpm < spokes (30) result 0, 30 < rpm < 60, result 1. In other words it will round to 30, which is very inaccurate. Reorganize your formula in a way : multiply everything first, than divide, or even exclude division at all, just multiply float 0.0333 instead of division by 30

Ok, that makes sense as to why the equation isn't working! However I am confused as to how to use floating numbers. I have updated the code to this, but am not sure if I successfully set the equation to solve by floating. I apologize for my lack of knowledge on the subject! Also, changing the variable to a floating variable did not help with the fact that 'rpm' always has a value of around 22000.

//................................................all consants used.........................
const int rpmPin =  13;      // the number of the sensor input pin
const int spokes = 30;    // number of spokes on reading sproket X2
float wheelDiameter = .1; //wheel diameter in m
const int interval = 250;            // time, in millisec between readings
//...
float wheelSpeed = 0;          // speed wheel is rotating
int rpm = 0;             // number of sprokets read
int previousRead = 0;    // previous sensor input
int currentRead = 0;            // current sensor input
long previousMillis = 0;        // will store last time LED was updated

void setup() {
  pinMode(rpmPin, INPUT); 
  Serial.begin(9600); 
}

void loop()
{
//..............................count numer of spokes going by..........................
  currentRead = digitalRead(rpmPin);
  if(currentRead != previousRead);
  {
    rpm ++;
    previousRead = currentRead;
  }
//......................Calculate rpm/speed and send over serial...............
  unsigned long currentMillis = millis();
 
  if(currentMillis - previousMillis > interval) 
  {
    previousMillis = currentMillis;   
    wheelSpeed = (float) ((rpm / spokes) * 3.14 * wheelDiameter) * (1000/interval);
   Serial.print(wheelSpeed);
   Serial.println(" m/s");
   Serial.println(rpm);
   Serial.print((rpm / spokes)*(1000/interval));
   Serial.println(" rpm");
   rpm = 0;
  }
}

To tell the compiler that you want to do floating-point calculations, one of the operands must be a floating point number. Any variable you declare "float" or "double" is obviously floating point. Any constant with a decimal point is a floating point number

float var1 = 1; // float
double var2 = 5; //float
5; // int
8.2 // float
8.0 // float

5/8 != 0.625; // Integer arithmetic rounds down
var2/8 == 0.625; //var2 is floating point, even though 8 is an int
5.0/8 == 0.625; // 5.0 is floating point
5.0/8.0 == 0.625; // They're both floating point

wheelSpeed = (float) ((rpm / spokes)

It should be :
wheelSpeed = (( (float)rpm / spokes) - casting before division, not after.
There is a link with better approach to do the same thing, using interrupt:

linked from: Arduino Playground - HomePage

I have a frequency counter here:

Two different approaches are described on that page. One is to count pulses over time, literally getting the frequency. The other is to measure the length (period) of a single pulse, from which you can deduce the frequency by inverting it.

Both methods use the hardware timers, rather than mucking around testing pins and using millis() or micros(), either of which are going to introduce a bit of jitter depending on exactly when you test the pin.

I have seemed to have got it working! Using interrupts helped a TON, I will defiantly remember to use those again! I want to thank you magician for all your help on the equations and floating numbers! This is my code I ended up with, and as far as I can tell it works like a charm!

//................................................all consants used.........................
const int spokes = 30;    // number of spokes on reading sproket X2
float wheelDiameter = .1; //wheel diameter in m
const int interval = 250;            // time, in millisec between readings
//.................................................................................
float wheelSpeed = 0;          // speed wheel is rotating
volatile int rotations = 0;             // number of sprokets read
long previousMillis = 0;        // will store last time rotaions was updated

void setup() {
  Serial.begin(9600); 
  attachInterrupt(0, sproket, CHANGE); //sensor input tied to pin 2
}

void loop()
{
//......................Calculate rpm/speed and send over serial...............
  unsigned long currentMillis = millis();
 
  if(currentMillis - previousMillis > interval) 
  {
    previousMillis = currentMillis;   
    wheelSpeed =  ((  (float)rotations / spokes) * 3.14 * wheelDiameter) * (1000.0/interval);
   Serial.print(wheelSpeed);
   Serial.println(" m/s");
   Serial.print((rotations / spokes)*(1000/interval));
   Serial.println(" rpm");
   rotations = 0;
  }
}
//........................ Monitor number of spokes passing by....................
void sproket()
{
  rotations += 1;
}

Nice, one more things to mention, if you getting right numbers.
Could be that this line count each spoke twice:
attachInterrupt(0, sproket, CHANGE); //sensor input tied to pin 2
Try Faling or Rising

Magician:
Nice, one more things to mention, if you getting right numbers.
Could be that this line count each spoke twice:
attachInterrupt(0, sproket, CHANGE); //sensor input tied to pin 2
Try Faling or Rising

Yep I noticed that and did account for it when listing the number of spokes, I did change it to falling however, so as to make it easier for future referance! Thanks again