IR counter

What distance do you need to cover with the beam? Red/IR LEDs are good for about two meters (depends on where you want to use it), for bigger distances I would choose a laser. The sensor is a simple photodiode/phototransistor.