Counting a loop

Don't use two separate reads in an if/else combination. The second one might give a different answer and cause all sorts of strange behaviour.

Don't bother with servo.read() - it doesn't do anything useful. Just use a variable that records the last value used with servo.write().

Since your code should "know" what it has already told the servo to do I suspect the entire if/else is superfluous.

The delay which you have programmed with delay(100) could better be programmed using the BWOD technique.

To my way of thinking you have far too much code in loop(). The logic of the system would be much easier to follow if the different activities are put into their own functions. And because the code in each function would be short it would also be easy to understand and debug.

...R