An optical sensor device has an illuminating light source and an image
sensor. The image sensor captures a sequence of images under exposure of
light from the light source. A controller in the optical sensor device
has a control output and generates an exposure time control signal on the
control output. The controller includes an exposure time control loop.
Each iteration of the loop includes the steps: calculating an error
between a set value and an actual luminance condition value determined in
a current image in the sequence of images; calculating a current exposure
time as a function of the error and an exposure time calculated during
the preceding iteration of the control loop; and generating the exposure
time control signal on the control output based on the current exposure
time. The exposure time may thereby be determined so as to yield optimum
contrast in an image which is to be captured by the image sensor.