The navigation of mobile robots using heuristic algorithms is one of the important issues in computer and control sciences. Path planning and obstacle avoidance are current topics of navigational challenges for mobile robots. The major drawbacks of conventional methods are the inability to plan motion in a dynamic and unknown environment, failure in crowded and complex environments, and inability to predict the velocity vector of obstacles and non-optimality of the synthesised path. This paper presents a novel path planning approach using a grasshopper algorithm for navigation of a mobile robot in dynamic and unknown environments. To accomplish this goal, two different approaches are presented. First, a sensory system is used to detect the obstacles and then a new method is developed to predict and avoid static and dynamic obstacles while the velocity of obstacles is unknown. The robot uses the obtained information and finds a collision-free, optimal and safe path. The controller proposed in this paper is tested in crowded and complex environments. Simulation results show that the approach is successful in all test environments. Also, the proposed controller is compared with several heuristic methods. The comparison work stipulates that the introduced controller here is promising in terms of running time, optimality, stability and failure rate.