The robots science has been developed over the past few years, where robots have become used to accomplish difficult, repetitive or accurate tasks, which are very hard for humans to carry out. In this paper, we propose an algorithm to control the motion of a swarm of robots and make them able to avoid obstacles. The proposed solution is based on forming the robots in circular fashion. A group set of robots consists of multiple groups of robots, each group of robots consists of robots forming a circular shape and each group set is a circular form of robots. The proposed algorithm is concerned with first locating the randomly generated robots in groups and secondly with the swarm robot motion and finally with the swarm obstacle avoidance and swarm reorganization after crossing the obstacle. The proposed algorithm has been simulated with five different obstacles with various numbers of randomly generated robots. The results show that the swarm in the circular form can deal with the obstacles very effectively by passing the obstacles smoothly. The proposed algorithm has been compared with flocking algorithm and it is shown that the circular formation algorithm does not need extensive computation after obstacle avoidance whereas the flocking algorithm needs extensive computation. In addition, the circular formation algorithm maintains every robot in its group after avoiding the obstacles whereas with flocking algorithm does not.