I am trying to measure the RPM of a shaft using a neodymium magnet attached to a shaft and reed switch measuring the rotation.
At the minute I'm still just trying to get the reed and Arduino to acknowledge that the reed switch is measuring the magnet but I'm not sure about my code, would someone be able to look it over?
//need to define which pin reed is connected to #define reed A0
float radius = 0.246063;
int reedVal;
long timer=0;
float mph=0.00;
float circumference;
int maxReedCounter = 100;
int reedCounter;
rogAberdeen:
I'm still just trying to get the reed and Arduino to acknowledge that the reed switch is measuring the magnet
What does this mean?
Has your setup not even been proven to be reliable before you skipped a bunch of steps and lost yourself?
Make something simple. An LED that flashes every time the magnet trips the reed switch or something. Or make a code that gives a raw count and see if it matches what would be expected.
What kind of RPMs are you working with? Throwing the weight of a magnet onto the spinning shaft already sounds like a poor engineering decision.
That is, if you absolutely must stick to this approach of using a magnet/reed switch contraption instead of a more sensible optical system.
The material of the magnet doesn't matter. Unless it is bar shaped and is parallel to the orientation of the reed switch,so the magnetic lines of force, N and S, go through the reeds of the magnetic switch. Otherwise there is great potential for the reeds to bounce, giving false indication to your program.
Please read the first post in any forum entitled how to use this forum. http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
What shaft speed are you trying to measure?
As said previously, a reed switch is not a good choice because of contact bounce and the fact that they are relatively slow compared to hall effect devices.
This is derived from code I use with an optical detector to monitor the speed of a small DC motor. It should work with any sensor that produces a pulse.
volatile unsigned long isrMicros;
unsigned long latestIsrMicros;
unsigned long previousIsrMicros;
volatile boolean newISR = false;
void loop() {
 if (newISR == true) {
  previousIsrMicros = latestIsrMicros; // save the old value
  noInterrupts(); // pause interrupts while we get the new value
    latestIsrMicros = isrMicros;
    newISR = false;
  interrupts();
  microsThisRev = latestIsrMicros - previousIsrMicos;
}
void myISR() {
 isrMicros = micros();
 newISR = true;
}