The Vertical takeoff landing Flying Robot Contest competition, which is one of the branches of the Indonesian Flying Robot Contest (KRTI) in 2021, provides a new challenge, namely that there is an obstacle that will hinder the movement of the flying robot which is likened to a building whose placement is will be carried out randomly and the competition will be held indoors causing the GPS and Barometer values to be unusable. This system uses the Pixhawk flight controller, Raspberry Pi 4, RPLIDAR, OpticalFlow, Ultrasonic GY-US42 and robot operating system (ROS) frameworks. The Bug2 algorithm can be a solution because it has a lightweight process and only requires input parameters from the Lidar sensor distance and global position from the OpticalFlow sensor. The application of the Bug2 algorithm uses a speed value of 1 m/s and a detection distance of 1.5 m according to the test by simulating the Gazebo. For obstacle detection, the Bug2 algorithm gets success results at 90%, a travel time of 24.3 seconds, and CPU usage of 63%.