In an optical code detection system and method, infrared pulses are utilized to detect the presence of an object within the range of an optical imaging device, but the image of an infrared pulse reflected from the object is also analyzed to determine the distance between the object and the imaging device. An illumination pulse is then produced to illuminate the optical code on the object, and the characteristic of that pulse, such as duration, are controlled to provide appropriate exposure for an object at the detected distance.