Problem with my optoendstop RRS-OE.

Hi,
I tested my captor with the program of the creator of the captor.
The program have to say open or blocked if the is a signal or not, and it doesn't work at each time. Some signal miss.
How can i know the tinest possibiliy between two signals?
Because, actually, i tested several program of tachymetre and all of them give me sometimes good speed and sometimes the speed is doubled.
For my project, i have to measure the speed of a motor wich i sometimes slow down by touching it (with my hand), and speed it up by realeasing it.
Frequency should between one and 5 hz.
Can you give me advice of sensor?
Thanks you.

Here the program:
//what pin are we using?
#define ENDSTOP_PIN 2

//which opto enstop are we using?
//this is for the H21LOB
#define INVERTED 1
//this is for the H21LOI
//#define INVERTED 0

void setup()
{
pinMode(ENDSTOP_PIN, INPUT);

Serial.begin(9600);
Serial.println("Starting opto endstop exerciser.");
}

void loop()
{
if (digitalRead(ENDSTOP_PIN))
{
if (INVERTED)
Serial.println("open.");
else
Serial.println("blocked.");
}
else
{
if (INVERTED)
Serial.println("blocked.");
else
Serial.println("open.");
}

delay(500);
}

First: Use code tags (that’s the </> button in the editor) when posting code!

How can i know the tinest possibiliy between two signals?

Remove the delay() call in your sketch.

If the serial output is too fast then, save the pin state and print out only if you have a state change.

The output is open collector, do you have input pullup activated?

Hi,
I have changed my code like that pinMode(interruptPin, INPUT_PULLUP); but nothing has changed.

In my project, I need to measure the speed of a motorB (with constant speed in first) and proportionnaly to assign with this measure, the speed of an other motorA
Then, when i will slow down the motor, the other should go slow down as well with less time as possible.

To avoid the problem of the measure, i smoothed data of speed but after i will have too much latency between the real speed of motor A and the assigment of motor B.

An other mediator of the forum told me this about optical sensor: "There is a little equivalent of the "mechanical rebounds" around the optical transition zone, so you can end up with several "CHANGE" fast before being in a stable state ".

So how can i avoid those "mechanical rebounds" ?

I need to measure the speed of motor between 5 and 0 round par secound. What is the most appropriated sensor?

If i make an wheel with a lot of hole, will i have more precision with less problems of rebounds?

Or last solution, which is the best sensor in the market specilized to encode the speed of a motor of 0 to 5 hz? or even a motor with an encoder.
Thanks you for all advices.