I tried a program to find the rpm of a wheel using an IR sensor... i dont have hardware ready now, so i cant check it
pls tell me if this will work
int count=0; //number of rotates
unsigned int r; //rotates per minute
unsigned long int pretime=0; //previous time
void setup()
{
Serial.begin(9600);
pinMode(2,0); //IR sensor at pin 2
attachInterrupt(0,cnt,RISING); //function cnt called when
} //IR output signal goes from LOW to HIGH
void loop()
{
unsigned long int curtime=millis(); //current time
if((curtime-pretime)>5000) //calculating rpm every 5 second
r=count/(curtime-pretime)*1000*60;
Serial.print("count : ");
Serial.println(count);
Serial.print("rpm : ");
Serial.println(r);
pretime=millis(); //updating previous time and count
count=0;
delay(1000);
}
void cnt()
{
count++;
}