1. A device for controlling a driven moving element, the device comprising an electronic unit with an object sensor, wherein the object sensor of the electronic unit is an optical sensor that is arranged above the driven moving element and which determines an object distance between the driven moving element and an object in the region of the driven moving element and controls movement of the driven moving element depending on the object distance, wherein the electronic unit uses only a front edge of the driven moving element, which is a first part of the driven moving element that would otherwise collide with the object, as a reference for the driven moving element to determine the object distance.