In this Thesis a control system has been developed which permits optimizing the performance of the Sequencing Batch Reactors (SBR) within the field of organic matter and nitrogen removal from the wastewater. This control system is based on the on-line adjustment of the length of the reaction phases using directly or indirectly the data acquired from the sensors. In a first stage of the Thesis the calibration of the activated sludge models is studied what permits obtaining models for testing different operating and control strategies. From the analysis of historical data several options for controlling the SBR are obtained and most suitable is tested using a simulation approach. Afterwards, the control strategy is implemented in a semi-industrial plant obtaining promising results. Finally, a proposal for a supervisory control system is presented which can be in charge of controlling the performance of the SBR not only at a phase level but also at cycle level.