Interference on slotted optical switch.

Hi,

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.

Ignition systems are the worst possible environment for electronics - make everything shielded, shielded cables, metal boxes etc etc, use low impedances. On the input to the Arduino use a 100 ohm series resistor, 100pF cap to ground, schottky diodes to the rails to clip transients. Oscilloscope is almost essential to debug this sort of stuff...

Tried most of that without much success. As you say way to much EMI from the engine. I ended up using a Schmitt trigger to help reduce the noise and then using just a simple digital read and analogue read found that the data from the sensor is fine. The problem starts when i use an interrupt trigger in the arduino. It works fine without the engine running but with the engine running and not changing the sensor at all spikes are occurring so it is interfering with the actual arduino and causing false triggers. I've got a workaround by just dumping the value of the sensor and calculating the RPM using post processing but it would be nice to stop it happening.