For my project i'm making a dyno for a gokart engine. To grab the RPM i am using a slotted optical sensor to detect a plate attached to the shaft. The sensor works perfectly when just rotating the shaft or through testing using a bent nail and a drill. However when i start up the engine the spark plug and related ignition system is inducing a lot of EMI into the system which is causing alot of false triggering with the interrupt system, also caused my arduino to stop talking through USB. I've moved the sensor further away and added a shielded cable with some ferrite cores but that has only reduced but not eliminated the problem. I am thinking about using a debounce but would prefer not to in order to keep accuracy. I'm planning on adding a low pass filter using a resistor and capacitor but was wondering if anyone has any suggestions on how to trim the spikes. I've looked around but believe its not possible to change what arduino thinks a high and low value are. The values from the sensor are pretty clean between 4.9v and 0v just need to reduce the ~2.5v spikes from causing a false trigger.