Abstract Chemical oxygen demand (COD) reflects the degree of water damage by organic pollutants, and is an important indicator for water environment protection and marine hydrological monitoring, so it is very important to accurately measure COD. However, changes in ambient temperature and atmospheric noise cause huge deviations in the precise measurement of COD by optical-based water quality detectors. The purpose of this research is to realize the accurate measurement of COD of the optical water quality detector by compensating the environmental parameters of the water quality detector. The compensation model established in this paper is a particle swarm optimization (PSO) back-propagation neural network (BPNN), which can compensate for temperature and filter out atmospheric noise, named back-propagation neural network of particle swarm optimization of filter out atmospheric noise (FAN-PSO-BPNN). FAN-PSO-BPNN reduced the maximum relative error by 92.51%, root mean square error by 91.64%, coefficient of variation by 91.74%, and the distance between the maximum and minimum prediction errors by 92.94% compared with BPNN in filtering out atmospheric noise interference and temperature compensation. The optimization scheme proposed in this paper for BPNN is crucial and effective, and the FAN-PSO-BPNN compensation model improves the anti-interference ability of the water quality detector, guarantees the accurate measurement of COD in seawater, and helps the water quality detector to monitor in seawater for a long time.