Photo interrupter outputting erratic analog signal

Two things.

  1. This is a digital device, so the output should be connected to a digital pin.

  2. It has an open collector output, so it needs a pull up resistor to 5volt.

Or, easier, enable the internal pull up resistor on the pin in setup().

pinMode(PhotoPin, INPUT_PULLUP);

Leo..