The control algorithm of path tracking is very important for wheeled mobile robot. This paper proposes an algorithm that drives a wheeled mobile robot to a desired path, including obstacle avoidance capabilities. The main objective of this paper is to obtain a collision-free trajectory from the starting point to the target in monitoring environments. In this work, ultrasonic sensors are adopted to implement a real-time obstacle avoidance system for wheeled robots, so that the robot can continually detect surroundings, and avoid obstacles. In this paper, the position of the motor is controlled by using PID controller and PD controller was used in the wallfollowing method to achieve the optimized path design. In this paper, experimental results of motor control and simulation results for mobile robot's path were shown using MATLAB software. Microcontroller was used as a brain of mobile robot.