Autofocus is a procedure for finding the correct position of the lens for a scene. The autofocus feature can be provided in a system which includes a movable optical element, a motor, an image sensor and a processing unit. The autofocus procedure is done by changing the lense position and image quality measurements in each position. The position that provides the image with the best quality will be used as the best focus.