The invention provides a robot suitable for detecting underwater and overwater parts of a bridge pile foundation and a control method. The robot comprises a rack, holding mechanisms, a walking mechanism, a rotating mechanism, an adjusting mechanism, an observation mechanism and the like. An upper layer holding mechanism and a lower layer holding mechanism are arranged, each layer is composed of two parts which are symmetrical left and right, every two parts are connected through a middle power source and a commutator, torque output by the power sources is converted into two holding lead screw mechanisms which are installed on guide rails in the left horizontal direction and the right horizontal direction, and the holding lead screw mechanisms move to drive holding blocks connected to the holding lead screw mechanisms to move left and right. The upper layer holding mechanism and the lower layer holding mechanism are installed on the walking mechanism, two ends of the walking mechanism are fixed on the rack, one end of the walking mechanism is fixedly connected with one layer of holding mechanism, a movable walking nut is connected with the other layer of holding mechanism, the holding mechanism connected with the movable walking nut is driven to move up and down through vertical movement of the movable walking nut on a walking lead screw, and the robot moves up and down along the pile foundation in cooperation with holding and loosening of the holding mechanisms.