I am writing some code to get RPM from a shaft using a magnet and reed switch. However I know that the speed will not be over 5000RPM. The reed switch seems fine from 0 to around 2500rpm but then it jumps up to 9000rpm plus and not very steady. It fluctuates from 9000 to 11000
My question is would a Hall sensor be better and more accurate? what type voltage etc.
Also I have found a wire hall effect on a machine, how does that work a and how to wire it up.
For info here is the code I am using
//-----------------------------------------------
volatile byte rpmcount;
unsigned long time;
unsigned int rpm;
unsigned long timeold;
void setup()
{
Serial.begin(9600);
attachInterrupt(0, rpm_fun, FALLING);
rpmcount = 0;
rpm = 0;
timeold = 0;
time = 0;
}
void loop()
{
if (rpmcount >= 20) {
//Update RPM every 20 counts
detachInterrupt(0);
Serial.print("rpmcount");
Serial.println(rpmcount);
Serial.print("micros");
Serial.println(micros());
Serial.print("timeold ");
Serial.println(timeold);
time = micros() - timeold;
Serial.print("Time ");
Serial.println(time);
RPM= (60000000/time) * 20
Serial.print("RPM");
Serial.println(RPM);
timeold = micros();
rpmcount = 0;
attachInterrupt(0, rpm_fun, FALLING);
}
}
void rpm_fun()
{
rpmcount++;
}
//-----------------------------------------------