Encoder coupled with motor shaft.Encoder is giving larger redings than expected
I guess this is a kind of debouncing problem, caused by noise on the interrupt pin. The behaviour might also get worsened by the disalignment you mentioned. You could verify this by manually rotating the shaft, even though you "get the blinks" I doubt they are accurate in count.

If that is the case there are two things you could do:


add a capacity or a RC filter to the interrupt pin to smoothen out voltage peaks if there are some. This will decrease the chance that the interrupt gets triggered accidentially (and will not solve the problem), but as a low pass it also limits the maximum count rate you are able to detect.
implement debouncing in software. This is usually done by ignoring the input signal for a specific amount of time ("deadtime") after an interrupt has occured. As you are expecting a periodic signal and debouncing behaviour might be different at different speed it could be a good idea to capture the time span between two "blinks" and make the deadtime dependend on this calculated speed.


Something else: the way you check for the timestamp is little incorrect. You should instead do something like this:

void setup() {
  unsigned long starttime=millis();
}

void loop() {
  if (millis()-starttime &gt; 5000) {
    starttime=millis();
    // put code here to run every 5000 ms
  }
}