I'm working on a project controlling standard dc motors via a photoelectic sensor with a lm393 and an encoder disc.
I connect the sensor to digital pin 2 and attach an interrupt via
attachInterrupt(digitalPinToInterrupt(2), sensor1Pulse, FALLING);
sensor1Pulse() just increases or decreases an integer according to a +1, or -1 rotation variable.
I also tried with RISING.
I tried with my Uno rev3, my Nano rev3 and my Mega2560, but interrupt mode does not seem to have any effect. When defining FALLING it also triggers on rising input, and vice versa.
The sensor output seems as expected and I tried with all 4 sensors I own. Dso oscilloscope (and dito my cheap multimeter) shows the output potential is around 0.2 V when not blocked and 4.2V when the ir-light is blocked. The transition does not seem overly bouncy or noisy, but quite "sharp". The sensors indicator-led also behaves as expected.
A problem that might be related to this is that I get incorrect results, when I spin the motor which is connected to the encoder disc at a certain speed (i.e. I use a Lego motor and when supplied with more than 6V there seem to be ignored steps). But I have seen examples of motors spinning way faster and encoder discs having way more steps per revolution - and my interrupt routine is even shorter and less complex than the code used in corresponding examples (they often use 2 sensors to also detect rotation direction and need to differenciate that in interrupt triggered method - I just check a rotation direction value and increase or decrease step count accordingly).
The problem does not seem to be related to how I control the motor itself - it is same, when I power it externaly, as when I power it via anduino and h bridge.
What might I be missing? Are all my 3 arduino defect?