you should declare your numOfRotations as ' volatile unsigned int ' as it appears in both main thread and the ISR routineyou can google what 'volatile ' means
well it is recommended to use variables as volatile inside interrupts. but It doesn't influence on your result generally.I tried all of them and got same results.the problem is, the result from pin2 and pin 3 are not same with same conditions!
try INPUT_PULLUP in pinModeCHANGE over FALLING in attachInterrupt()
I use the program in this link to detect the speed of a small motor. Note how simple the ISR code is and how there is no need for detachInterrupt()...R
Thanks for your answare. The problem is with interrupt 0(pin2). I don't know why, but it does not give me the right answare. interrupt 1 (pin 3) is good and I don't have any problem with my code.
Is that true with my program ?...R
I used your code. It is working well on both of pins 2,3.
So why not use it?...R
Your code has also one second delay to write pulses and without that is not working.
I don't know what you mean by "without that is not working"...R
pulses per second will not be true if you unable those lines!
You don't need a 1 second interval to know the pulse rate. All you need to know is the interval between two pulses (or the interval between a larger number if you want an average.Rather than pick small holes in specific pieces of code that were just prepared as a typical example why not tell us exactly what you want to achieve?...R