Sliding mode control is a robust technique that is used to overcome difficulties such as parameter variations, unmodeled dynamics, external disturbances, and payload changes in the position-tracking problem regarding robots. However, the selection of the gains in the controller could produce bigger forces than are required to move the robots, which requires spending a large amount of energy. In the literature, several approaches were used to manage these features, but some proposals are complex and require tuning the gains. In this work, a sliding mode controller was designed and optimized in order to save energy in the position-tracking problem of a two-degree-of-freedom SCARA robot. The sliding mode controller gains were optimized usinga Bat algorithm to save energy by minimizing the forces. Finally, two controllers were designed and implemented in the simulation, and as a result, adequate controller gains were found that saved energy by minimizing the forces.