In this study, an optimal control algorithm is proposed to overcome low performance problems arising from the non-linear characteristics of pneumatic motor in compressed air-based energy conversion systems. The effectiveness of the proposed algorithm is tested on an energy conversion system which includes a compressor, a proportional valve, a pneumatic motor (PM), a permanent magnet direct current (PMDC) generator and a control card. The control function of the system is carried out by driving the proportional valve with the control signals which is obtained depending on the PMDC generator output voltage error. In this structure, an optimal proportional-integral-derivative (PID) controller which tunes on-line its own gain parameters by particle swarm optimization (PSO) algorithm according to the operating conditions of the system used. In order to observe the effects of PSO-based PID controller on the system performance, the energy conversion system is also controlled by a discrete time PID controller. The experimental results show that PSO-based PID controller provides more robust control performance than discrete time PID controller under various operating conditions.