Parameter optimization of PID control is always a hot spot in the research field of control, and control effect of PID depends on the parameter values: proportion, integral and differentiation. This paper puts forward a global best and local best PSO algorithm, which is an optimization strategy of PID, the result of this method making the system have small overshoot and short adjusting time. The optimization scheme of this paper will be used in the control of HVAC system. through simulation, it is shown that there is good effect, such as non-overshoot and short adjusting time. Compared with the traditional method, performance of this algorithm is well improved and optimized objective function is decreasing.