The duty cycle of pulse width modulation is used to adjust the current of the oxyhydrogen generator with on-off square signals. These signals are essential for an oxyhydrogen gas generator to reduce thermal operation, improve the quality of oxyhydrogen gas, and enhance efficiency. A framework combining particle swarm optimization and regression analysis was proposed to determine the minimum temperature and production time of oxyhydrogen gas while maximizing efficiency using a single input, the duty cycle. The optimization results indicated that the duty cycle for the optimum solution remained within the upper and lower temperature boundaries. In this study, particle swarm optimization successfully provided valuable insights for practical applications in renewable energy technologies.