The invention relates to a robot and a method for controlling a robot. The distance between an object and the robot and/or the derivative thereof or a first motion of the object is detected by means of a non-contact distance sensor arranged in or on a robot arm of the robot and/or on or in an end effector fastened on the robot arm. The robot arm is moved based on the first motion detected by means of the distance sensor, a target force or a target torque to be applied by the robot is determined based on the distance detected between the object and the robot, and/or a function of the robot or a parameterization of a function of the robot is triggered based on the first motion detected and/or a target distance between the object and the robot and/or the derivative thereof detected by means of the distance sensor.