As far as I can tell from your limited description, you are using some homebrew optocoupler to defect some opaque object passing between the LED and the photodiode.

What are the usual failure modes here:

1. Optics lose alignment. I.e. the brightest spot of the LED is not on the photodiode anymore.

Reasons: Mechanical stress, substandard build quality.

Mitigation: There are factory-made air-gapped optocouplers that could perform better in this regard. They have a rigid package containing both elements aligned against each other.

Mitigation 2: Use visible light LED. They still can lose alignment, but one would be in a better position to diagnose what happened.

2. The LED ages and dims. 

Reasons: Mediocre quality LED driven at high current.

Mitigation: Use better LED, drive it 50% of the rated current (or lower). Be aware that this will lower the signal/noise at the receiver side.

Mitigation 2: use AC-driven LED, detect AC signal at the receiver side. Complex. On the other hand, you may find an "optical sensor" element that does everything this in a single package.

3. The LED and/or the photodiode accumulating dust.

Reason: it simply happens, especially when something moves.

Mitigation: air the dust once in a while.

Mitigation 2: Use another kind of sensor (e.g. magnetic, acoustic, capacitive) if applicable.