Hi all, I am trying to make a RPM sensor for my bot. I am using Arduino and this hall effect sensor that i got:
I have made a small bench setup to prove the concept. See attached snap. I am using 8 equidistant magnets around the perifery of the sprocket. Here is the arduino program:
const int ledPin = 13;
volatile int rpmcount;
int sensorState = 0;
unsigned int rpm;
unsigned long timeold;
void rpm_fun()
{
rpmcount++;
digitalWrite(ledPin, HIGH);
delay(50);
digitalWrite(ledPin, LOW);
}
void setup() {
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
attachInterrupt(0, rpm_fun, FALLING);
}
void loop(){
if(rpmcount>=5) {
rpm=(60000rpmcount)/(8(millis()-timeold)); //the 8 changes to 4 if 4 magnets are used.
timeold = millis();
//Serial.println(rpmcount,DEC);
rpmcount = 0;
Serial.println(rpm,DEC);
}
}
Here is the problem:
At slow speeds this setup works and i can read correct rpm value on the serial monitor. But at higher speeds, the hall effect sensor does not detect the magnet or the arduino doesnt get the interrupt. The magnets are very powerfull and work from even 15mm away. I have tried this with 4 and 1 magnet around the periphery but at higher speeds the magnet is not detected.
What can be causing this? Is the hall sensor not switching at high enough frequency? Am I messing something in the setup? I have tried changing the distance between the magnet and the sensor but no difference.