I lifted some code others have posted to do a sanity check. I have a 6 window 1" optical wheel on a motor shaft. I have a commercial RPM meter to check against. I am crazy off. The code comments in the post (can't remember where) said scale the number based on the number of windows your wheel has. So I adjusted it to 6 holes per revolution. I am reading 23k RPM when I should be in the 4k RPM range or something. See capture below...RPM and hole counter from the interrupt. Any help is much appreciated.
At least partially because of the issue noted above. Also, if the optical setup is not completely reliable, you will be getting spurious counts at the edges, or missing counts. The only way to be sure is to use an oscilloscope to look at the detector output.
What is the optical detector? Post a link or photo.
This is a 3-D printed wheel and sensor. I will check out the output signal on the Oscope. Tomorrow, my workshop is in the garage. Will post back what I find.
Mixing delay() and millis() is not good. During the delay(2000) the ISR is still incrementing the value of holes so the number will be twice what you expect to collect in one second.
Post a link to that module marked ITR-9608. It may be you need a pull up resistor.
This is the module URL ITR9608-Photo Sensor - CQRobot-Wiki.
Actually this ISR only needs to happen once every 5mins. It is a subroutine in a bigger code I wrote. The other stuff is debugged and works. I just need to go into a subroutine for 100ms to capture enough counts to do a bit of math to figure out RPM.
So I got some image captures running at 5,108 rpm on a commercial meter. No jitter clean transitions. No multiple noise edges. The screen grabs have cursors measuring the pulse edges including period and frequency.
Did all the changes. Still the same thing. I resorted to good old pulsein and it gave the same crudd. I moved from an uno to mega. Same thing. I'm frustrated by this.....