Passive dynamic walking biped robots utilize the inherent dynamics of their structure to achieve walking motion without continuous actuation, enhancing energy efficiency and stability. Replacing conventional rigid legs with flexible elastic beams in the simplest passive walker will be associated with undesirable vibrations. Despite the positive effect of the damper in reducing vibrations, the current research has used the piezoelectric energy harvesting with the aim of reducing the wasted energy of the gait cycle and improving its stability range. For this purpose, the electromechanical Lagrange equations are determined by applying Hamilton's principle and the assumed mode method and then, the new definition of the step function is obtained through numerical methods, solving a boundary value problem to establish proper initial conditions for stable walking. Numerical simulations indicate that the piezoelectric energy harvester can create a stable period-one gait cycle by optimizing the length of the piezo layers attached to the undamped elastic legs despite the presence of small vibrations. Additional results are presented in bifurcation diagrams, investigating the effect of important physical and structural parameters such as slope angle, length and thickness of the piezo layer.